基于读取车载RFID标签自动开关车库门c#算法实现
生活随笔
收集整理的這篇文章主要介紹了
基于读取车载RFID标签自动开关车库门c#算法实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近做物聯網自動識別技術,遇到一個算法難題,如下發給大家分享:
1 問題描述
2.流程圖稍后上,
3.編碼實現
編碼實現using System; using System.Collections.Generic; using System.Linq; using System.Text; using log4net; using Org.LLRP.LTK.LLRPV1; using Org.LLRP.LTK.LLRPV1.DataType; using Org.LLRP.LTK.LLRPV1.Impinj; using System.Collections.Concurrent; using System.Diagnostics; using System.Collections.ObjectModel; using com.dn.Edgenode.Plugins.Data; using com.dn.Edgenode.Plugins.Rfid.Impinj; using com.dn.Edgenode.Plugins.Rfid.Impinj.Config; using System.Text.RegularExpressions;namespace com.dn. {internal class TagFilter : Filter<NormalizedData>{private static ILog log = log4net.LogManager.GetLogger("com.dn.Edgenode.Log.Engine.Plugin");private Dictionary<string, DateTime> tagGroupTimeDic = new Dictionary<string, DateTime>();public object device { get; set; }public override Func<NormalizedData, bool> Condition{get{return FilterEpcByConf;}set{throw new NotImplementedException();}}private bool FilterEpcByConf(NormalizedData dataSource){bool re = false;ReaderSite rs = this.device as ReaderSite;string epc = dataSource.Data["Epc"].ToString();#region Fiter by Regex ruleif (!string.IsNullOrEmpty(rs.ReaderCfg.filter.rule.Value) && !rs.ReaderCfg.filter.rule.operation.Equals(null)){if (Regex.IsMatch(epc, rs.ReaderCfg.filter.rule.Value)){if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.Submit){//do nothing// continue Fiter by Time.}else if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.None){//Ignored Fiter by Timereturn false;}}}#endregion#region Fiter by TimereaderCfgTagGroup tagsArray = rs.ReaderCfg.tagGroups.Where(p => p.tag.Contains(epc)).FirstOrDefault();//epc not in config or this tag's tagGroup is disanable ,Submit dataif (tagsArray == null || tagsArray.Enabled == false || tagsArray.tag == null || tagsArray.tag.Length == 0){re = true;}else{DateTime dtNow = DateTime.Now;if (!tagGroupTimeDic.ContainsKey(epc)){//Submit datare = true;}else{DateTime epcTime = tagGroupTimeDic[epc];//find max time, it is the last time of reading the any of tags in the group.foreach (string epcItem in tagsArray.tag){if (tagGroupTimeDic.ContainsKey(epcItem)){epcTime = tagGroupTimeDic[epcItem] > epcTime ? tagGroupTimeDic[epcItem] : epcTime;}}//check timeif (dtNow.Subtract(epcTime).TotalMilliseconds > tagsArray.readingTimeout){re = true;// the timespan is greater than reading timeout, it means the group of tags has left the reader before already.// so, remove all.(so the act will be as the same as the firs seen of them for the reader.)foreach (string epcItem in tagsArray.tag){if (tagGroupTimeDic.ContainsKey(epcItem)){tagGroupTimeDic.Remove(epcItem);}}}else{//do nothingre = false;}}// add/update the reading time.tagGroupTimeDic[epc] = dtNow;}if (!re){log.InfoFormat("EPC Ignored: {0}", epc);}#endregionreturn re;}} }?
轉載于:https://www.cnblogs.com/sung/archive/2012/08/23/2652647.html
總結
以上是生活随笔為你收集整理的基于读取车载RFID标签自动开关车库门c#算法实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2440,6410,210存储器接口比较
- 下一篇: c++ mfc