Exemplo n.º 1
0
 /// <summary>
 /// 通讯方法
 /// </summary>
 public void Communication()
 {
     try
     {
         while (true)
         {
             CommandToValue ctov = null;
             if (QueueCommand.Count > 0 && QueueCommand.TryPeek(out ctov))//有动作命令
             {
                 while ((!ExeCommand(ctov)))
                 {
                     Thread.Sleep(90);
                 }
                 QueueCommand.TryDequeue(out ctov);
             }
             //else
             //{
             //    //发送查询命令
             //    Tcpsocket.Send(readbytelist.ToArray());
             //    Thread.Sleep(300);
             //}
         }
     }
     catch (Exception ex)
     {
         Clear();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 通讯方法
 /// </summary>
 public void Communication()
 {
     try
     {
         while (true)
         {
             CommandToValue ctov = null;
             LogHelper.WriteSendAGVMessLog($"{this.DeviceID}号AGV 当前线程{Thread.CurrentThread.ManagedThreadId}");
             ///因为考虑到发送指令判断返回状态,需要在发送指令前将读取指令
             /// 返回的状态指令消耗调,所以应该判断一下缓存中是否有指令
             if (QueueCommand.Count > 0 && Tcpsocket.Available > 0)
             {
                 ///如果缓存区有数据应该将数据消耗完
                 /// 否则再发送执行指令返回的指令则不知道是执行指令
                 /// 返回的还是发送读取指令返回的
                 GetCallBack();
             }
             else if (QueueCommand.Count > 0 && QueueCommand.TryPeek(out ctov))//有动作命令
             {
                 while ((!ExeCommand(ctov)))
                 {
                     Thread.Sleep(200);
                 }
                 QueueCommand.TryDequeue(out ctov);
             }
             else
             {
                 //查询心跳指令告知在地标上的信息
                 SetBitComand();
                 //发送查询命令
                 string SenDLog = "";
                 foreach (byte item in readbytelist)
                 {
                     SenDLog += ((int)item).ToString("X") + " ";
                 }
                 byte[] arr           = new byte[] { readbytelist[4], readbytelist[3] };
                 Int16  SendPackIndex = BitConverter.ToInt16(arr, 0);
                 LogHelper.WriteSendAGVMessLog("报文序号:" + SendPackIndex.ToString() + "发送--心跳--AGV" + this.DeviceID.ToString() + "命令" + ":" + SenDLog);
                 while (!SendExeCommand(readbytelist))
                 {
                     LogHelper.WriteSendAGVMessLog("报文序号:" + SendPackIndex.ToString() + "发送--心跳--AGV" + this.DeviceID.ToString() + "未成功,等待200ms再发送");
                     Thread.Sleep(200);
                 }
                 Thread.Sleep(100);
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.WriteSendAGVMessLog($"{this.DeviceID}号AGV  Communication 异常:" + ex.Message);
         //Clear();
         //ReConnect();
     }
 }
Exemplo n.º 3
0
 public void Communication()
 {
     try
     {
         while (true)
         {
             CommandToValue ctov = null;
             if (QueueCommand.Count > 0 && Tcpsocket.Available > 0)
             {
                 ///如果缓存区有数据应该将数据消耗完
                 /// 否则再发送执行指令返回的指令则不知道是执行指令
                 /// 返回的还是发送读取指令返回的
                 GetCallBack();
             }
             else if (QueueCommand.Count > 0 && QueueCommand.TryPeek(out ctov))//有动作命令
             {
                 while ((!ExeCommand(ctov)))
                 {
                     Thread.Sleep(500);
                 }
                 QueueCommand.TryDequeue(out ctov);
             }
             else
             {
                 /*
                  * 发送查询命令
                  */
                 SetReadByteList();
                 Tcpsocket.Send(readbytelist.ToArray());//发送字节
                 Thread.Sleep(50);
                 GetCallBack();
                 Thread.Sleep(500);
             }
         }
     }
     catch (Exception ex)
     {
         //LogHelper.WriteErrorLog(ex);
         //Clear();
         //ReConnect();
     }
 }