private void MenuItem_inventory_Click(object sender, EventArgs e) { InventoryResult result = _driver.Inventory(GetCurrentReaderName(), "only_new"); MessageBox.Show(this, result.ToString()); if (result.Results != null && result.Results.Count > 0) { _inventory_info = result.Results[0]; } else { _inventory_info = null; } }
async Task DoInventory() { Program.MainForm.OutputHistory("开始捕获", 0); if (Program.Rfid.Readers.Count == 0) { Program.MainForm.OutputHistory("当前没有可用的读卡器", 2); } else { List <string> names = new List <string>(); Program.Rfid.Readers.ForEach((o) => names.Add(o.Name)); Program.MainForm.OutputHistory($"当前读卡器数量 {Program.Rfid.Readers.Count}。包括: \r\n{StringUtil.MakePathList(names,"\r\n")}", 0); } _cancelInventory = new CancellationTokenSource(); bool bFirst = true; try { // uid --> Driver Name // Hashtable uid_table = new Hashtable(); while (_cancelInventory.IsCancellationRequested == false) { await Task.Delay(200, _cancelInventory.Token).ConfigureAwait(false); ClearIdleTag(TimeSpan.FromSeconds(1)); // 1 秒的防误触发时间 FlushCompactLog(); //if (_captureEnabled.Value == false) // continue; // uid_table.Clear(); foreach (Reader reader in Program.Rfid.Readers) { if (reader == null) { continue; } if (string.IsNullOrEmpty(Program.Rfid.State) == false) { break; } InventoryResult inventory_result = Program.Rfid.Inventory( reader.Name, bFirst ? "" : "only_new"); // bFirst = false; if (inventory_result.Value == -1) { _compactLog?.Add($"*** 读卡器 {0} 点选标签时出错: {1}", new object[] { reader.Name, inventory_result.ToString() } ); continue; // ioError 要主动卸载有问题的 reader? // 如何报错?写入操作历史? // Program.MainForm.OutputHistory($"读卡器{reader.Name}点选标签时出错:{inventory_result.ToString()}\r\n已停止捕获过程", 2); // return; } foreach (InventoryInfo info in inventory_result.Results) { //if (uid_table.ContainsKey(info.UID)) // continue; //uid_table[info.UID] = reader.Name; AddToTagList(reader.Name, info.UID, info.DsfID, info.Protocol); } } } } catch (TaskCanceledException) { } finally { _cancelInventory = null; Program.MainForm.OutputHistory("结束捕获", 0); } }
async Task DoInventory() { Program.MainForm.OutputHistory("开始捕获", 0); if (Program.Rfid.Readers.Count == 0) { Program.MainForm.OutputHistory("当前没有可用的读卡器", 2); } _cancelInventory = new CancellationTokenSource(); bool bFirst = true; try { while (_cancelInventory.IsCancellationRequested == false) { await Task.Delay(200, _cancelInventory.Token).ConfigureAwait(false); ClearIdleTag(TimeSpan.FromSeconds(1)); // 1 秒的放误触发时间 //if (_captureEnabled.Value == false) // continue; foreach (Reader reader in Program.Rfid.Readers) { if (reader == null) { continue; } InventoryResult inventory_result = Program.Rfid.Inventory( reader.Name, bFirst ? "" : "only_new"); // bFirst = false; if (inventory_result.Value == -1) { // ioError 要主动卸载有问题的 reader? // 如何报错?写入操作历史? Program.MainForm.OutputHistory($"读卡器{reader.Name}点选标签时出错:{inventory_result.ToString()}\r\n已停止捕获过程", 2); // Task.Delay(500, _cancelInventory.Token); return; } foreach (InventoryInfo info in inventory_result.Results) { AddToTagList(reader.Name, info.UID, info.DsfID, info.Protocol); } } } } catch (TaskCanceledException) { } finally { _cancelInventory = null; Program.MainForm.OutputHistory("结束捕获", 0); } }