コード例 #1
0
 public bool SendRemsg(udpPackage package, string ip, int port)
 {
     byte[] byteStream = package.UnPack();
     if (byteStream == null)
     {
         return false;
     }
     else
     {
         return _udpServer.SendData(byteStream, byteStream.Length, ip, port);
     }
 }
コード例 #2
0
 private void ThreadUIHandleMethod(msgReceiptEventArg eventData)
 {
     if (eventData.ErrorHappened)
     {
         this.labelUdpstatus.Text = "通讯服务发生错误,已断开";
     }
     else
      {
          udpPackage package = new udpPackage();
          if (package.Pack(eventData.data))
          {
              _rfidReader.RecvCmd(package, eventData.requestIP, eventData.requestPort);
          }
      }
 }
コード例 #3
0
        public void RecvCmd( udpPackage package,string requestIP,int requestPort)
        {
            lock(this)
             {
                 _requestIP = requestIP;
                _requestPort = requestPort;
                 if(package.addr == Addr)
                 {
                     switch(package.cmd)
                     {
                         case (byte)CmdCode.CMD_READ:
                             {
                                 //查询
                                 udpPackage rePackage = new udpPackage();
                                 rePackage.len = 0x18;
                                 rePackage.frameType = 0x02;
                                 rePackage.addr = Addr;
                                 rePackage.cmd = package.cmd;
                                 if(_rfidObj.bScaned == false)
                                 {
                                     //扫描到
                                     rePackage.status = 0x00;
                                     rePackage.data = new byte[20];
                                     string s;
                                     if (_rfidObj.id.Length >= 20)
                                     {
                                         s = _rfidObj.id.Substring(0, 20);
                                     }
                                     else
                                     {
                                         s = _rfidObj.id.PadLeft(20, '0');
                                     }
                                     rePackage.data = System.Text.ASCIIEncoding.UTF8.GetBytes(s);
                                     _rfidObj.bScaned = true;
                                     //_rfidObj.id = string.Empty;
                                     _svc.AppendRuninfo("识别ID:" + s + "\r\n");
                                 }
                                 else
                                 {
                                     //该产品已经扫描过了

                                     rePackage.status = 0x01;
                                     string s = new string('0', 20);
                                     rePackage.data = System.Text.ASCIIEncoding.UTF8.GetBytes(s);
                                 }
                                 _svc.SendRemsg(rePackage, _requestIP, _requestPort);
                                 break;
                             }
                         case (byte)CmdCode.CMD_OBJREMOVE:
                             {
                                 //通知物件已经移走
                                 _svc.ShowScanobj(false);
                                 _bEnableIn = true;

                                 //应答
                                 udpPackage rePackage = new udpPackage();
                                 rePackage.len = 0x04;
                                 rePackage.frameType = 0x02;
                                 rePackage.addr = Addr;
                                 rePackage.cmd = package.cmd;
                                 rePackage.status = 0x00;
                                 _svc.SendRemsg(rePackage, _requestIP, _requestPort);
                                 _svc.AppendRuninfo("产品:" + _rfidObj.id + "已经取走" + "\r\n");
                                 break;
                             }
                         case (byte)CmdCode.CMD_CLEAR:
                             {
                                 //通知物件已经移走
                                 _svc.ShowScanobj(false);
                                 _bEnableIn = true;

                                 //应答
                                 udpPackage rePackage = new udpPackage();
                                 rePackage.len = 0x04;
                                 rePackage.frameType = 0x02;
                                 rePackage.addr = Addr;
                                 rePackage.cmd = package.cmd;
                                 rePackage.status = 0x00;
                                 _svc.SendRemsg(rePackage, _requestIP, _requestPort);
                                 _svc.AppendRuninfo("产品:" + _rfidObj.id + "产品ID 信息错误,产品已经清除" + "\r\n");
                                 break;
                             }
                         default:
                             break;
                     }
                 }
             }
        }