public override void ListenReader() { Task.Factory.StartNew(() => { while (shouldListenReader) { byte fComAdr = 0; // Multiply query parameters. byte Qvalue = 4; byte Session = 255; byte MaskMem = 0; byte[] MaskAdr = new byte[2]; byte MaskLen = 0; byte[] MaskData = new byte[100]; byte MaskFlag = 0; byte AdrTID = 0; byte LenTID = 6; byte TIDFlag = 0; byte Target = 0; byte InAnt = 0x80; byte Scantime = 20; byte FastFlag = 0; byte[] EPC = new byte[50000]; byte Ant = 0; int Totallen = 0; int TagNum = 0; int frmcomportindex = 1; int fCmdRet = RWDev.Inventory_G2( ref fComAdr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, Scantime, FastFlag, EPC, ref Ant, ref Totallen, ref TagNum, frmcomportindex ); Thread.Sleep(5); } }); }
/// <summary> /// Calls Inventory_G2 with own parameters and the number of the port of the reader. /// </summary> /// <param name="portNum"></param> /// <returns> /// Returns fCmdRet that represents information about the process /// </returns> public int DoInventory(int portNum) { return(RWDev.Inventory_G2( ComAdr: ref FComAddress, QValue: QValue, Session: Session, MaskMem: MaskMem, MaskAdr: MaskAdr, MaskLen: MaskLen, MaskData: MaskData, MaskFlag: MaskFlag, AdrTID: AdrTID, LenTID: LenTID, TIDFlag: TIDFlag, Target: Target, InAnt: InAnt, Scantime: Scantime, FastFlag: FastFlag, pEPCList: EPC, Ant: ref Ant, Totallen: ref Totallen, CardNum: ref CardNum, frmComPortindex: portNum)); }
private void flash_G2() { Session = Convert.ToByte((int)_readerProfile.InventorySearchMode); Qvalue = Convert.ToByte(4); byte Ant = 0x80; int CardNum = 0; int Totallen = 0; int EPClen, m; byte[] EPC = new byte[50000]; int CardIndex; string temps, temp; temp = ""; string sEPC; 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; AdrTID = 0; LenTID = 6; MaskFlag = 0; int cbtime = System.Environment.TickCount; CardNum = 0; fCmdRet = RWDev.Inventory_G2(ref fComAdr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, Scantime, FastFlag, EPC, ref Ant, ref Totallen, ref CardNum, frmcomportindex); int cmdTime = System.Environment.TickCount - cbtime;//命令时间 if ((fCmdRet == 0x30) || (fCmdRet == 0x37)) { if (_readerProfile.ConnectionType == ConnectionType.Ethernet) { if (frmcomportindex > 1023) { fCmdRet = RWDev.CloseNetPort(frmcomportindex); if (fCmdRet == 0) { frmcomportindex = -1; } Thread.Sleep(1000); } fComAdr = 255; string ipAddress = _readerProfile.IpAddress; int nPort = Convert.ToInt32("27011"); fCmdRet = RWDev.OpenNetPort(nPort, ipAddress, ref fComAdr, ref frmcomportindex); } } if (CardNum == 0) { if (Session > 1) { AA_times = AA_times + 1;//没有得到标签只更新状态栏 } IntPtr ptrWnd = IntPtr.Zero; // ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16"); if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开 { string para = fCmdRet.ToString(); // SendMessage(ptrWnd, WM_SENDSTATU, IntPtr.Zero, para); } return; } AA_times = 0; if ((fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 0x26)) //代表已查找结束, { byte[] daw = new byte[Totallen]; Array.Copy(EPC, daw, Totallen); temps = ByteArrayToHexString(daw); if (fCmdRet == 0x26) { string SDCMD = temps.Substring(0, 12); temps = temps.Substring(12); daw = HexStringToByteArray(temps); byte[] datas = new byte[6]; datas = HexStringToByteArray(SDCMD); int tagrate = datas[0] * 256 + datas[1]; int tagnum = datas[2] * 256 * 256 * 256 + datas[3] * 256 * 256 + datas[4] * 256 + datas[5]; total_tagnum = total_tagnum + tagnum; IntPtr ptrWnd = IntPtr.Zero; // ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16"); if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开 { string para = tagrate.ToString() + "," + total_tagnum.ToString() + "," + cmdTime.ToString(); // SendMessage(ptrWnd, WM_SENDTAGSTAT, IntPtr.Zero, para); } } m = 0; List <string> epsList = new List <string>(); for (CardIndex = 0; CardIndex < CardNum; CardIndex++) { EPClen = daw[m] + 1; temp = temps.Substring(m * 2 + 2, EPClen * 2); sEPC = temp.Substring(0, temp.Length - 2); int RSSI = Convert.ToInt32(temp.Substring(temp.Length - 2, 2), 16); m = m + EPClen + 1; if (sEPC.Length != (EPClen - 1) * 2) { return; } if (epsList.Contains(sEPC)) { continue; } epsList.Add(sEPC); IntPtr ptrWnd = IntPtr.Zero; // ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16"); if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开 { string para = sEPC + "," + RSSI.ToString() + " "; // SendMessage(ptrWnd, WM_SENDTAG, IntPtr.Zero, para); } var readTime = DateTime.Now; var tag = new Split { DateTimeOfDay = readTime, TimeOfDay = readTime.ToString("hh.mm.ss.ff"), Epc = sEPC, Rssi = RSSI, SplitName = _readerProfile.Name, SplitDeviceId = _readerProfile.Id, InventorySearchMode = _readerProfile.InventorySearchMode, Antenna = Ant.ToString() }; recordTag(tag); } } }
private void inventory() { byte Ant = 0; int CardNum = 0; int Totallen = 0; int EPClen, m; byte[] EPC = new byte[50000]; int CardIndex; string temps, temp; temp = ""; string sEPC; 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; DataGridViewRow rows = new DataGridViewRow(); ErrorsCatcher.errorName = RWDev.Inventory_G2(ref RWDev.comAddress, RWDev.QValue, RWDev.session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, RWDev.TIDFlag, RWDev.target, RWDev.inAnt, scantime, RWDev.fastFlag, EPC, ref Ant, ref Totallen, ref CardNum, RWDev.frmComPortIndex); resultTime = DateTime.Now; if ((ErrorsCatcher.errorName == 1) | (ErrorsCatcher.errorName == 2) | (ErrorsCatcher.errorName == 3) | (ErrorsCatcher.errorName == 4)) { byte[] daw = new byte[Totallen]; Array.Copy(EPC, daw, Totallen); temps = ConverterTo.ByteArrayToHexString(daw); m = 0; if (CardNum == 0) { return; } for (CardIndex = 0; CardIndex < CardNum; CardIndex++) { EPClen = daw[m] + 1; temp = temps.Substring(m * 2 + 2, EPClen * 2); sEPC = temp.Substring(0, temp.Length - 2); string RSSI = Convert.ToInt32(temp.Substring(temp.Length - 2, 2), 16).ToString(); m = m + EPClen + 1; if (sEPC.Length != (EPClen - 1) * 2) { return; } if (!scanData.ContainsKey(sEPC)) { scanData.Add(sEPC, resultTime); richTextBoxLogs.AppendText(resultTime.ToString() + " goods with RFID " + sEPC + " scaned." + Environment.NewLine); Task sendToServer = Task.Run(() => { try { Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); var client = new ScannerServer.ScannerServerClient(channel); var reply = client.SendDataToServer(new SendRequest { GoodsInfo = { RFID = sEPC, Time = resultTime.ToString() } }); } catch { richTextBoxLogs.AppendText("Send data to server failed!" + Environment.NewLine); } }); } } } }