static void StartPolling(SerialReader reader, DemoArgs demoArgs) { var cs = ConnectionString.Parse(demoArgs.ConnectionString); Task.Run(async() => { temperatureSubject.OnNext(reader.GetReaderTemperature().Result); var processingTime = new Stopwatch(); var sw = Stopwatch.StartNew(); while (true) { try { processingTime.Stop(); var pTime = processingTime.Elapsed; var res = await reader.TagInventory(new TagInventoryParams { QValue = (byte)cs.QValue, Session = (SessionValue)cs.Session }); processingTime.Restart(); pollingResults.OnNext(new TagInventoryResultWithProcessingTime { Result = res, ProcessingTime = pTime }); if (sw.ElapsedMilliseconds > 10000) { var t = reader.GetReaderTemperature().Result; if (t > demoArgs.ThermalLimit) { Console.WriteLine( $"Reader is overheating, temperature is {t}. To prevent damage, stopping inventory."); Environment.Exit(t); } temperatureSubject.OnNext(t); sw.Restart(); } } catch (Exception ex) { Console.WriteLine(ex); } } }); }
static void SetInventoryOptions(SerialReader reader, DemoArgs demoArgs) { var cs = ConnectionString.Parse(demoArgs.ConnectionString); reader.SetAntennaCheck(false).Wait(); reader.SetAntennaConfiguration((GenAntennaConfiguration)cs.AntennaConfiguration).Wait(); reader.SetDrmEnabled(demoArgs.EnableDrmMode).Wait(); reader.SetRealTimeInventoryParameters(new RealtimeInventoryParams { QValue = (byte)cs.QValue, Session = (SessionValue)cs.Session, TagDebounceTime = TimeSpan.Zero }).Wait(); reader.SetInventoryScanInterval(TimeSpan.FromMilliseconds(cs.InventoryDuration)).Wait(); }
static void SubscribeToPollingResults(DemoArgs demoArgs) { pollingResults.Buffer(TimeSpan.FromMilliseconds(demoArgs.StatsSamplingInterval)) .Where(x => x.Count > 0) .Subscribe(buf => { var bufferedTags = buf.SelectMany(x => x.Result.Tags).ToList(); var inventoryDuration = new Triple(buf.Select(x => x.Result.Elapsed.TotalMilliseconds)); var processingDuration = new Triple(buf.Select(x => x.ProcessingTime.TotalMilliseconds)); var rpsStats = RpsCounter.Count(bufferedTags, demoArgs.StatsSamplingInterval); DisplayInventoryInfo(demoArgs, rpsStats, buf.Count * 1000 / demoArgs.StatsSamplingInterval, inventoryDuration, processingDuration); }); }
static void SubscribeToStreamingResults(DemoArgs demoArgs) { tagStreamErrors.Subscribe(x => { Console.WriteLine(x); Environment.Exit(0); }); tagStream.Buffer(TimeSpan.FromMilliseconds(demoArgs.StatsSamplingInterval)) .Where(x => x.Count > 0) .Subscribe(buf => { var rpsStats = RpsCounter.Count(buf, demoArgs.StatsSamplingInterval); DisplayInventoryInfo(demoArgs, rpsStats, 0, Triple.Empty, Triple.Empty); }); }
static void DisplayInventoryInfo(DemoArgs demoArgs, RpsStats rpsStats, int inventoryPs, Triple inventoryDuration, Triple processingDuration) { Console.Clear(); Console.WriteLine($"Connected to: {connectionString}, {demoArgs.Inventory} mode, update {updateNumber++}"); Console.WriteLine($"Reader Temp={temperatureSubject.Value}, Limit={demoArgs.ThermalLimit}"); Console.WriteLine($"TagIds={rpsStats.TagIds}, RPS={rpsStats.RPS}, InventoryPS={inventoryPs}"); Console.WriteLine($"Inventory duration: {inventoryDuration}"); Console.WriteLine($"Processing duration: {processingDuration}"); foreach (var h in rpsStats.Histogram) { Console.Write("{0,6:F1}", h); } Console.WriteLine($" Avg={rpsStats.Average:F1}"); foreach (var h in rpsStats.AggTags .Where(x => string.IsNullOrWhiteSpace(demoArgs.TagIdFilter) || Regex.IsMatch(x.TagId, demoArgs.TagIdFilter))) { Console.WriteLine($"{h.TagId} {h.ReadCount}"); } }
static void ShowBasicReaderInfo(SerialReader reader, DemoArgs args) { reader.SetRFPower((byte)ConnectionString.Parse(args.ConnectionString).RFPower).Wait(); Console.WriteLine("Serial number: {0}", reader.GetSerialNumber().Result); var info = reader.GetReaderInfo().Result; Console.WriteLine("Model: {0}", info.Model); Console.WriteLine("FirmwareVersion: {0}", info.FirmwareVersion); Console.WriteLine("AntennaConfiguration: {0}", info.AntennaConfiguration); Console.WriteLine("SupportedProtocols: {0}", info.SupportedProtocols); Console.WriteLine("RFPower: {0}", info.RFPower); Console.WriteLine("InventoryScanInterval: {0}", info.InventoryScanInterval); if (args.Confirm) { Console.WriteLine("Press enter to start inventory cycle"); Console.ReadLine(); } Console.WriteLine("Performing inventory. Ctrl+C to stop"); }
static void SubscribeToInventoryResults(SerialReader reader, DemoArgs demoArgs) { SubscribeToPollingResults(demoArgs); SubscribeToStreamingResults(demoArgs); }