Exemplo n.º 1
0
        public static void ProcessTcpServerMessage()
        {
            if (m_MyTcpServer != null)
            {
                while (m_MyTcpServer.m_RecvMeasQueue.Count != 0)
                {
                    TcpMeas TempMeas = m_MyTcpServer.m_RecvMeasQueue.Dequeue();
                    if (TempMeas != null && TempMeas.Client != null)
                    {
                        if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_PLC)  // 处理和PLC之间的消息
                        {
                            if (TempMeas.MeasCode == (byte)Message.MessageCodePLC.GetCurStationState)
                            {
                                NetworkStream stream = TempMeas.Client.GetStream();

                                TempMeas.Param[7] = GetStationCurState();                                                               //工作站运行状态
                                TempMeas.Param[8] = GetStationSalverState();                                                            //物料盘的状态
                                TempMeas.Param[TempMeas.Param.Length - 2] = MyMath.CalculateSum(TempMeas.Param, TempMeas.Param.Length); //校验和
                                stream.Write(TempMeas.Param, 0, TempMeas.Param.Length);
                            }
                        }
                        else if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_MIS)  //处理和MIS之间的消息
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void ProcessArmControlerMessage(Board board, TcpMeas meassage)
        {
            if (meassage != null)
            {
                ArmCommandCode Code = (ArmCommandCode)meassage.MeasCode;
                switch (Code)
                {
                case ArmCommandCode.GetOutput:       //读取输出口缓冲区数据
                {
                } break;

                case ArmCommandCode.GetInput:        //读取输入口的IO
                {
                    int  DataIndex = Message.MessageCommandIndex + 1;
                    uint dataInput = (uint)meassage.Param[DataIndex + 3] * 0x1000000
                                     + (uint)meassage.Param[DataIndex + 2] * 0x10000
                                     + (uint)meassage.Param[DataIndex + 1] * 0x100
                                     + (uint)meassage.Param[DataIndex + 0];

                    m_ArmControler.SetInputPoint(board, dataInput);
                    ProcessArmControlerInputPoint(board);
                } break;

                case ArmCommandCode.GetAxisStepsAbs:
                {
                    int  DataIndex = Message.MessageCommandIndex + 2;
                    uint steps     = (uint)meassage.Param[DataIndex + 3] * 0x1000000
                                     + (uint)meassage.Param[DataIndex + 2] * 0x10000
                                     + (uint)meassage.Param[DataIndex + 1] * 0x100
                                     + (uint)meassage.Param[DataIndex + 0];

                    Axis axis = (Axis)meassage.Param[Message.MessageCommandIndex + 1];
                    m_ArmControler.SetAxisPostion(axis, steps);
                    ProcessArmControlerAxisPosition(board);
                }
                break;

                case ArmCommandCode.GetAxisState:
                {
                    Axis AxisNum = (Axis)meassage.Param[Message.MessageCommandIndex + 1];
                    byte State   = meassage.Param[Message.MessageCommandIndex + 2];
                    m_ArmControler.SetAxisState(AxisNum, State);
                }
                break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public static void ProcessCameraMessage(TcpMeas meassage)
        {
            if (meassage != null)
            {
                Message.MessageCodeCamera Code = (Message.MessageCodeCamera)meassage.MeasCode;
                switch (Code)
                {
                case Message.MessageCodeCamera.GetCameraCoords:
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
        public static void ProcessTcpClientMessage()
        {
            //作为客户端处理所有Arm控制板的消息
            for (int i = 0; i < m_ArmControler.m_MyTcpClientArm.Length; i++)
            {
                MyTcpClient Client = m_ArmControler.m_MyTcpClientArm[i];
                if (Client != null && Client.IsConnected)
                {
                    while (Client.m_RecvMeasQueue.Count != 0)
                    {
                        TcpMeas TempMeas = Client.m_RecvMeasQueue.Dequeue();
                        if (TempMeas != null && TempMeas.Client != null)
                        {
                            if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_ARM)  // 处理和ARM之间的消息
                            {
                                ProcessArmControlerMessage((Board)i, TempMeas);
                            }
                        }
#if DebugTest
                        Debug.WriteLine(BitConverter.ToString(TempMeas.Param));
#endif
                    }
                }
            }

            //作为客户端处理相机的消息
            if (m_MyTcpClientVisual != null && m_MyTcpClientVisual.IsConnected)
            {
                while (m_MyTcpClientVisual.m_RecvMeasQueue.Count != 0)
                {
                    TcpMeas TempMeas = m_MyTcpClientVisual.m_RecvMeasQueue.Dequeue();
                    if (TempMeas != null && TempMeas.Client != null)
                    {
                        if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_CAMERA)  // 处理和相机之间的消息
                        {
                            ProcessCameraMessage(TempMeas);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 解析数据,收到一包有效数据后,添加到消息队列
        /// </summary>
        /// <param name="recvBytes">接收到的数据</param>
        /// <param name="recvCount">接收到的数据长度</param>
        /// <param name="client">客户端</param>
        /// <param name="parseCount">解析计数器</param>
        /// <param name="arrayParse">解析缓冲区</param>
        public void ParseAndAddMessageToQueue(byte[] RecvBytes, int RecvCount, TcpClient Client, ref int parseCount, byte[] arrayParse)
        {
            //匹配比较数组, -1表示不需要比较,忽略
            int[] arrayCompare = new int[Message.MessageLength]
            {
                Message.MessStartCode, Message.MessVID1, Message.MessVID2, -1, Message.MessRightState, -1, Message.MessStationCode, -1,
                -1, -1, -1, -1, -1, -1, -1, -1,
                -1, -1, -1, -1, -1, -1, -1, -1,
                -1, -1, -1, -1, -1, -1, -1, Message.MessEndCode,
            };

            for (int i = 0; i < RecvCount; i++)
            {
                if (arrayCompare[parseCount] != -1)               //需要匹配
                {
                    if (RecvBytes[i] == arrayCompare[parseCount]) //相等
                    {
                        arrayParse[parseCount++] = RecvBytes[i];
                    }
                    else  //不相等,复位计数器
                    {
                        parseCount = 0;
                    }
                }
                else  //不需要比较,直接赋值,并更新计数器
                {
                    arrayParse[parseCount++] = RecvBytes[i];
                }

                if (parseCount >= Message.MessageLength)
                {
                    parseCount = 0;                                         //和校验

                    if (MyMath.CheckSum(arrayParse, Message.MessageLength)) //分析数据,把数据添加到队列m_TcpMeas
                    {
                        TcpMeasType MeasType = TcpMeasType.MEAS_TYPE_NONE;
                        byte        MeasCode = 0;

                        if (arrayParse[Message.MessageCommandIndex] == (byte)Message.MessageCodePLC.GetCurStationState)  //根据命令码区分消息类型
                        {
                            MeasType = TcpMeasType.MEAS_TYPE_PLC;
                            MeasCode = arrayParse[Message.MessageCommandIndex];
                        }

                        TcpMeas TempMeas = new TcpMeas();
                        if (TempMeas != null)
                        {
                            TempMeas.Client   = Client;
                            TempMeas.MeasType = MeasType;
                            TempMeas.MeasCode = MeasCode;
                            Array.Copy(RecvBytes, TempMeas.Param, TempMeas.Param.Length);
                            m_RecvMeasQueue.Enqueue(TempMeas);
                        }
                    }
                    else  //校验和错误,则更新错误码后发回
                    {
                        arrayParse[Message.MessageStateIndex] = Message.MessErrorState;
                        using (NetworkStream stream = Client.GetStream())
                        {
                            stream.Write(arrayParse, 0, arrayParse.Length);
                        }
                    }
                }
            }
        }