/// <summary> /// 处理读到的Epc信息 /// </summary> /// <param name="obj"></param> private void DealEpcInfo(object obj) { while (IsDealEpc) { try { Thread.Sleep(1000); if (QEpcInfo != null && QEpcInfo.Count > 0) { while (QEpcInfo.Count > 0) { EpcInfo ei = null; QEpcInfo.TryDequeue(out ei); if (ei != null) { DealToolInfo(ei); } } } } catch (Exception ex) { Thread.Sleep(1000); } } }
private void DealToolInfo(EpcInfo ei) { try { if (MainControl.dicTools != null && MainControl.dicTools.Count > 0) { if (MainControl.dicTools.ContainsKey(ei.StrEpc)) { DateTime dtBorrRet = MainControl.dicTools[ei.StrEpc].TimeBorrRet; TimeSpan ts = ei.DtReadedEpc - dtBorrRet; if (ts.TotalSeconds >= infoOfSystem.iBorrRetSpan) {//出入库时间大于设置时间才算有效 string strToolType = MainControl.dicTools[ei.StrEpc].StrToolType; string strToolName = MainControl.dicTools[ei.StrEpc].StrToolName; string strToolID = MainControl.dicTools[ei.StrEpc].StrToolId; string strBorrOrRetTime = ei.DtReadedEpc.ToString("yyyy-MM-dd HH:mm:ss"); if (MainControl.dicTools[ei.StrEpc].ToolState == ToolsState.在库) { if (ei.UsingReadNo == DeviceUsing.启用) { if (ei.BorrOrRet == ToolsBorrRet.借出) { MainControl.dicTools[ei.StrEpc].ToolState = ToolsState.借出; GenToolRorrRetRecord(ToolsState.借出, strBorrOrRetTime, ei.StrEpc, strToolType, strToolName, strToolID); //ei.IsEpcRead = IsReadShow.已读; MainControl.dicTools[ei.StrEpc].TimeBorrRet = DateTime.Now; } } else { MainControl.dicTools[ei.StrEpc].ToolState = ToolsState.借出; GenToolRorrRetRecord(ToolsState.借出, strBorrOrRetTime, ei.StrEpc, strToolType, strToolName, strToolID); //ei.IsEpcRead = IsReadShow.已读; MainControl.dicTools[ei.StrEpc].TimeBorrRet = DateTime.Now; } } else if (MainControl.dicTools[ei.StrEpc].ToolState == ToolsState.借出) { if (ei.UsingReadNo == DeviceUsing.启用) { if (ei.BorrOrRet == ToolsBorrRet.归还) { MainControl.dicTools[ei.StrEpc].ToolState = ToolsState.在库; GenToolRorrRetRecord(ToolsState.在库, strBorrOrRetTime, ei.StrEpc, strToolType, strToolName, strToolID); //ei.IsEpcRead = IsReadShow.已读; MainControl.dicTools[ei.StrEpc].TimeBorrRet = DateTime.Now; } } else { MainControl.dicTools[ei.StrEpc].ToolState = ToolsState.在库; GenToolRorrRetRecord(ToolsState.在库, strBorrOrRetTime, ei.StrEpc, strToolType, strToolName, strToolID); //ei.IsEpcRead = IsReadShow.已读; MainControl.dicTools[ei.StrEpc].TimeBorrRet = DateTime.Now; } } } } } } catch (Exception ex) { } }
public bool ReadEpcInfo() { bool blRet = false; try { byte MaskMem = 0; byte[] MaskAdr = new byte[2]; byte MaskLen = 0; byte[] MaskData = new byte[100]; byte MaskFlag = 0; byte AdrTID = 0; byte LenTID = 0; byte TIDFlag = 0; byte Ant = 0; blScan = true; int CardCount = 0; //输出变量,电子标签的张数 int EpcLen = 0; //EPC 的字节数 byte[] bEpcArray = new byte[5000]; //指向输出数组变量 是读到的电子标签的EPC数据,是一张标签的EPC长度+一张标签的EPC号,依此累加 //int fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, MaskMem, MaskLen, MaskFlag); //if ((fCmdRet==0)|| (fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 3) || (fCmdRet == 4) || (fCmdRet == 0xFB))//代表已查找结束, //{ } //else //{ // iReadEpcErr++; // blRet = false; //} int fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, bEpcArray, ref Ant, ref EpcLen, ref CardCount, frmcomportindex); // 8616 if ((fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 3) || (fCmdRet == 4) || (fCmdRet == 0xFB)) //代表已查找结束, { iReadEpcErr = 0; blRet = true; if (CardCount == 0) { blScan = false; return(blRet); } byte[] bEpcCopy = new byte[EpcLen]; Array.Copy(bEpcArray, bEpcCopy, EpcLen); string strEpcAll = SerialPortUtil.ByteToStr(bEpcCopy); int iEpcIndex = 0;//单张EPC的长度在bEpcCopy中的位置 for (int i = 0; i < CardCount; i++) { int iEpcLen = bEpcCopy[iEpcIndex]; //epc的长度 string strEpc = strEpcAll.Substring(iEpcIndex * 2 + 2, iEpcLen * 2); //得到一个EPC数据 iEpcIndex = iEpcIndex + iEpcLen + 1; //下一个EPC标签的 标签长度指示位置 if (strEpc.Length != 12) { break; } bool blHas = false; if (dicEpcInfo.ContainsKey(strEpc)) {//存在标签信息 #region 顺序读取 if (usingReadNo == DeviceUsing.启用) { if (dicEpcInfo[strEpc].IntAnt != Ant) { //查询到标签的天线和原来的不一样 if ((dicEpcInfo[strEpc].IntAnt & 0x01) == 0x01 || (dicEpcInfo[strEpc].IntAnt & 0x02) == 0x02) { //归还 原来是1# 2#天线扫描到 if ((Ant & 0x04) == 0x04 || (Ant & 0x08) == 0x08) { //现在是3# 4#天线扫描到 dicEpcInfo[strEpc].BorrOrRet = ToolsBorrRet.归还; dicEpcInfo[strEpc].DtReadedEpc = DateTime.Now; RfidManage.QEpcInfo.Enqueue(dicEpcInfo[strEpc]); } } else { //借出 if ((dicEpcInfo[strEpc].IntAnt & 0x04) == 0x04 || (dicEpcInfo[strEpc].IntAnt & 0x08) == 0x08) { //原来是3# 4#天线扫描到 if ((Ant & 0x01) == 0x01 || (Ant & 0x02) == 0x02) { //现在是1# 2#天线扫描到 dicEpcInfo[strEpc].BorrOrRet = ToolsBorrRet.借出; dicEpcInfo[strEpc].DtReadedEpc = DateTime.Now; RfidManage.QEpcInfo.Enqueue(dicEpcInfo[strEpc]); } } } dicEpcInfo[strEpc].IntAnt = Ant; } dicEpcInfo[strEpc].UsingReadNo = DeviceUsing.启用; } blHas = true; #endregion } else { EpcInfo ei = new EpcInfo(strEpc, Ant); ei.TimeLastRead = DateTime.Now; if (usingReadNo == DeviceUsing.启用) { ei.UsingReadNo = DeviceUsing.启用; } ei.BorrOrRet = ToolsBorrRet.未知; ei.IsEpcRead = IsReadShow.未读; dicEpcInfo.Add(strEpc, ei); } } } else { iReadEpcErr++; blRet = false; } blScan = false; } catch (Exception ee) { if (frmMain.blDebug) { MessageUtil.ShowTips(ee.Message); } } return(blRet); }