コード例 #1
0
        private void recvRfidProc()
        {
            //byte[] data = new byte[1024];
            byte[] byteStream = null;
            while (_conRfid)
            {
                int recv = 0;
                try
                {
                    //recv = _sockRfid.ReceiveFrom(data, ref _epRfid);
                    byteStream = _udpClient.Receive(ref C_Point);
                    _bConnected = true;
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(" recvRfidProc"+e.Message);
                    continue;
                }

                //事件参数
                udpPackage package = new udpPackage();
                if (package.Pack(byteStream))
                {
                    switch(package.cmd)
                    {
                        case 0x01:
                            {
                                ProcessReCmd_query(package);
                                break;
                            }
                        case 0x02:
                            {
                                //正常移出的应答
                                break;
                            }
                        case 0x03:
                            {
                                //强制清除的应答
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 接收数据线程函数
        /// </summary>
        private void recvPlcProc()
        {
            byte[] data = new byte[1024];
            while (_conPlc)
            {
                 int recv =0;
                 byte[] byteStream = null;
                try
                {

                  //  recv= _sockPlc.ReceiveFrom(data, ref _epPlc);
                    byteStream = _udpClient.Receive(ref  C_Point);
                    _heartCount = 0; //收到数据包,清零,标识连接建立
                    _bConnected = true;
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("plc comm:"+e.Message);
                    continue;
                }

                //事件参数

                udpPackage package = new udpPackage();

                for (int i = 0; i < recv; i++)
                {
                    byteStream[i] = data[i];
                }
                if (package.Pack(byteStream))
                {
                    if ((package.frameType == 0x02) && (package.addr == this.MachineNo))
                    {
                        //应答帧,地址正确
                        if (package.cmd == (byte)HouseCmdCode.CMD_QUERY)
                        {
                            MachineWorkStatus newS = (MachineWorkStatus)package.data[3];
                            TMCoord newPos = new TMCoord(package.data[0], this.MachineNo, (package.data[1] + (package.data[2] << 8)));

                            if (newS != MStatus)
                            {
                                if(MStatus == MachineWorkStatus.PRODUCT_INHOUSE_OK)
                                {
                                    string ss = "入库任务"+(_currentCmdIndex+1).ToString()+"完成";
                                    Console.WriteLine(ss);

                                }
                                MStatus = newS;
                            //    string strS = "小车"+MachineNo.ToString()+"状态:"+MStatus.ToString();
                           //     Console.WriteLine(strS);
                                msgTMEventArg e = new msgTMEventArg();
                                e.MachineNo = this.MachineNo;
                                e.ErrorHappened = false;
                                e.TMStatus = newS;
                                if (EventTMStatusUpdated != null)
                                {
                                    EventTMStatusUpdated(this, e);
                                }

                            }
                            if(newPos != this.currentCoord)
                            {
                                msgTMEventArg e = new msgTMEventArg();
                                e.MachineNo = this.MachineNo;
                                e.ErrorHappened = false;
                                e.TMPos = newPos;
                                if(EventTMPosUpdated != null)
                                {
                                    EventTMPosUpdated(this,e);
                                }
                            }
                        }
                        else if (package.cmd == (byte)HouseCmdCode.CMD_PRODUCT_INHOUSE)
                        {

                        }
                        else if (package.cmd == (byte)HouseCmdCode.CMD_PRODUCT_OUTHOUSE)
                        {

                        }
                    }
                }
            }
        }