Пример #1
0
 public void recdata()   //接收消息
 {
     while (true)
     {
         byte[] buffer = new byte[36];  //数据接收容器(共36个数据)
         if (PAGV1Socket.Connected)
         {
             try
             {
                 int r = PAGV1Socket.Receive(buffer);
                 //  ModifyTxt.PrintReceiveTxt(buffer);     //打印
                 if ((buffer[0] == 0x05) && (buffer[1] == 0x0A) && (buffer[2] == 0x05) && (buffer[3] == 0x0A))  //头校验通过
                 {
                     if (DataCheck.CheckData(buffer))
                     {
                         if ((buffer[5] == 0xFF) && (buffer[6] == 0x30) && (buffer[7] == 0x00) && (buffer[8] == 0x00))   //0x30FF 平台AGV主动反馈当前状态信息
                         {
                             PlatfromStateArray[0]  = 0x04;
                             PlatfromStateArray[1]  = buffer[20]; //应答状态
                             PlatfromStateArray[2]  = buffer[21]; //平台位置
                             PlatfromStateArray[3]  = buffer[22]; //是否有料盘
                             PlatfromStateArray[4]  = buffer[23]; //作业执行状态
                             PlatfromStateArray[5]  = buffer[24];
                             PlatfromStateArray[6]  = buffer[25];
                             PlatfromStateArray[7]  = buffer[26];
                             PlatfromStateArray[8]  = buffer[27];  //X坐标
                             PlatfromStateArray[9]  = buffer[28];
                             PlatfromStateArray[10] = buffer[29];
                             PlatfromStateArray[11] = buffer[30];
                             PlatfromStateArray[12] = buffer[31];   //Y坐标
                             PlatfromStateArray[13] = buffer[32];
                             PlatfromStateArray[14] = buffer[33];
                             PlatfromStateArray[15] = buffer[34];
                             PlatfromStateArray[16] = buffer[35];   //theta坐标
                             callback(PlatfromStateArray);
                             Array.Clear(buffer, 0, 36);
                         }
                     }
                 }
             }
             catch
             {
                 WMS.MainWindow.InterruptMsg(1, "AGV1断开连接");
                 CanStop = true;
                 Thread.Sleep(TimeSpan.FromSeconds(1));
                 PAGV1Socket.Dispose();
                 PAGV1Socket.Close();
                 MessageBox.Show("AGV1断开连接");
             }
         }
         else
         {
         }
     }
 }
Пример #2
0
 //接收复合发来的消息
 public void recdata()   //接收消息
 {
     while (true)
     {
         byte[] buffer = new byte[35];  //数据接收容器
         if (MixSocket.Connected)
         {
             try
             {
                 int r = MixSocket.Receive(buffer);
                 // ModifyTxt.PrintReceiveTxt(buffer);   //打印
                 if ((buffer[0] == 0x05) && (buffer[1] == 0x0A) && (buffer[2] == 0x05) && (buffer[3] == 0x0A))         //头校验通过
                 {
                     if (DataCheck.CheckData(buffer))                                                                  //异或校验通过
                     {
                         if ((buffer[5] == 0xFF) && (buffer[6] == 0x30) && (buffer[7] == 0x00) && (buffer[8] == 0x00)) //0x30FF  复合反馈当前状态信息
                         {
                             PlatfromStateArray[0]  = 0x06;
                             PlatfromStateArray[1]  = buffer[20]; //应答状态
                             PlatfromStateArray[2]  = buffer[21]; //平台位置
                             PlatfromStateArray[3]  = buffer[22]; //动作完成状态
                             PlatfromStateArray[4]  = buffer[23]; //X轴
                             PlatfromStateArray[5]  = buffer[24];
                             PlatfromStateArray[6]  = buffer[25];
                             PlatfromStateArray[7]  = buffer[26];
                             PlatfromStateArray[8]  = buffer[27]; //Y轴
                             PlatfromStateArray[9]  = buffer[28];
                             PlatfromStateArray[10] = buffer[29];
                             PlatfromStateArray[11] = buffer[30];
                             PlatfromStateArray[12] = buffer[31];  //theta轴
                             PlatfromStateArray[13] = buffer[32];
                             PlatfromStateArray[14] = buffer[33];
                             PlatfromStateArray[15] = buffer[34];
                             callback(PlatfromStateArray);
                             Array.Clear(buffer, 0, 35);
                         }
                     }
                 }
             }
             catch
             {
                 WMS.MainWindow.InterruptMsg(3, "复合断开连接");
                 CanStop = true;
                 Thread.Sleep(TimeSpan.FromSeconds(1));  //延时1秒
                 MixSocket.Dispose();
                 MixSocket.Close();
                 MessageBox.Show("复合断开连接");
             }
         }
     }
 }
Пример #3
0
//接收FAGV发来的消息
        public void recdata()   //接收消息
        {
            while (true)
            {
                byte[] buffer = new byte[13];  //数据接收容器
                try
                {
                    int r = FagvSocket.Receive(buffer);
                    //   ModifyTxt.PrintReceiveTxt(buffer);    //打印
                    if (buffer[0] == 0x1B && buffer[1] == 0x27)
                    {
                        if (DataCheck.CheckDataE2(buffer))
                        {
                            ExecuteState[0] = 0x07;
                            ExecuteState[1] = buffer[6]; //表示是执行状态信息
                            ExecuteState[2] = buffer[7]; //终点
                            ExecuteState[3] = buffer[8]; //工作状态
                            ExecuteState[4] = buffer[9];
                            ExecuteState[5] = buffer[10];
                            ExecuteState[6] = buffer[11]; //故障代码
                            callback(ExecuteState);
                            if (ExecuteState[3] == 0x06)  //叉车AGV在安全位置
                            {
                                test1.FAGVInSafeArea   = true;
                                CJClass.FAGVInSafeArea = true;
                            }
                            Array.Clear(buffer, 0, 13);
                        }
                    }
                }
                catch
                {
                    WMS.MainWindow.InterruptMsg(5, "叉车AGV断开连接");
                    CanStop = true;
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                    FagvSocket.Dispose();
                    FagvSocket.Close();
                    MessageBox.Show("叉车AGV断开连接");
                }
            }
        }
Пример #4
0
 public void recdata()   //接收消息
 {
     while (true)
     {
         byte[] buffer = new byte[27];  //数据接收容器
         if (TwoSocket.Connected)
         {
             try
             {
                 int r = TwoSocket.Receive(buffer);
                 //  ModifyTxt.PrintReceiveTxt(buffer);   //打印
                 if ((buffer[0] == 0x05) && (buffer[1] == 0x0A) && (buffer[2] == 0x05) && (buffer[3] == 0x0A))         //头校验通过
                 {
                     if (DataCheck.CheckData(buffer))                                                                  //校验通过
                     {
                         if ((buffer[5] == 0x00) && (buffer[6] == 0x10) && (buffer[7] == 0x00) && (buffer[8] == 0x00)) //0x1000 双臂机器人请求命令回复信息
                         {
                             answerinfo[0] = 0x00;
                             answerinfo[1] = buffer[20];   //启动信号
                             answerinfo[2] = buffer[21];   //请求动作是否完成
                             answerinfo[3] = buffer[22];
                             answerinfo[4] = buffer[23];
                             answerinfo[5] = buffer[24];
                             answerinfo[6] = buffer[25];                     //前四位为应答号(与请求号一致)
                             answerinfo[7] = buffer[26];                     //执行状态  0:正常  1:异常
                             callback(answerinfo);                           //回调
                             if (buffer[20] == 0x00 && (buffer[21] == 0x00)) //动作0完成
                             {
                                 MainWindow.TwoRobotActionFlag0 = false;     //停止发送动作0消息
                                 test1.TwoRobotActionComplete0  = true;      //通知自动化类test1动作0完成
                                 RequestId[0] = 0;
                             }
                             if (buffer[20] == 0x01 && buffer[21] == 0x00) //动作1完成
                             {
                                 MainWindow.TwoRobotActionFlag1 = false;   //停止动作1:装配的发送
                                 RequestId[1]            = 0;
                                 test1.AssemblyCompleted = true;           //装配完成
                             }
                             if (buffer[20] == 0x02 && buffer[21] == 0x00) //动作2完成
                             {
                                 MainWindow.TwoRobotActionFlag2 = false;
                                 RequestId[2] = 0;
                                 test1.TwoRobotActionComplete2 = true;
                             }
                             if (buffer[20] == 0x03 && buffer[21] == 0x00)   //动作3完成
                             {
                                 MainWindow.TwoRobotActionFlag3 = false;
                                 RequestId[3] = 0;
                                 CJClass.TwoRobotActionComplete3 = true;    //通知拆解类,双臂动作3完成:从成品料盘取出成品
                             }
                             if (buffer[20] == 0x04 && buffer[21] == 0x00)  //动作4完成
                             {
                                 MainWindow.TwoRobotActionFlag4 = false;
                                 RequestId[4] = 0;
                                 CJClass.TwoRobotActionComplete4 = true;     //通知拆解类,双臂动作4完成:拆解
                             }
                             if (buffer[20] == 0x05 && buffer[21] == 0x00)   //动作5完成
                             {
                                 MainWindow.TwoRobotActionFlag5 = false;
                                 RequestId[5] = 0;
                                 CJClass.TwoRobotActionComplete5 = true;     //通知拆解类,双臂动作5完成:将零件放到零件料盘
                             }
                             Array.Clear(buffer, 0, 27);
                         }
                     }
                 }
             }
             catch
             {
                 WMS.MainWindow.InterruptMsg(4, "双臂断开连接");
                 CanStop = true;
                 Thread.Sleep(TimeSpan.FromSeconds(1));
                 TwoSocket.Dispose();
                 TwoSocket.Close();
                 MessageBox.Show("双臂断开连接");
             }
         }
     }
 }