impinj固定式阅读器数据解析中Rfid筛选器实现
在做物聯網倉庫管理中用到RFID標簽進行盤點和出庫掃描檢查,其中在倉庫門口的impinj固定式閱讀器對進出的貨物進行檢測,在讀取rfid時候需要對epc標簽進行過濾,實現2個過濾器,第一個是正則過濾,第二個是時間,在60秒內只讀取一次,默認tag是一秒讀200次,下面是過濾器的實現:輸入
dataSource--tag信息類
device---設備配置類(包含讀取時間和過濾條件的xml,在最后)
???????
???????
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 Data
{
??? public 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)
??????? {
??????????? ReaderSite rs = this.device as ReaderSite;
??????????? TagData tag = dataSource as TagData;
??????????? string epc = tag.Data["Epc"].ToString();
??????????? bool re = false;
??????????? #region Fiter by Regex rule
??????????? try
??????????? {
??????????????? if (!string.IsNullOrEmpty(rs.ReaderCfg.filter.rule.Value) && rs.ReaderCfg.filter.rule.operation != null)
??????????????? {
??????????????????? if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.Submit)
??????????????????? {
??????????????????????? if (!Regex.IsMatch(epc, rs.ReaderCfg.filter.rule.Value))
??????????????????????? {
??????????????????????????? return false;
??????????????????????? }
??????????????????????? else
??????????????????????? {
??????????????????????????? //do nothing
??????????????????????? }
??????????????????? }
??????????????????? else if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.None)
??????????????????? {
??????????????????????? if (Regex.IsMatch(epc, rs.ReaderCfg.filter.rule.Value))
??????????????????????? {
??????????????????????????? return false;
??????????????????????? }
??????????????????????? else
??????????????????????? {
??????????????????????????? //do nothing
??????????????????????? }
??????????????????? }
??????????????? }
??????????? }
??????????? catch(Exception ex)
??????????? {
??????????????? log.ErrorFormat("FilterEpcByConf: do fiter by rule error: {0}", ex.Message);
??????????? }
??????????? #endregion
??????????? #region Fiter by Time
??????????? try
??????????? {
??????????????? string[] epcGroup = null;
??????????????? int readingTimeout = 0;
??????????????? //epc not in config ,Submit datas
??????????????? foreach (readerCfgTagGroup rg in rs.ReaderCfg.tagGroups)
??????????????? {
??????????????????? if (rg.Enabled == true && rg.Value.Contains(epc))
??????????????????? {
??????????????????????? epcGroup = rg.Value.Split(';');
??????????????????????? readingTimeout = rg.readingTimeout;
??????????????????????? break;
??????????????????? }
??????????????? }
??????????????? //epc not in config or this tag's tagGroup is disanable ,Submit data
??????????????? if (epcGroup == null || epcGroup.Length == 0)
??????????????? {
??????????????????? return true;
??????????????? }
??????????????? if (!tagGroupTimeDic.ContainsKey(epc))
??????????????? {
??????????????????? //Submit data
??????????????????? re = true;
??????????????????? tagGroupTimeDic.Add(epc, DateTime.Now);
??????????????? }
??????????????? else
??????????????? {
??????????????????? DateTime dtNow = DateTime.Now;
??????????????????? DateTime epcTime = tagGroupTimeDic[epc];
??????????????????? //find max time
??????????????????? foreach (string epcItem in epcGroup)
??????????????????? {
??????????????????????? if (tagGroupTimeDic.ContainsKey(epcItem))
??????????????????????? {
??????????????????????????? epcTime = tagGroupTimeDic[epcItem] < epcTime ? tagGroupTimeDic[epcItem] : epcTime;
??????????????????????? }
??????????????????? }
??????????????????? //check time
??????????????????? if (dtNow.Subtract(epcTime).TotalMilliseconds > readingTimeout)
??????????????????? {
??????????????????????? re = true;
??????????????????????? foreach (string epcItem in epcGroup)
??????????????????????? {
??????????????????????????? if (tagGroupTimeDic.ContainsKey(epcItem))
??????????????????????????? {
??????????????????????????????? tagGroupTimeDic.Remove(epcItem);
??????????????????????????? }
??????????????????????? }
??????????????????????? tagGroupTimeDic[epc] = dtNow;
??????????????????? }
??????????????????? else
??????????????????? {
??????????????????????? //do nothing
??????????????????????? re = false;
??????????????????? }
??????????????? }
??????????? }
??????????? catch (Exception ex)
??????????? {
??????????????? log.ErrorFormat("FilterEpcByConf: do fiter by rule error: {0}", ex.Message);
??????????? }
??????????? #endregion
??????????? return re;
??????? }
??? }
}
轉載于:https://www.cnblogs.com/sung/archive/2012/08/22/2651086.html
總結
以上是生活随笔為你收集整理的impinj固定式阅读器数据解析中Rfid筛选器实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 货车增压器扫了点轮残渣会进发动机吗?
- 下一篇: 医疗在线服务InQuicker,融资0元