private void GetRealtiemeData() { byte[] ScanModeData = new byte[40960]; int nLen, NumLen; string temp1 = ""; string binarystr1 = ""; string binarystr2 = ""; string RSSI = ""; string AntStr = ""; string lenstr = ""; string EPCStr = ""; int ValidDatalength; string temp; ValidDatalength = 0; DataGridViewRow rows = new DataGridViewRow(); int xtime = System.Environment.TickCount; fCmdRet = RWDev.ReadActiveModeData(ScanModeData, ref ValidDatalength, frmcomportindex); if (fCmdRet == 0) { try { byte[] daw = new byte[ValidDatalength]; Array.Copy(ScanModeData, 0, daw, 0, ValidDatalength); temp = ByteArrayToHexString(daw); fInventory_EPC_List = fInventory_EPC_List + temp;//把字符串存进列表 nLen = fInventory_EPC_List.Length; while (fInventory_EPC_List.Length > 18) { string FlagStr = Convert.ToString(fComAdr, 16).PadLeft(2, '0') + "EE00";//查找头位置标志字符串 int nindex = fInventory_EPC_List.IndexOf(FlagStr); if (nindex > 1) { fInventory_EPC_List = fInventory_EPC_List.Substring(nindex - 2); } else { fInventory_EPC_List = fInventory_EPC_List.Substring(2); continue; } NumLen = Convert.ToInt32(fInventory_EPC_List.Substring(0, 2), 16) * 2 + 2;//取第一个帧的长度 if (fInventory_EPC_List.Length < NumLen) { break; } temp1 = fInventory_EPC_List.Substring(0, NumLen); fInventory_EPC_List = fInventory_EPC_List.Substring(NumLen); if (!CheckCRC(temp1)) { continue; } AntStr = Convert.ToString(Convert.ToInt32(temp1.Substring(8, 2), 16), 2).PadLeft(4, '0'); lenstr = Convert.ToString(Convert.ToInt32(temp1.Substring(10, 2), 16), 10); EPCStr = temp1.Substring(12, temp1.Length - 18); RSSI = temp1.Substring(temp1.Length - 6, 2); var readTime = DateTime.Now; var tag = new Split { DateTimeOfDay = readTime, TimeOfDay = readTime.ToString("hh.mm.ss.ff"), Epc = EPCStr, Rssi = int.Parse(RSSI), SplitName = _readerProfile.Name, SplitDeviceId = _readerProfile.Id, InventorySearchMode = _readerProfile.InventorySearchMode, Antenna = AntStr }; if (_readerProfile.ReadingMode == ReadingMode.Desktop) { onAssignTag(tag); continue; } onRecordTag(tag); } } catch (System.Exception ex) { ex.ToString(); } } }