Esempio n. 1
0
        /// <summary>
        /// 接收到信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Socketclient_Scanner_Received(object sender, ReceivedEventArgs e)
        {
            try
            {
                var    ipEndPoint = e.EndPoint as IPEndPoint;
                byte[] buffer     = e.Buff;

                TagInfo tagInfo = MyReader.TagTimeSpanInventory(300);//时间段盘点标签的时间建议在200ms以上,否则比较容易读取失败,读取时间大约在 time + 50 ms

                //判断是否为空

                var sas = System.Text.Encoding.ASCII.GetString(tagInfo.EPC);



                string strReceived = Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrWhiteSpace(strReceived))
                {
                    return;
                }
                //截取字符串
                string[] splitReceived = strReceived.Split(new[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < splitReceived.Length; i++)
                {
                    //删掉读取信息前的'&'符号
                    string trimReceived = splitReceived[i].TrimStart('&');
                    if (string.IsNullOrWhiteSpace(trimReceived))
                    {
                        continue;
                    }
                    else
                    {
                        //异步写入数据库
                        UpdateDBInfoDelegate updateDBInfoDelegate = new UpdateDBInfoDelegate(UpdateInfoToDataBase);
                        IAsyncResult         result = updateDBInfoDelegate.BeginInvoke(trimReceived, ipEndPoint.Address.ToString(), ipEndPoint.Port.ToString(), UpdateDBInfoFinishedCallnack, null);
                        result.AsyncWaitHandle.WaitOne(ALLOWTIME);
                        if (result.IsCompleted)
                        {
                            AsyncResult          asyncResult = (AsyncResult)result;
                            UpdateDBInfoDelegate del         = (UpdateDBInfoDelegate)asyncResult.AsyncDelegate;
                            bool bResult = del.EndInvoke(result);
                            if (bResult == true)
                            {
                                ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"数据库处理成功!  --来自{ipEndPoint.Address.ToString()}:{ipEndPoint.Port.ToString()}", 0));
                            }
                            else
                            {
                                ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"数据库处理失败..--来自{ipEndPoint.Address.ToString()}:{ipEndPoint.Port.ToString()}", 0));
                            }
                        }
                    }
                    ShowFormData.Instance.ShowFormInfo(new ShowInfoData(strReceived, 0));
                }
            }
            catch (Exception ex)
            {
                log.Error("初始化socket,接收信息异常:" + ex.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 业务处理入口
        /// </summary>
        public void BizListen()
        {
            //IBiz biz = null;
            foreach (var loc in mRfIdReadList)
            {
                if (!myUHFreader.ContainsKey(loc.LocNo))
                {
                    UHFreader MyReader = new UHFreader();

                    bool result = MyReader.NetConnect(loc.IPAddress, int.Parse(loc.PortNo));
                    if (result)
                    {
                        myUHFreader.Add(loc.LocNo, MyReader);
                        TagInfo tagInfo = MyReader.TagTimeSpanInventory(300);//时间段盘点标签的时间建议在200ms以上,否则比较容易读取失败,读取时间大约在 time + 50 ms
                        //判断是否为空
                        string readInfo = null;
                        if (tagInfo.EPC != null)
                        {
                            readInfo = System.Text.Encoding.ASCII.GetString(tagInfo.EPC);
                        }
                        if (LastReadInfo != readInfo)
                        {
                            ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"{readInfo}", loc.LocNo, InfoType.locStatus));
                            ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"当前读取RFID:{readInfo}", loc.LocNo, InfoType.logInfo));

                            UpdatePemLocStatus(loc.LocNo, readInfo);
                            LastReadInfo = readInfo;
                        }
                    }
                }
                else
                {
                    UHFreader myReader = myUHFreader.SingleOrDefault(k => k.Key == loc.LocNo).Value;
                    TagInfo   tagInfo  = myReader.TagTimeSpanInventory(300);
                    string    readInfo = null;
                    if (tagInfo.EPC != null)
                    {
                        readInfo = System.Text.Encoding.ASCII.GetString(tagInfo.EPC);
                    }
                    if (LastReadInfo != readInfo)
                    {
                        ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"{readInfo}", loc.LocNo, InfoType.locStatus));
                        ShowFormData.Instance.ShowFormInfo(new ShowInfoData($"当前读取RFID:{readInfo}", loc.LocNo, InfoType.logInfo));

                        UpdatePemLocStatus(loc.LocNo, readInfo);
                        LastReadInfo = readInfo;
                    }
                }
            }
        }