Exemplo n.º 1
0
        //任务
        #region
        //xd300发送任务
        public static void Polling_XD300Send()
        {
            for (int i = 0; i < _XD300Buffer.Length; i++)
            {
                for (int j = 0; j < _XD300Buffer[i]._Command.Length; j++)
                {
                    //判断命令是否开启
                    if (_XD300Buffer[i]._Command[j]._onoff == false)
                    {
                        continue;
                    }

                    //判断是否已发送
                    if (_XD300Buffer[i]._Command[j]._send == false)
                    {
                        //检测ISocketRS是否被占用和是否连接
                        Gprs.GprsList gl = Gprs.Get_GprsList(_XD300Buffer[i]._Info._ip);
                        if (gl._Iscon == false || gl._Isbusy == true || gl._activate == false)
                        {
                            continue;
                        }
                        bool send_flg = Gprs.Gprs_send(gl, _XD300Buffer[i]._Command[j]._cmd);
                        if (send_flg == true)
                        {
                            _XD300Buffer[i]._Command[j]._send       = true;
                            _XD300Buffer[i]._Command[j]._back       = false;
                            _XD300Buffer[i]._Command[j]._timeoutnow = 0;
                            _XD300Buffer[i]._Command[j]._senddt     = DateTime.Now;
                            _XD300Buffer[i]._LastCommandIndex       = j;
                            //占用ISocketRS
                            Gprs.Gprs_IsOccupy(_XD300Buffer[i]._Info._ip, true);
                        }
                    }
                    //发送完成 开始计时 计算超时时间
                    else
                    {
                        _XD300Buffer[i]._Command[j]._timeoutnow++;
                    }

                    //判断超时
                    if (_XD300Buffer[i]._Command[j]._timeoutnow >= _XD300Buffer[i]._Info._timeout)
                    {
                        _XD300Buffer[i]._Command[j]._timeoutnow = 0;
                        _XD300Buffer[i]._Command[j]._send       = false;
                        //解除ISocketRS占用
                        Gprs.Gprs_IsOccupy(_XD300Buffer[i]._Info._ip, false);
                        _XD300Buffer[i]._Command[j]._retrytimesnow++;
                    }

                    //判断重试次数 超过次数 设备故障
                    if (_XD300Buffer[i]._Command[j]._retrytimesnow >= _XD300Buffer[i]._Info._retrytimes)
                    {
                        _XD300Buffer[i]._Command[j]._onoff         = false;
                        _XD300Buffer[i]._Command[j]._retrytimesnow = 0;
                        _XD300Buffer[i]._Info._state = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
 //发送心跳包
 public static void Polling_HeatbeatSend()
 {
     for (int i = 0; i < _GprsList.Length; i++)
     {
         //检测是否到达心跳周期
         if ((DateTime.Now - _GprsList[i]._lasttime).TotalSeconds >= 300)
         {
             //检测ISocketRS是否被占用和是否连接
             if (_GprsList[i]._Iscon == false || _GprsList[i]._Isbusy == true || _GprsList[i]._activate == false)
             {
                 continue;
             }
             byte[] buffer   = new System.Text.UnicodeEncoding().GetBytes(_GprsList[i]._heatbeat);
             bool   send_flg = Gprs.Gprs_send(_GprsList[i], buffer);
             if (send_flg == true)
             {
                 _GprsList[i]._lasttime = DateTime.Now;
             }
         }
     }
 }