Ejemplo n.º 1
0
Archivo: main.cs Proyecto: hkiaipc/guye
        //接收事件
        private void rs_ReceivedEvent( object sender, EventArgs e )
        {
            ISocketRS rs = sender as ISocketRS;

            //心跳包
            if (rs.ReceivedBytes[0] == 123)
            {
                return;
            }
            //不合校验
            if (Tool.DataInfo.check_crc(rs.ReceivedBytes) == false)
            {
                return;
            }

            string ip = ((IPEndPoint)rs.Socket.RemoteEndPoint).Address.ToString();

            //控制器
            Tool.XD100n x = new Tool.XD100n(rs.ReceivedBytes[0]);
            int listid = -1;
            for (int i = 0; i < _XDRZInfoList.Length; i++)
            {
                if (_XDRZInfoList[i]._station._IPAddress == ip && _XDRZInfoList[i]._station._deviceAddress == rs.ReceivedBytes[0])
                {
                    listid = i;
                    break;
                }
            }
            if (listid != -1)
            {
                rz_deal(rs.ReceivedBytes, listid);
            }

            //巡更
            Tool.xd300 xg = new Tool.xd300(rs.ReceivedBytes[3]);
            int xglistid = -1;
            for (int i = 0; i < _XDXGInfoList.Length; i++)
            {
                if (_XDXGInfoList[i]._XGInfo._IPAddress == ip && _XDXGInfoList[i]._XGInfo._deviceAddress == rs.ReceivedBytes[3] && rs.ReceivedBytes[0] == 0x21 && rs.ReceivedBytes[1] == 0x58 && rs.ReceivedBytes[2] == 0x44)
                {
                    xglistid = i;
                    break;
                }
            }
            if (xglistid != -1)
            {
                xg_deal(rs.ReceivedBytes, xglistid);
            }
        }
Ejemplo n.º 2
0
Archivo: main.cs Proyecto: hkiaipc/guye
        //建立xd300数据缓存
        public Tool.XDXGInfo[] Createxd300Datas()
        {
            try
            {
                string sql = "SELECT [XgID],[XgName], [deviceAddress], [DTUregister], [IPAddress], [Remark], [cycle], [timeout], [retrytimes] FROM [v_xgstation]";
                DataTable dt = Tool.DB.getDt(sql);
                Tool.XDXGInfo[] baseList = new Tool.XDXGInfo[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    baseList[i]._XGInfo._XgID = int.Parse(dt.Rows[i]["XgID"].ToString());
                    baseList[i]._XGInfo._XgName = dt.Rows[i]["XgName"].ToString();
                    baseList[i]._XGInfo._Remark = dt.Rows[i]["Remark"].ToString();

                    baseList[i]._XGInfo._DTUregister = dt.Rows[i]["DTUregister"].ToString();
                    baseList[i]._XGInfo._IPAddress = dt.Rows[i]["IPAddress"].ToString();
                    baseList[i]._XGInfo._cycle = int.Parse(dt.Rows[i]["cycle"].ToString());
                    baseList[i]._XGInfo._deviceAddress = int.Parse(dt.Rows[i]["deviceAddress"].ToString());
                    baseList[i]._XGInfo._timeout = int.Parse(dt.Rows[i]["timeout"].ToString());
                    baseList[i]._XGInfo._retrytimes = int.Parse(dt.Rows[i]["retrytimes"].ToString());
                    baseList[i].state = true;

                    Tool.xd300 x = new Tool.xd300(baseList[i]._XGInfo._deviceAddress);

                    string sql2 = "SELECT [xglastdata_id], [DT], [XgName], [person], [XgID] FROM [v_xgreallast] where [XgID]=" + baseList[i]._XGInfo._XgID.ToString();
                    DataTable dt1 = Tool.DB.getDt(sql2);
                    if (dt1.Rows.Count > 0)
                    {
                        baseList[i]._XGDataNow._DT = dt1.Rows[0]["DT"].ToString();
                        baseList[i]._XGDataNow._person = dt1.Rows[0]["person"].ToString(); ;
                        baseList[i]._refDisplay = true;
                    }

                    baseList[i]._command = new Tool.XGCommandcyc[1];
                    baseList[i]._command[0]._cmd = x.Get_record_count();
                    baseList[i]._command[0]._onoff = true;

                    baseList[i]._commandonce = new Tool.XGCommandonce[5];
                    baseList[i]._commandonce[0]._cmd = x.Get_record_n(0);
                    baseList[i]._commandonce[1]._cmd = x.Get_record_clean_now();
                    baseList[i]._commandonce[2]._cmd = x.Get_record_clean();
                    baseList[i]._commandonce[3]._cmd = x.Set_date();
                    baseList[i]._commandonce[4]._cmd = x.Set_time();

                    for (int k = 0; k < baseList[i]._commandonce.Length; k++)
                    {
                        baseList[i]._commandonce[k]._onoff = false;
                    }

                }
                return baseList;
            }
            catch (Exception ex)
            {
                MessageBox.Show("建立数据缓存失败!请检查数据库连接!" + ex, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return null;
            }
        }
Ejemplo n.º 3
0
Archivo: main.cs Proyecto: hkiaipc/guye
        //xd300数据处理
        private void xg_deal(byte[] rs, int xglistid)
        {
            Tool.xd300 xg = new Tool.xd300(rs[3]);
            //功能码 0x0a 主动上报
            if (rs[5] == 0x0a)
            {
                _XDXGInfoList[xglistid]._XGDataNow = xg.Read_record_n(rs);
                _XDXGInfoList[xglistid]._XGDataNow._person = getperson(_XDXGInfoList[xglistid]._XGDataNow._card);
                _XDXGInfoList[xglistid]._commandonce[1]._cmd = xg.Get_record_clean_now();
                _XDXGInfoList[xglistid]._commandonce[1]._onoff = true;
                _XDXGInfoList[xglistid]._commandonce[1]._timeoutnow = 0;
                _XDXGInfoList[xglistid]._commandonce[1]._sendover = false;
                _XDXGInfoList[xglistid]._saveDatas = true;
                _XDXGInfoList[xglistid]._refDisplay = true;
            }
            //功能码 0x06 读取记录总条数
            if (rs[5] == 0x06)
            {
                _XDXGInfoList[xglistid]._count = xg.Read_record_count(rs);
                if (_XDXGInfoList[xglistid]._count > 0)
                {
                    _XDXGInfoList[xglistid]._commandonce[0]._cmd = xg.Get_record_n(1);
                    _XDXGInfoList[xglistid]._commandonce[0]._onoff = true;
                    _XDXGInfoList[xglistid]._commandonce[0]._timeoutnow = 0;
                    _XDXGInfoList[xglistid]._commandonce[0]._sendover = false;
                }
            }
            //功能码 0x07 读取第N条记录
            if (rs[5] == 0x07)
            {
                _XDXGInfoList[xglistid]._XGDataNow = xg.Read_record_n(rs);
                _XDXGInfoList[xglistid]._XGDataNow._person = getperson(_XDXGInfoList[xglistid]._XGDataNow._card);
                if (_XDXGInfoList[xglistid]._XGDataNow._n < _XDXGInfoList[xglistid]._count)
                {
                    //读下条记录
                    _XDXGInfoList[xglistid]._commandonce[0]._cmd = xg.Get_record_n(_XDXGInfoList[xglistid]._XGDataNow._n + 1);
                    _XDXGInfoList[xglistid]._commandonce[0]._onoff = true;
                    _XDXGInfoList[xglistid]._commandonce[0]._timeoutnow = 0;

                }
                if (_XDXGInfoList[xglistid]._XGDataNow._n == _XDXGInfoList[xglistid]._count && _XDXGInfoList[xglistid]._count>0)
                {
                    //清除总记录
                    _XDXGInfoList[xglistid]._commandonce[2]._cmd = xg.Get_record_clean();
                    _XDXGInfoList[xglistid]._commandonce[2]._onoff = true;
                    _XDXGInfoList[xglistid]._count = 0;

                }
                _XDXGInfoList[xglistid]._saveDatas = true;
                _XDXGInfoList[xglistid]._refDisplay = true;
                _XDXGInfoList[xglistid]._command[0]._retrytimesnow = 0;
                _XDXGInfoList[xglistid]._commandonce[0]._sendover = false;
            }
            //功能码 0x08 清除记录
            if (rs[5] == 0x08)
            {
                _XDXGInfoList[xglistid]._commandonce[2]._sendover = false;
            }
            //功能码 0x01 修改日期
            if (rs[5] == 0x01)
            {
                _XDXGInfoList[xglistid]._commandonce[3]._sendover = false;
            }
            //功能码 0x02 修改时间
            if (rs[5] == 0x01)
            {
                _XDXGInfoList[xglistid]._commandonce[4]._sendover = false;
            }

            _XDXGInfoList[xglistid].state = true;
            On_ISocketRS(_XDXGInfoList[xglistid]._XGInfo._IPAddress, false);
        }
Ejemplo n.º 4
0
Archivo: main.cs Proyecto: hkiaipc/guye
 //存储xd300
 private void xg_save_task()
 {
     for (int i = 0; i < _XDXGInfoList.Length; i++)
     {
         if (_XDXGInfoList[i]._saveDatas == true)
         {
             Tool.xd300 xg = new Tool.xd300(_XDXGInfoList[i]._XGInfo._deviceAddress);
             xg.xgInsertSql(_XDXGInfoList[i]);
             _XDXGInfoList[i]._saveDatas = false;
             return;
         }
     }
 }
Ejemplo n.º 5
0
        //校时
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }

            for (int i = 0; i < SocketServer.main._XDXGInfoList.Length; i++)
            {
                if (SocketServer.main._XDXGInfoList[i]._XGInfo._XgID == Convert.ToInt32(dataGridView1["XgID", dataGridView1.CurrentRow.Index].Value))
                {
                    Tool.xd300 x = new Tool.xd300(SocketServer.main._XDXGInfoList[i]._XGInfo._deviceAddress);
                    SocketServer.main._XDXGInfoList[i]._commandonce[3]._cmd = x.Set_date();
                    SocketServer.main._XDXGInfoList[i]._commandonce[3]._onoff = true;
                    SocketServer.main._XDXGInfoList[i]._commandonce[3]._cmd = x.Set_time();
                    SocketServer.main._XDXGInfoList[i]._commandonce[4]._onoff = true;
                    MessageBox.Show("成功添加校时任务!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }