private void recordTag(Split tag) { if (_readerProfile.ReadingMode == ReadingMode.Desktop) { onAssignTag(tag); return; } if (_readerProfile.GatingEnabled) { TagsInView.AddOrUpdate(tag.Epc, new List <Split> { tag }, (key, tagsInView) => { if (tagsInView.Count > 100) { tagsInView.Clear(); } tagsInView.Add(tag); return(tagsInView); } ); RecentTags.AddOrUpdate(tag.Epc, tag, (key, oldTag) => tag); } else { onRecordTag(tag); } }
public List <Property> Resolve(List <string> tags) { List <Property> list = new List <Property>(); if (tags != null) { foreach (var tag in tags) { var parts = tag.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (!Exclusions.ContainsKey(_SelectedDomain) || !Exclusions[_SelectedDomain].Contains(parts[0])) { Property property = new Property(); if (parts.Length > 1) { property.Value = TypeResolver.Resolve(parts[1]); } string key = parts[0].Trim(); var found = TagItems.FirstOrDefault(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (found == null) { found = new TagMapViewModel(new TagMap() { Key = key }); TagItems.Add(found); } property.Name = found.Key; var counter = found.Model.Counters.FirstOrDefault(y => y.Key.Equals(y.Key, StringComparison.OrdinalIgnoreCase) && y.Domain.Equals(_SelectedDomain, StringComparison.OrdinalIgnoreCase)); if (counter == null) { counter = new Counter() { Key = key, Domain = _SelectedDomain }; found.Model.Counters.Add(counter); } counter.Count++; if (recenttags.Add(found.Key)) { RecentTags.Insert(0, found); if (RecentTags.Count > MaxRecentTags) { while (RecentTags.Count > MaxRecentTags) { RecentTags.RemoveAt(RecentTags.Count - 1); } } } list.Add(property); } } } RefreshFiltering(); return(list); }
internal void SetRecentTags(IEnumerable <string> tags) { foreach (var tag in tags) { var found = TagItems.FirstOrDefault(x => x.Key.Equals(tag, StringComparison.OrdinalIgnoreCase)); if (found != null && recenttags.Add(tag)) { RecentTags.Add(found); } } }
private void ReportTags() { if (_readerProfile.ReadingMode == ReadingMode.Desktop) { return; } onReportTags(new TagsReports($"{RecentTags.Count} recent tags and {TagsInView.Count} tags in view")); DateTime currentTime = DateTime.Now.ToLocalTime(); logger.Log(LogLevel.Trace, "RecentTags count: " + RecentTags.Count); logger.Log(LogLevel.Trace, $"TagsInView count: {TagsInView.Count}"); foreach (KeyValuePair <string, Split> recentTag in RecentTags) { TimeSpan difference = currentTime - recentTag.Value.DateTimeOfDay; if (difference.TotalSeconds > _readerProfile.GatingTime) { Split removedTag; if (RecentTags.TryRemove(recentTag.Key, out removedTag)) { logger.Log(LogLevel.Trace, "removed " + recentTag.Key); if (removedTag != null) { List <Split> tags; if (TagsInView.TryRemove(removedTag.Epc, out tags)) { logger.Log(LogLevel.Trace, $"TagsInView for {removedTag.Epc} count: {tags.Count}"); Split nearestTag = tags.OrderByDescending(x => x.Rssi).FirstOrDefault(); onRecordTag(nearestTag); } else { onRecordTag(removedTag); } } } else { logger.Log(LogLevel.Trace, "failed to remove recent tag: " + recentTag.Key); } } } }
public bool BeginReading() { RecentTags.Clear(); TagsInView.Clear(); if (_readerProfile.InventoryMode == InventoryMode.Buffer) { StartBufferRead(); } // Create a timer with a two second interval. _aTimer = new System.Timers.Timer(100); // Hook up the Elapsed event for the timer. _aTimer.Elapsed += TimerTick; _aTimer.AutoReset = true; _aTimer.Enabled = false; // _aTimer.Enabled = true; StartReadDelay(); return(true); }
public bool StopReading() { RecentTags.Clear(); TagsInView.Clear(); switch (_readerProfile.InventoryMode) { case InventoryMode.Answer: _aTimer.Enabled = false; break; case InventoryMode.RealTime: _aTimer.Enabled = false; break; case InventoryMode.Buffer: stopBufferRead(); break; } return(true); }
private void Inventory() { int readSuppressionTime = 1; // = _readerProfile.Settings.ReadSuppressionTime; int maxReadUpdateTime = 1; // = _readerProfile.Settings.MaxReadUpdateTime; int minNewReadTime = 1; // = _readerProfile.Settings.MinNewReadTime; byte Qvalue = Convert.ToByte(5); byte Session = Convert.ToByte((int)_readerProfile.InventorySearchMode); byte AdrTID = 0; byte LenTID = 0; byte TIDFlag = 0; byte[] EPC = new byte[5000]; int CardIndex; int CardNum = 0; int Totallen = 0; int EPClen, m; string s, sEPC; string temps; int fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, Qvalue, Session, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, comPortIndex); if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB)) //end of read { byte[] daw = new byte[Totallen]; Array.Copy(EPC, daw, Totallen); temps = ByteArrayToHexString(daw); // fInventory_EPC_List = temps; //存贮记录 m = 0; if (CardNum == 0) { // fIsInventoryScan = false; return; } string lastEPC = ""; for (CardIndex = 0; CardIndex < CardNum; CardIndex++) { EPClen = daw[m]; sEPC = temps.Substring(m * 2 + 2, EPClen * 2); lastEPC = sEPC; string RSSI = temps.Substring(m * 2 + 2 + EPClen * 2, 2); m = m + EPClen + 2; if (sEPC.Length != EPClen * 2) { return; } var readTime = DateTime.Now; var tag = new Split { DateTimeOfDay = readTime, TimeOfDay = readTime.ToString("hh.mm.ss.ff"), Epc = sEPC, Rssi = Convert.ToInt32(RSSI, 16), SplitName = _readerProfile.Name, SplitDeviceId = _readerProfile.Id, InventorySearchMode = _readerProfile.InventorySearchMode }; if (_readerProfile.ReadingMode == ReadingMode.Desktop) { onAssignTag(tag); } else { if (RecentTags.ContainsKey(tag.Epc)) { Split foundTag = null; // foundTag = RecentTags[tag.Epc]; // var nowSeconds = DateTime.Now.yo // var secondsOld = foundTag(DateTimeOfDay.AddSeconds(- DateTime.Now)) DateTime lastReadTime = foundTag.DateTimeOfDay; DateTime rightNow = DateTime.Now; TimeSpan timeSpan = rightNow - lastReadTime; if (timeSpan.Seconds <= readSuppressionTime) { //log filter tag //update tag // RecentTags.TryRemove(tag.Epc, out foundTag); // RecentTags.TryAdd(tag.Epc, tag); } if (timeSpan.Seconds > readSuppressionTime && timeSpan.Seconds <= maxReadUpdateTime) { //update tag // RecentTags.TryRemove(tag.Epc, out foundTag); // RecentTags.TryAdd(tag.Epc, tag); } if (timeSpan.Seconds > maxReadUpdateTime && timeSpan.Seconds < minNewReadTime) { //update tag // RecentTags.TryRemove(tag.Epc, out foundTag); // RecentTags.TryAdd(tag.Epc, tag); } if (timeSpan.Seconds >= minNewReadTime) { //update tag // RecentTags.TryRemove(tag.Epc, out foundTag); // RecentTags.TryAdd(tag.Epc, tag); } } else { // RecentTags.TryAdd(tag.Epc, tag); } onRecordTag(tag); } } } }