private void setupReaderConfiguration() { String PARAM_STR_REGION = "/reader/region/id"; String PARAM_STR_SESSION = "/reader/gen2/session"; String PARAM_STR_READPLAN = "/reader/read/plan"; //Set the region to NA if (Reader.Region.UNSPEC == (Reader.Region)reader.ParamGet(PARAM_STR_REGION)) { Reader.Region[] supportedRegions = (Reader.Region[])reader.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { reader.ParamSet(PARAM_STR_REGION, supportedRegions[0]); } } //Set the session to session 0 reader.ParamSet(PARAM_STR_SESSION, Gen2.Session.S0); //Get the region Reader.Region region = (Reader.Region)reader.ParamGet(PARAM_STR_REGION); Console.WriteLine("The current region is " + region); //Get the session Gen2.Session session = (Gen2.Session)reader.ParamGet(PARAM_STR_SESSION); Console.WriteLine("The current session is " + session); //Get the read plan ReadPlan rp = (ReadPlan)reader.ParamGet(PARAM_STR_READPLAN); Console.WriteLine("Read plan: " + rp); }
public void configTM(int power = 3000) { int[] antennaList = { 1, 2, 3, 4 }; //选择天线1,2,3,4 mReaderTM.ParamSet("/reader/region/id", Reader.Region.NA); SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000); //设置天线和协议 mReaderTM.ParamSet("/reader/read/plan", plan); //场景配置,用于隧道机 Gen2.LinkFrequency blf = Gen2.LinkFrequency.LINK320KHZ; mReaderTM.ParamSet("/reader/gen2/BLF", blf); Gen2.Tari tari = Gen2.Tari.TARI_6_25US; mReaderTM.ParamSet("/reader/gen2/tari", tari); Gen2.TagEncoding tagncoding = Gen2.TagEncoding.FM0; mReaderTM.ParamSet("/reader/gen2/tagEncoding", tagncoding); Gen2.Session session = Gen2.Session.S1; mReaderTM.ParamSet("/reader/gen2/session", session); Gen2.Target target = Gen2.Target.A; mReaderTM.ParamSet("/reader/gen2/target", target); //500~3150 mReaderTM.ParamSet("/reader/radio/readPower", power); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="target"></param> /// <param name="filter"></param> /// <param name="antID"></param> public CustomAntConfigPerAntenna(Gen2.Session session, Gen2.Target target, TagFilter filter, int antID) { this.session = session; this.target = target; this.filter = filter; this.antID = antID; }
public virtual bool ConnectReader() { try { if (reader == null) { return(false); } reader.Connect(); int[] antennaList = { 1, 2, 3, 4 }; //选择天线1,2,3,4 reader.ParamSet("/reader/region/id", Reader.Region.NA); SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000); //设置天线和协议 reader.ParamSet("/reader/read/plan", plan); //场景配置,用于隧道机 Gen2.LinkFrequency blf = Gen2.LinkFrequency.LINK320KHZ; reader.ParamSet("/reader/gen2/BLF", blf); Gen2.Tari tari = Gen2.Tari.TARI_6_25US; reader.ParamSet("/reader/gen2/tari", tari); Gen2.TagEncoding tagncoding = Gen2.TagEncoding.FM0; reader.ParamSet("/reader/gen2/tagEncoding", tagncoding); Gen2.Session session = Gen2.Session.S1; reader.ParamSet("/reader/gen2/session", session); Gen2.Target target = Gen2.Target.A; reader.ParamSet("/reader/gen2/target", target); //500~3150 reader.ParamSet("/reader/radio/readPower", SysConfig.mReaderPower); reader.TagRead += Reader_OnTagReported; reader.ReadException += new EventHandler <ReaderExceptionEventArgs>(r_ReadException); } catch (Exception ex) { Log4netHelper.LogError(ex); return(false); } return(true); }
private void setupReaderConfiguration() { String PARAM_STR_REGION = "/reader/region/id"; String PARAM_STR_SESSION = "/reader/gen2/session"; String PARAM_STR_READPLAN = "/reader/read/plan"; //Set the region to NA if (Reader.Region.UNSPEC == (Reader.Region)reader.ParamGet(PARAM_STR_REGION)) { Reader.Region[] supportedRegions = (Reader.Region[])reader.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } reader.ParamSet(PARAM_STR_REGION, supportedRegions[0]); } string model = reader.ParamGet("/reader/version/model").ToString(); if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } //Use first antenna for operation if (antennaList != null) { reader.ParamSet("/reader/tagop/antenna", antennaList[0]); } //Set the session to session 0 reader.ParamSet(PARAM_STR_SESSION, Gen2.Session.S0); //Get the region Reader.Region region = (Reader.Region)reader.ParamGet(PARAM_STR_REGION); Console.WriteLine("The current region is " + region); //Get the session Gen2.Session session = (Gen2.Session)reader.ParamGet(PARAM_STR_SESSION); Console.WriteLine("The current session is " + session); //Get the read plan ReadPlan rp = (ReadPlan)reader.ParamGet(PARAM_STR_READPLAN); Console.WriteLine("Read plan: " + rp); }
static void Main(string[] args) { // Program setup if (1 > args.Length) { Usage(); } int[] antennaList = null; for (int nextarg = 1; nextarg < args.Length; nextarg++) { string arg = args[nextarg]; if (arg.Equals("--ant")) { if (null != antennaList) { Console.WriteLine("Duplicate argument: --ant specified more than once"); Usage(); } antennaList = ParseAntennaList(args, nextarg); nextarg++; } else { Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg); Usage(); } } try { // Create Reader object, connecting to physical device. // Wrap reader in a "using" block to get automatic // reader shutdown (using IDisposable interface). using (Reader r = Reader.Create(args[0])) { // Uncomment this line to add default transport listener. // r.Transport += r.SimpleTransportListener; r.Connect(); if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } r.ParamSet("/reader/region/id", supportedRegions[0]); } if (r.isAntDetectEnabled(antennaList)) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } TagReadData[] tagReads; TagFilter filter; byte[] mask = new byte[4]; Gen2.Impinj.Monza4.QTPayload payLoad; Gen2.Impinj.Monza4.QTControlByte controlByte; Gen2.Impinj.Monza4.QTReadWrite readWrite; uint accesspassword = 0; //Use first antenna for operation if (antennaList != null) { r.ParamSet("/reader/tagop/antenna", antennaList[0]); } Gen2.Session session = Gen2.Session.S0; r.ParamSet("/reader/gen2/session", session); SimpleReadPlan readPlan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 public EPC in response Console.WriteLine("Reading tags with a Monza 4 public EPC in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); // Initialize the payload and the controlByte of Monza4 payLoad = new Gen2.Impinj.Monza4.QTPayload(); controlByte = new Gen2.Impinj.Monza4.QTControlByte(); Console.WriteLine("Changing to private Mode "); // Executing Monza4 QT Write Set Private tagop payLoad.QTMEM = false; payLoad.QTSR = false; controlByte.QTReadWrite = true; controlByte.Persistence = true; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); Console.WriteLine(); // Setting the session to S2 session = Gen2.Session.S2; r.ParamSet("/reader/gen2/session", session); // Enable filter mask[0] = (byte)0x20; mask[1] = (byte)0x01; mask[2] = (byte)0xB0; mask[3] = (byte)0x00; filter = new Gen2.Select(true, Gen2.Bank.TID, 0x04, 0x18, mask); Console.WriteLine("Reading tags private Mode with session s2 "); readPlan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with TID in response Console.WriteLine("Reading tags with a Monza 4 FastID with TID in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Setting the session to S0"); // Setting the session to S0 session = Gen2.Session.S0; r.ParamSet("/reader/gen2/session", session); mask[0] = (byte)0xE2; mask[1] = (byte)0x80; mask[2] = (byte)0x11; mask[3] = (byte)0x05; filter = new Gen2.Select(false, Gen2.Bank.TID, 0x00, 0x20, mask); Console.WriteLine("Reading tags private Mode with session s0 "); readPlan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with NO TID in response Console.WriteLine("Reading tags with a Monza 4 FastID with NO TID in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Converting to public mode"); // Executing Monza4 QT Write Set Public tagop payLoad.QTMEM = true; payLoad.QTSR = false; controlByte.QTReadWrite = true; controlByte.Persistence = true; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); Console.WriteLine(); // Enable filter mask[0] = (byte)0x20; mask[1] = (byte)0x01; mask[2] = (byte)0xB0; mask[3] = (byte)0x00; filter = new Gen2.Select(true, Gen2.Bank.TID, 0x04, 0x18, mask); Console.WriteLine("Reading tags public Mode with session s0 "); readPlan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with TID in response tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Reset the Read protect on "); // Reset the Read protect on payLoad.QTMEM = false; payLoad.QTSR = false; controlByte.QTReadWrite = false; controlByte.Persistence = false; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
static void Main(string[] args) { // Program setup int[] antennaList = { 1, 2, 3, 4 }; //选择天线1,2,3,4 try { Reader.SetSerialTransport("tcp", SerialTransportTCP.CreateSerialReader); // Create Reader object, connecting to physical device. // Wrap reader in a "using" block to get automatic // reader shutdown (using IDisposable interface). using (Reader r = Reader.Create("tcp://192.168.8.166:8086")) //创建对象 { r.Connect(); //连接读写器 r.ParamSet("/reader/region/id", Reader.Region.NA); // Create a simplereadplan which uses the antenna list created above SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000); //设置天线和协议 // Set the created readplan r.ParamSet("/reader/read/plan", plan); //场景配置,用于隧道机 Gen2.LinkFrequency blf = Gen2.LinkFrequency.LINK320KHZ; r.ParamSet("/reader/gen2/BLF", blf); Gen2.Tari tari = Gen2.Tari.TARI_6_25US; r.ParamSet("/reader/gen2/tari", tari); Gen2.TagEncoding tagncoding = Gen2.TagEncoding.FM0; r.ParamSet("/reader/gen2/tagEncoding", tagncoding); Gen2.Session session = Gen2.Session.S1; r.ParamSet("/reader/gen2/session", session); Gen2.Target target = Gen2.Target.A; r.ParamSet("/reader/gen2/target", target); //500~3150 r.ParamSet("/reader/radio/readPower", 3000); // 注册标签数据回调方法 r.TagRead += delegate(Object sender, TagReadDataEventArgs e) { Console.WriteLine("Background read: " + e.TagReadData); }; //创建异常回调方法 r.ReadException += new EventHandler <ReaderExceptionEventArgs>(r_ReadException); // 开始读卡 r.StartReading(); Console.WriteLine("\r\n<Do other work here>\r\n"); Thread.Sleep(5000); Console.WriteLine("\r\n<Do other work here>\r\n"); Thread.Sleep(10000); //结束读卡 r.StopReading(); } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); Console.Out.Flush(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
static void Main(string[] args) { // Program setup if (1 > args.Length) { Usage(); } int[] antennaList = null; for (int nextarg = 1; nextarg < args.Length; nextarg++) { string arg = args[nextarg]; if (arg.Equals("--ant")) { if (null != antennaList) { Console.WriteLine("Duplicate argument: --ant specified more than once"); Usage(); } antennaList = ParseAntennaList(args, nextarg); nextarg++; } else { Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg); Usage(); } } try { // Create Reader object, connecting to physical device. // Wrap reader in a "using" block to get automatic // reader shutdown (using IDisposable interface). using (Reader r = Reader.Create(args[0])) { //Uncomment this line to add default transport listener. //r.Transport += r.SimpleTransportListener; r.Connect(); TagReadData[] tagReads; if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } r.ParamSet("/reader/region/id", supportedRegions[0]); } if (r.isAntDetectEnabled(antennaList)) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } // In the current system, sequences of Gen2 operations require Session 0, // since each operation resingulates the tag. In other sessions, // the tag will still be "asleep" from the preceding singulation. Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session"); Gen2.Session newSession = Gen2.Session.S0; Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")"); r.ParamSet("/reader/gen2/session", newSession); // Create a simplereadplan which uses the antenna list created above SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000); // Set the created readplan r.ParamSet("/reader/read/plan", plan); try { // Find a tag to work on tagReads = r.Read(1000); if (0 == tagReads.Length) { Console.WriteLine("No tags found to work on"); return; } TagData t = tagReads[0].Tag; //Use first antenna for operation if (antennaList != null) { r.ParamSet("/reader/tagop/antenna", antennaList[0]); } // Lock the tag r.ExecuteTagOp(new Gen2.Lock(0, new Gen2.LockAction(Gen2.LockAction.EPC_LOCK)), t); Console.WriteLine("Locked EPC of tag " + t); // Unlock the tag r.ExecuteTagOp(new Gen2.Lock(0, new Gen2.LockAction(Gen2.LockAction.EPC_UNLOCK)), t); Console.WriteLine("Unlocked EPC of tag " + t); } finally { // Restore original settings Console.WriteLine("Restoring Session " + oldSession); r.ParamSet("/reader/gen2/session", oldSession); } } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
static void Main(string[] args) { // Program setup if (1 != args.Length) { Console.WriteLine(String.Join("\r\n", new string[] { "Please provide reader URL, such as:", "tmr:///com4", "tmr://my-reader.example.com", })); Environment.Exit(1); } try { // Create Reader object, connecting to physical device. // Wrap reader in a "using" block to get automatic // reader shutdown (using IDisposable interface). using (Reader r = Reader.Create(args[0])) { // Uncomment this line to add default transport listener. // r.Transport += r.SimpleTransportListener; r.Connect(); if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { r.ParamSet("/reader/region/id", supportedRegions[0]); } } TagReadData[] tagReads; TagFilter filter; byte[] mask = new byte[4]; Gen2.Impinj.Monza4.QTPayload payLoad; Gen2.Impinj.Monza4.QTControlByte controlByte; Gen2.Impinj.Monza4.QTReadWrite readWrite; uint accesspassword = 0; r.ParamSet("/reader/tagop/antenna", 1); Gen2.Session session = Gen2.Session.S0; r.ParamSet("/reader/gen2/session", session); SimpleReadPlan readPlan = new SimpleReadPlan(null, TagProtocol.GEN2, null, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 public EPC in response Console.WriteLine("Reading tags with a Monza 4 public EPC in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); // Initialize the payload and the controlByte of Monza4 payLoad = new Gen2.Impinj.Monza4.QTPayload(); controlByte = new Gen2.Impinj.Monza4.QTControlByte(); Console.WriteLine("Changing to private Mode "); // Executing Monza4 QT Write Set Private tagop payLoad.QTMEM = false; payLoad.QTSR = false; controlByte.QTReadWrite = true; controlByte.Persistence = true; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); Console.WriteLine(); // Setting the session to S2 session = Gen2.Session.S2; r.ParamSet("/reader/gen2/session", session); // Enable filter mask[0] = (byte)0x20; mask[1] = (byte)0x01; mask[2] = (byte)0xB0; mask[3] = (byte)0x00; filter = new Gen2.Select(true, Gen2.Bank.TID, 0x04, 0x18, mask); Console.WriteLine("Reading tags private Mode with session s2 "); readPlan = new SimpleReadPlan(null, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with TID in response Console.WriteLine("Reading tags with a Monza 4 FastID with TID in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Setting the session to S0"); // Setting the session to S0 session = Gen2.Session.S0; r.ParamSet("/reader/gen2/session", session); mask[0] = (byte)0xE2; mask[1] = (byte)0x80; mask[2] = (byte)0x11; mask[3] = (byte)0x05; filter = new Gen2.Select(false, Gen2.Bank.TID, 0x00, 0x20, mask); Console.WriteLine("Reading tags private Mode with session s0 "); readPlan = new SimpleReadPlan(null, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with NO TID in response Console.WriteLine("Reading tags with a Monza 4 FastID with NO TID in response"); tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Converting to public mode"); // Executing Monza4 QT Write Set Public tagop payLoad.QTMEM = true; payLoad.QTSR = false; controlByte.QTReadWrite = true; controlByte.Persistence = true; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); Console.WriteLine(); // Enable filter mask[0] = (byte)0x20; mask[1] = (byte)0x01; mask[2] = (byte)0xB0; mask[3] = (byte)0x00; filter = new Gen2.Select(true, Gen2.Bank.TID, 0x04, 0x18, mask); Console.WriteLine("Reading tags public Mode with session s0 "); readPlan = new SimpleReadPlan(null, TagProtocol.GEN2, filter, null, 1000); r.ParamSet("/reader/read/plan", readPlan); // Reading tags with a Monza 4 FastID with TID in response tagReads = r.Read(1000); foreach (TagReadData tagData in tagReads) { Console.WriteLine("Monza4 tag epc: " + tagData.EpcString); } Console.WriteLine(); Console.WriteLine("Reset the Read protect on "); // Reset the Read protect on payLoad.QTMEM = false; payLoad.QTSR = false; controlByte.QTReadWrite = false; controlByte.Persistence = false; readWrite = new Gen2.Impinj.Monza4.QTReadWrite(accesspassword, payLoad, controlByte); r.ExecuteTagOp(readWrite, null); } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
static void Main(string[] args) { // Program setup if (1 > args.Length) { Usage(); } int[] antennaList = null; for (int nextarg = 1; nextarg < args.Length; nextarg++) { string arg = args[nextarg]; if (arg.Equals("--ant")) { if (null != antennaList) { Console.WriteLine("Duplicate argument: --ant specified more than once"); Usage(); } antennaList = ParseAntennaList(args, nextarg); nextarg++; } else { Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg); Usage(); } } // Create Reader object, connecting to physical device try { Reader r; TagReadData[] tagReads, filteredTagReads; TagFilter filter; r = Reader.Create(args[0]); //Uncomment this line to add default transport listener. //r.Transport += r.SimpleTransportListener; r.Connect(); if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } r.ParamSet("/reader/region/id", supportedRegions[0]); } string model = r.ParamGet("/reader/version/model").ToString(); if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } // In the current system, sequences of Gen2 operations require Session 0, // since each operation resingulates the tag. In other sessions, // the tag will still be "asleep" from the preceding singulation. Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session"); Gen2.Session newSession = Gen2.Session.S0; Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")"); r.ParamSet("/reader/gen2/session", newSession); Console.WriteLine(); SimpleReadPlan srp = new SimpleReadPlan(antennaList, TagProtocol.GEN2); r.ParamSet("/reader/read/plan", srp); //To perform standalone operations if (antennaList != null) { r.ParamSet("/reader/tagop/antenna", antennaList[0]); } try { Console.WriteLine("Unfiltered Read:"); // Read the tags in the field tagReads = r.Read(500); foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); if (0 == tagReads.Length) { Console.WriteLine("No tags found."); } else { // A TagData object may be used as a filter, for example to // perform a tag data operation on a particular tag. Console.WriteLine("Filtered Tagop:"); // Read kill password of tag found in previous operation filter = tagReads[0].Tag; Console.WriteLine("Read kill password of tag {0}", filter); Gen2.ReadData tagop = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2); try { ushort[] data = (ushort[])r.ExecuteTagOp(tagop, filter); foreach (ushort word in data) { Console.Write("{0:X4}", word); } Console.WriteLine(); } catch (ReaderException ex) { Console.WriteLine("Can't read tag: {0}", ex.Message); } Console.WriteLine(); // Filter objects that apply to multiple tags are most useful in // narrowing the set of tags that will be read. This is // performed by setting a read plan that contains a filter. // A TagData with a short EPC will filter for tags whose EPC // starts with the same sequence. filter = new TagData(tagReads[0].Tag.EpcString.Substring(0, 4)); Console.WriteLine("EPCs that begin with {0}:", filter); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // A filter can also be an full Gen2 Select operation. For // example, this filter matches all Gen2 tags where bits 8-19 of // the TID are 0x003 (that is, tags manufactured by Alien // Technology). Console.WriteLine("Tags with Alien Technology TID"); filter = new Gen2.Select(false, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); if (r is SerialReader) { // A filter can also be Gen2 Truncate Select operation. // Truncate indicates whether a Tag’s backscattered reply shall be truncated to those EPC bits that follow Mask. // For example, truncated select starting with PC word start address and length of 16 bits Console.WriteLine("GEN2 Select Truncate Operation"); filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCTRUNCATE, 16, 40, new byte[] { 0x30, 0x00, 0xDE, 0xAD, 0xCA }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // A filter can also perform Gen2 Tag Filtering. // Major advantage of this feature is to limit the EPC response to user specified length field and all others will be rejected by firmware. // invert, bitPointer, mask : Parameters will be ignored when TMR_GEN2_EPC_LENGTH_FILTER is used // maskBitLength : Specified EPC Length used for filtering // For example, Tag filtering will be applied on EPC with 128 bits length, rest of the tags will be ignored Console.WriteLine("GEN2 Tag Filter Based on EPC Length"); filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCLENGTHFILTER, 16, 128, new byte[] { 0x30, 0x00 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); } // Gen2 Select may also be inverted, to give all non-matching tags Console.WriteLine("Tags without Alien Technology TID"); filter = new Gen2.Select(true, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // Filters can also be used to match tags that have already been // read. This form can only match on the EPC, as that's the only // data from the tag's memory that is contained in a TagData // object. // Note that this filter has invert=true. This filter will match // tags whose bits do not match the selection mask. // Also note the offset - the EPC code starts at bit 32 of the // EPC memory bank, after the StoredCRC and StoredPC. filter = new Gen2.Select(true, Gen2.Bank.EPC, 32, 2, new byte[] { (byte)0xC0 }); Console.WriteLine("EPCs with first 2 bits equal to zero (post-filtered):"); foreach (TagReadData tr in tagReads) // unfiltered tag reads from the first example { if (filter.Matches(tr.Tag)) { Console.WriteLine(tr.ToString()); } } Console.WriteLine(); } } finally { // Restore original settings Console.WriteLine("Restoring Session " + oldSession); r.ParamSet("/reader/gen2/session", oldSession); } // Shut down reader r.Destroy(); } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private void run(String reader_uri) { try { String PARAM_STR_REGION = "/reader/region/id"; String PARAM_STR_SESSION = "/reader/gen2/session"; String PARAM_STR_READPLAN = "/reader/read/plan"; Console.WriteLine(String.Format("Connecting to {0}", reader_uri)); //Create the reader reader = Reader.Create(reader_uri); try { //Uncomment this line to add default transport listener. //reader.Transport += reader.SimpleTransportListener; //Connect to the reader reader.Connect(); //Set the region to NA if (Reader.Region.UNSPEC == (Reader.Region)reader.ParamGet(PARAM_STR_REGION)) { Reader.Region[] supportedRegions = (Reader.Region[])reader.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { reader.ParamSet(PARAM_STR_REGION, supportedRegions[0]); } } //Set the session to session 0 reader.ParamSet(PARAM_STR_SESSION, Gen2.Session.S0); //Get the region Reader.Region region = (Reader.Region)reader.ParamGet(PARAM_STR_REGION); Console.WriteLine("The current region is " + region); //Get the session Gen2.Session session = (Gen2.Session)reader.ParamGet(PARAM_STR_SESSION); Console.WriteLine("The current session is " + session); //Get the read plan ReadPlan rp = (ReadPlan)reader.ParamGet(PARAM_STR_READPLAN); Console.WriteLine("The current Read Plan is: " + rp); //Create the Get Calibration Data tag operation Gen2.IDS.SL900A.GetCalibrationData getCal_tagop = new Gen2.IDS.SL900A.GetCalibrationData(); //Use the Get Calibration Data (and SFE Parameters) tag op Gen2.IDS.SL900A.CalSfe calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Save the current Cal to restore it to the tag after the test Gen2.IDS.SL900A.CalibrationData restore_cal = (Gen2.IDS.SL900A.CalibrationData)calSfe.Cal; //Display the Calibration (and SFE Parameters) Data Console.WriteLine("Detected Calibration: " + calSfe); //Set the Calibration Data to 0x0123456789ABCD (56 bits) byte[] test_cal_byte_array = new byte[7] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD }; Gen2.IDS.SL900A.CalibrationData test_cal = new Gen2.IDS.SL900A.CalibrationData(test_cal_byte_array, 0); //Execute the Set Calibration Data command with test_cal to change its value reader.ExecuteTagOp(new Gen2.IDS.SL900A.SetCalibrationData(test_cal), null); //Use Get Calibration Data to retrieve the new Calibration (and SFE Parameters) from the tag Gen2.IDS.SL900A.CalSfe verification_calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Get the Cal data from the CalSfe data Gen2.IDS.SL900A.CalibrationData verification_cal = (Gen2.IDS.SL900A.CalibrationData)verification_calSfe.Cal; //Print the verificationCal Console.WriteLine("Verification Cal: " + verification_cal.ToString()); //Ensure that the Calibration Data we set matches the current Calibration Data Console.WriteLine("Set Calibration Data Succeeded? " + test_cal.ToString().Equals(verification_cal.ToString())); //Restore the starting Calibration Data reader.ExecuteTagOp(new Gen2.IDS.SL900A.SetCalibrationData(restore_cal), null); //Get CalSfe of the restored tag Gen2.IDS.SL900A.CalSfe restored_calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Make sure that CalSfe is now the same as it was before the test Console.WriteLine("Restore Calibration Data Succeeded? " + calSfe.ToString().Equals(restored_calSfe.ToString())); } finally { //Disconnect from the reader reader.Destroy(); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
/// <summary> /// Populate optimal settings based on reader /// </summary> private void InitializeOptimalSettings() { _optimalReaderSettings = new Dictionary <string, string>(); try { Gen2.LinkFrequency blf = (Gen2.LinkFrequency)_reader.ParamGet("/reader/gen2/BLF"); switch (blf) { case Gen2.LinkFrequency.LINK250KHZ: _optimalReaderSettings["/reader/gen2/BLF"] = "LINK250KHZ"; break; case Gen2.LinkFrequency.LINK640KHZ: _optimalReaderSettings["/reader/gen2/BLF"] = "LINK640KHZ";; break; default: _optimalReaderSettings.Add("/reader/gen2/BLF", ""); break; } } catch (ArgumentException ex) { if (ex.Message.Contains("Unknown Link Frequency")) { MessageBox.Show("Unknown Link Frequency found, Reverting to defaults.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning); _optimalReaderSettings["/reader/gen2/BLF"] = "LINK250KHZ"; } else { _optimalReaderSettings.Add("/reader/gen2/BLF", ""); } } try { Gen2.Tari tariVal = (Gen2.Tari)_reader.ParamGet("/reader/gen2/Tari"); switch (tariVal) { case Gen2.Tari.TARI_6_25US: _optimalReaderSettings["/reader/gen2/tari"] = "TARI_6_25US"; break; case Gen2.Tari.TARI_12_5US: _optimalReaderSettings["/reader/gen2/tari"] = "TARI_12_5US"; break; case Gen2.Tari.TARI_25US: _optimalReaderSettings["/reader/gen2/tari"] = "TARI_25US"; break; default: _optimalReaderSettings.Add("/reader/gen2/tari", ""); break; } } catch (ArgumentException) { _optimalReaderSettings.Add("/reader/gen2/tari", ""); } catch (ReaderCodeException) { } try { Gen2.TagEncoding tagencoding = (Gen2.TagEncoding)_reader.ParamGet("/reader/gen2/tagEncoding"); switch (tagencoding) { case Gen2.TagEncoding.FM0: _optimalReaderSettings["/reader/gen2/tagEncoding"] = "FM0"; break; case Gen2.TagEncoding.M2: _optimalReaderSettings["/reader/gen2/tagEncoding"] = "M2"; break; case Gen2.TagEncoding.M4: _optimalReaderSettings["/reader/gen2/tagEncoding"] = "M4"; break; case Gen2.TagEncoding.M8: _optimalReaderSettings["/reader/gen2/tagEncoding"] = "M8"; break; default: _optimalReaderSettings.Add("/reader/gen2/tagEncoding", ""); break; } } catch (ArgumentException) { _optimalReaderSettings.Add("/reader/gen2/tagEncoding", ""); } try { Gen2.Session session = (Gen2.Session)_reader.ParamGet("/reader/gen2/session"); switch (session) { case Gen2.Session.S0: _optimalReaderSettings["/reader/gen2/session"] = "S0"; break; case Gen2.Session.S1: _optimalReaderSettings["/reader/gen2/session"] = "S1"; break; case Gen2.Session.S2: _optimalReaderSettings["/reader/gen2/session"] = "S2"; break; case Gen2.Session.S3: _optimalReaderSettings["/reader/gen2/session"] = "S3"; break; default: _optimalReaderSettings.Add("/reader/gen2/session", ""); break; } } catch (ArgumentException) { _optimalReaderSettings.Add("/reader/gen2/session", ""); } try { Gen2.Target target = (Gen2.Target)_reader.ParamGet("/reader/gen2/Target"); switch (target) { case Gen2.Target.A: _optimalReaderSettings["/reader/gen2/target"] = "A"; break; case Gen2.Target.B: _optimalReaderSettings["/reader/gen2/target"] = "B"; break; case Gen2.Target.AB: _optimalReaderSettings["/reader/gen2/target"] = "AB"; break; case Gen2.Target.BA: _optimalReaderSettings["/reader/gen2/target"] = "BA"; break; default: _optimalReaderSettings.Add("Target", ""); break; } } catch (FeatureNotSupportedException) { _optimalReaderSettings.Add("Target", ""); } try { Gen2.Q qval = (Gen2.Q)_reader.ParamGet("/reader/gen2/q"); if (qval.GetType() == typeof(Gen2.DynamicQ)) { _optimalReaderSettings["/reader/gen2/q"] = "DynamicQ"; } else if (qval.GetType() == typeof(Gen2.StaticQ)) { Gen2.StaticQ stqval = (Gen2.StaticQ)qval; _optimalReaderSettings["/reader/gen2/q"] = "StaticQ"; int countQ = Convert.ToInt32(((Gen2.StaticQ)qval).InitialQ); _optimalReaderSettings["/application/performanceTuning/staticQValue"] = countQ.ToString(); } else { _optimalReaderSettings.Add("/reader/gen2/q", ""); } } catch (FeatureNotSupportedException) { _optimalReaderSettings.Add("/reader/gen2/q", ""); } }
static void Main(string[] args) { // Program setup if (1 != args.Length) { Console.WriteLine(String.Join("\r\n", new string[] { "Please provide reader URL, such as:", "tmr:///com4", "tmr://my-reader.example.com", })); Environment.Exit(1); } try { // Create Reader object, connecting to physical device. // Wrap reader in a "using" block to get automatic // reader shutdown (using IDisposable interface). using (Reader r = Reader.Create(args[0])) { //Uncomment this line to add default transport listener. //r.Transport += r.SimpleTransportListener; r.Connect(); TagReadData[] tagReads; if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { r.ParamSet("/reader/region/id", supportedRegions[0]); } } // In the current system, sequences of Gen2 operations require Session 0, // since each operation resingulates the tag. In other sessions, // the tag will still be "asleep" from the preceding singulation. Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session"); Gen2.Session newSession = Gen2.Session.S0; Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")"); r.ParamSet("/reader/gen2/session", newSession); try { // Find a tag to work on tagReads = r.Read(1000); if (0 == tagReads.Length) { Console.WriteLine("No tags found to work on"); return; } TagData t = tagReads[0].Tag; // Lock the tag r.ExecuteTagOp(new Gen2.Lock(0, new Gen2.LockAction(Gen2.LockAction.EPC_LOCK)), t); Console.WriteLine("Locked EPC of tag " + t); // Unlock the tag r.ExecuteTagOp(new Gen2.Lock(0, new Gen2.LockAction(Gen2.LockAction.EPC_UNLOCK)), t); Console.WriteLine("Unlocked EPC of tag " + t); } finally { // Restore original settings Console.WriteLine("Restoring Session " + oldSession); r.ParamSet("/reader/gen2/session", oldSession); } } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private void run(String reader_uri) { try { String PARAM_STR_REGION = "/reader/region/id"; String PARAM_STR_SESSION = "/reader/gen2/session"; String PARAM_STR_READPLAN = "/reader/read/plan"; Console.WriteLine(String.Format("Connecting to {0}", reader_uri)); //Create the reader reader = Reader.Create(reader_uri); try { //Uncomment this line to add default transport listener. //reader.Transport += reader.SimpleTransportListener; //Connect to the reader reader.Connect(); //Set the region to NA if (Reader.Region.UNSPEC == (Reader.Region)reader.ParamGet(PARAM_STR_REGION)) { Reader.Region[] supportedRegions = (Reader.Region[])reader.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { reader.ParamSet(PARAM_STR_REGION, supportedRegions[0]); } } string model = reader.ParamGet("/reader/version/model").ToString(); if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } //Use first antenna for operation if (antennaList != null) { reader.ParamSet("/reader/tagop/antenna", antennaList[0]); } //Set the session to session 0 reader.ParamSet(PARAM_STR_SESSION, Gen2.Session.S0); //Get the region Reader.Region region = (Reader.Region)reader.ParamGet(PARAM_STR_REGION); Console.WriteLine("The current region is " + region); //Get the session Gen2.Session session = (Gen2.Session)reader.ParamGet(PARAM_STR_SESSION); Console.WriteLine("The current session is " + session); //Get the read plan ReadPlan rp = (ReadPlan)reader.ParamGet(PARAM_STR_READPLAN); Console.WriteLine("The current Read Plan is: " + rp); //Create the Get Calibration Data tag operation Gen2.IDS.SL900A.GetCalibrationData tagOp = new Gen2.IDS.SL900A.GetCalibrationData(); //Use the Get Calibration Data (and SFE Parameters) tag op Gen2.IDS.SL900A.CalSfe calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(tagOp, null); //Display the Calibration (and SFE Parameters) Data Console.WriteLine(calSfe); //Display the specific Calibration data gnd_switch Console.WriteLine("gnd_switch: " + calSfe.Cal.GndSwitch); //Display the specific SFE Parameter Verify Sensor ID Console.WriteLine("Verify Sensor ID: " + calSfe.Sfe.VerifySensorID); } finally { //Disconnect from the reader reader.Destroy(); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
static void Main(string[] args) { // Program setup if (args.Length != 1) { Console.WriteLine("Please provide reader URL, such as:\n" + "tmr:///com4\n" + "tmr://my-reader.example.com\n"); Environment.Exit(1); } // Create Reader object, connecting to physical device try { Reader r; TagReadData[] tagReads, filteredTagReads; TagFilter filter; r = Reader.Create(args[0]); //Uncomment this line to add default transport listener. //r.Transport += r.SimpleTransportListener; r.Connect(); if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { r.ParamSet("/reader/region/id", supportedRegions[0]); } } // In the current system, sequences of Gen2 operations require Session 0, // since each operation resingulates the tag. In other sessions, // the tag will still be "asleep" from the preceding singulation. Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session"); Gen2.Session newSession = Gen2.Session.S0; Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")"); r.ParamSet("/reader/gen2/session", newSession); Console.WriteLine(); try { Console.WriteLine("Unfiltered Read:"); // Read the tags in the field tagReads = r.Read(500); foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); if (0 == tagReads.Length) { Console.WriteLine("No tags found."); } else { // A TagData object may be used as a filter, for example to // perform a tag data operation on a particular tag. Console.WriteLine("Filtered Tagop:"); // Read kill password of tag found in previous operation filter = tagReads[0].Tag; Console.WriteLine("Read kill password of tag {0}", filter); Gen2.ReadData tagop = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2); try { ushort[] data = (ushort[])r.ExecuteTagOp(tagop, filter); foreach (ushort word in data) { Console.Write("{0:X4}", word); } Console.WriteLine(); } catch (ReaderException ex) { Console.WriteLine("Can't read tag: {0}", ex.Message); } Console.WriteLine(); // Filter objects that apply to multiple tags are most useful in // narrowing the set of tags that will be read. This is // performed by setting a read plan that contains a filter. // A TagData with a short EPC will filter for tags whose EPC // starts with the same sequence. filter = new TagData(tagReads[0].Tag.EpcString.Substring(0, 4)); Console.WriteLine("EPCs that begin with {0}:", filter); r.ParamSet("/reader/read/plan", new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // A filter can also be an full Gen2 Select operation. For // example, this filter matches all Gen2 tags where bits 8-19 of // the TID are 0x003 (that is, tags manufactured by Alien // Technology). Console.WriteLine("Tags with Alien Technology TID"); filter = new Gen2.Select(false, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // Gen2 Select may also be inverted, to give all non-matching tags Console.WriteLine("Tags without Alien Technology TID"); filter = new Gen2.Select(true, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(null, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // Filters can also be used to match tags that have already been // read. This form can only match on the EPC, as that's the only // data from the tag's memory that is contained in a TagData // object. // Note that this filter has invert=true. This filter will match // tags whose bits do not match the selection mask. // Also note the offset - the EPC code starts at bit 32 of the // EPC memory bank, after the StoredCRC and StoredPC. filter = new Gen2.Select(true, Gen2.Bank.EPC, 32, 2, new byte[] { (byte)0xC0 }); Console.WriteLine("EPCs with first 2 bits equal to zero (post-filtered):"); foreach (TagReadData tr in tagReads) // unfiltered tag reads from the first example { if (filter.Matches(tr.Tag)) { Console.WriteLine(tr.ToString()); } } Console.WriteLine(); } } finally { // Restore original settings Console.WriteLine("Restoring Session " + oldSession); r.ParamSet("/reader/gen2/session", oldSession); } // Shut down reader r.Destroy(); } catch (ReaderException re) { Console.WriteLine("Error: " + re.ToString()); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private void run(String reader_uri) { try { String PARAM_STR_REGION = "/reader/region/id"; String PARAM_STR_SESSION = "/reader/gen2/session"; String PARAM_STR_READPLAN = "/reader/read/plan"; Console.WriteLine(String.Format("Connecting to {0}", reader_uri)); //Create the reader reader = Reader.Create(reader_uri); try { //Uncomment this line to add default transport listener. //reader.Transport += reader.SimpleTransportListener; //Connect to the reader reader.Connect(); //Set the region to NA if (Reader.Region.UNSPEC == (Reader.Region)reader.ParamGet(PARAM_STR_REGION)) { Reader.Region[] supportedRegions = (Reader.Region[])reader.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } else { reader.ParamSet(PARAM_STR_REGION, supportedRegions[0]); } } string model = reader.ParamGet("/reader/version/model").ToString(); if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } //Use first antenna for operation if (antennaList != null) { reader.ParamSet("/reader/tagop/antenna", antennaList[0]); } //Set the session to session 0 reader.ParamSet(PARAM_STR_SESSION, Gen2.Session.S0); //Get the region Reader.Region region = (Reader.Region)reader.ParamGet(PARAM_STR_REGION); Console.WriteLine("The current region is " + region); //Get the session Gen2.Session session = (Gen2.Session)reader.ParamGet(PARAM_STR_SESSION); Console.WriteLine("The current session is " + session); //Get the read plan ReadPlan rp = (ReadPlan)reader.ParamGet(PARAM_STR_READPLAN); Console.WriteLine("The current Read Plan is: " + rp); //Create the Get Calibration Data tag operation Gen2.IDS.SL900A.GetCalibrationData getCal_tagop = new Gen2.IDS.SL900A.GetCalibrationData(); //Use the Get Calibration Data (and SFE Parameters) tag op Gen2.IDS.SL900A.CalSfe calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Save the current Sfe to restore it to the tag after the test Gen2.IDS.SL900A.SfeParameters restore_sfe = (Gen2.IDS.SL900A.SfeParameters)calSfe.Sfe; //Display the Calibration (and SFE Parameters) Data Console.WriteLine("Detected Calibration: " + calSfe); //Set the Sfe Parameters to 0xBEEF (16 bits) byte[] test_sfe_byte_array = new byte[2] { 0xBE, 0xEF }; Gen2.IDS.SL900A.SfeParameters test_sfe = new Gen2.IDS.SL900A.SfeParameters(test_sfe_byte_array, 0); //Execute the Set Calibration Data command with test_cal to change its value reader.ExecuteTagOp(new Gen2.IDS.SL900A.SetSfeParameters(test_sfe), null); //Use Get Calibration Data to retrieve the new Calibration (and SFE Parameters) from the tag Gen2.IDS.SL900A.CalSfe verification_calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Get the Sfe data from the CalSfe data Gen2.IDS.SL900A.SfeParameters verification_sfe = (Gen2.IDS.SL900A.SfeParameters)verification_calSfe.Sfe; //Ensure that the Calibration Data we set matches the current Calibration Data Console.WriteLine("Set SFE Parameters Succeeded? " + test_sfe.ToString().Equals(verification_sfe.ToString())); //Restore the starting SFE Parameters reader.ExecuteTagOp(new Gen2.IDS.SL900A.SetSfeParameters(restore_sfe), null); //Get CalSfe of the restored tag Gen2.IDS.SL900A.CalSfe restored_calSfe = (Gen2.IDS.SL900A.CalSfe)reader.ExecuteTagOp(getCal_tagop, null); //Make sure that CalSfe is now the same as it was before the test Console.WriteLine("Restore Calibration Data Succeeded? " + calSfe.ToString().Equals(restored_calSfe.ToString())); } finally { //Disconnect from the reader reader.Destroy(); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
static void Main(string[] args) { // Program setup if (1 > args.Length) { Usage(); } int[] antennaList = null; for (int nextarg = 1; nextarg < args.Length; nextarg++) { string arg = args[nextarg]; if (arg.Equals("--ant")) { if (null != antennaList) { Console.WriteLine("Duplicate argument: --ant specified more than once"); Usage(); } antennaList = ParseAntennaList(args, nextarg); nextarg++; } else { Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg); Usage(); } } // Create Reader object, connecting to physical device try { Reader r; TagReadData[] tagReads, filteredTagReads; TagFilter filter; r = Reader.Create(args[0]); //Uncomment this line to add default transport listener. //r.Transport += r.SimpleTransportListener; r.Connect(); if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id")) { Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions"); if (supportedRegions.Length < 1) { throw new FAULT_INVALID_REGION_Exception(); } r.ParamSet("/reader/region/id", supportedRegions[0]); } if (r.isAntDetectEnabled(antennaList)) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } // In the current system, sequences of Gen2 operations require Session 0, // since each operation resingulates the tag. In other sessions, // the tag will still be "asleep" from the preceding singulation. Gen2.Session oldSession = (Gen2.Session)r.ParamGet("/reader/gen2/session"); Gen2.Session newSession = Gen2.Session.S0; Console.WriteLine("Changing to Session " + newSession + " (from Session " + oldSession + ")"); r.ParamSet("/reader/gen2/session", newSession); Console.WriteLine(); SimpleReadPlan srp = new SimpleReadPlan(antennaList, TagProtocol.GEN2); r.ParamSet("/reader/read/plan", srp); //To perform standalone operations if (antennaList != null) { r.ParamSet("/reader/tagop/antenna", antennaList[0]); } try { Console.WriteLine("Unfiltered Read:"); // Read the tags in the field tagReads = r.Read(500); foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); if (0 == tagReads.Length) { Console.WriteLine("No tags found."); } else { // A TagData object may be used as a filter, for example to // perform a tag data operation on a particular tag. Console.WriteLine("Filtered Tagop:"); // Read kill password of tag found in previous operation filter = tagReads[0].Tag; Console.WriteLine("Read kill password of tag {0}", filter); Gen2.ReadData tagop = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2); try { ushort[] data = (ushort[])r.ExecuteTagOp(tagop, filter); foreach (ushort word in data) { Console.Write("{0:X4}", word); } Console.WriteLine(); } catch (ReaderException ex) { Console.WriteLine("Can't read tag: {0}", ex.Message); } Console.WriteLine(); // Filter objects that apply to multiple tags are most useful in // narrowing the set of tags that will be read. This is // performed by setting a read plan that contains a filter. // A TagData with a short EPC will filter for tags whose EPC // starts with the same sequence. filter = new TagData(tagReads[0].Tag.EpcString.Substring(0, 4)); Console.WriteLine("EPCs that begin with {0}:", filter); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // A filter can also be an full Gen2 Select operation. For // example, this filter matches all Gen2 tags where bits 8-19 of // the TID are 0x003 (that is, tags manufactured by Alien // Technology). // In case of Network readers, ensure that bitLength is a multiple of 8. Console.WriteLine("Tags with Alien Technology TID"); filter = new Gen2.Select(false, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); if (r is SerialReader) { // A filter can also be Gen2 Truncate Select operation. // Truncate indicates whether a Tag’s backscattered reply shall be truncated to those EPC bits that follow Mask. // For example, truncated select starting with PC word start address and length of 16 bits // In case of Network readers, ensure that bitLength is a multiple of 8. Console.WriteLine("GEN2 Select Truncate Operation"); filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCTRUNCATE, 16, 40, new byte[] { 0x30, 0x00, 0xDE, 0xAD, 0xCA }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // A filter can also perform Gen2 Tag Filtering. // Major advantage of this feature is to limit the EPC response to user specified length field and all others will be rejected by firmware. // invert, bitPointer, mask : Parameters will be ignored when TMR_GEN2_EPC_LENGTH_FILTER is used // maskBitLength : Specified EPC Length used for filtering // For example, Tag filtering will be applied on EPC with 128 bits length, rest of the tags will be ignored // In case of Network readers, ensure that bitLength is a multiple of 8. Console.WriteLine("GEN2 Tag Filter Based on EPC Length"); filter = new Gen2.Select(false, Gen2.Bank.GEN2EPCLENGTHFILTER, 16, 128, new byte[] { 0x30, 0x00 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); } // Gen2 Select may also be inverted, to give all non-matching tags // In case of Network readers, ensure that bitLength is a multiple of 8. Console.WriteLine("Tags without Alien Technology TID"); filter = new Gen2.Select(true, Gen2.Bank.TID, 8, 12, new byte[] { 0, 0x30 }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, filter, 1000)); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); // Filters can also be used to match tags that have already been // read. This form can only match on the EPC, as that's the only // data from the tag's memory that is contained in a TagData // object. // Note that this filter has invert=true. This filter will match // tags whose bits do not match the selection mask. // Also note the offset - the EPC code starts at bit 32 of the // EPC memory bank, after the StoredCRC and StoredPC. // In case of Network readers, ensure that bitLength is a multiple of 8. filter = new Gen2.Select(true, Gen2.Bank.EPC, 32, 2, new byte[] { (byte)0xC0 }); Console.WriteLine("EPCs with first 2 bits equal to zero (post-filtered):"); foreach (TagReadData tr in tagReads) // unfiltered tag reads from the first example { if (filter.Matches(tr.Tag)) { Console.WriteLine(tr.ToString()); } } Console.WriteLine(); /** * Multi filter creation and initialization. This filter will match those tags whose bits matches the * selection mask of both tidFilter(tags manufactured by Alien Technology) and epcFilter(epc of first * tag read from tagReads[0]). Target and action are the two new parameters of Gen2.Select class whose * default values could be "Gen2.Select.Target.Select" and "Gen2.Select.Action.ON_N_OFF" respectively * if not provided by the user. * * Gen2 Select Action indicates which Select action to take * (See Gen2 spec /Select commands / Tag response to Action parameter) * |-----------------------------------------------------------------------------| * | Action | Tag Matching | Tag Not-Matching | * |----------|--------------------------------|---------------------------------| * | 0x00 | Assert SL or Inventoried->A | Deassert SL or Inventoried->B | * | 0x01 | Assert SL or Inventoried->A | Do nothing | * | 0x02 | Do nothing | Deassert SL or Inventoried->B | * | 0x03 | Negate SL or (A->B,B->A) | Do nothing | * | 0x04 | Deassert SL or Inventoried->B | Assert SL or Inventoried->A | * | 0x05 | Deassert SL or Inventoried->B | Do nothing | * | 0x06 | Do nothing | Assert SL or Inventoried->A | * | 0x07 | Do nothing | Negate SL or (A->B,B->A) | * * * To improve readability and ease typing, these names abbreviate the official terminology of the Gen2 spec. * <A>_N_<B>: The "_N_" stands for "Non-Matching". * The <A> clause before the _N_ describes what happens to Matching tags. * The <B> clause after the _N_ describes what happens to Non-Matching tags. * (Alternately, you can pronounce "_N_" as "and", or "&"; i.e., * the pair of Matching / Non-Matching actions is known as "<A> and <B>".) * * ON: assert SL or inventoried -> A * OFF: deassert SL or inventoried -> B * NEG: negate SL or (A->B, B->A) * NOP: do nothing * * The enum is simply a transliteration of the Gen2 spec's table: "Tag response to Action parameter" */ // create and initialize tidFilter // In case of Network readers, ensure that bitLength is a multiple of 8. Gen2.Select tidFilter = new Gen2.Select(false, Gen2.Bank.TID, 32, 16, new byte[] { (byte)0x01, (byte)0x2E }); tidFilter.target = Gen2.Select.Target.Select; tidFilter.action = Gen2.Select.Action.ON_N_OFF; // create and initialize epcFilter // In case of Network readers, ensure that bitLength is a multiple of 8. Gen2.Select epcFilter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { (byte)0x11, (byte)0x22 }); epcFilter.target = Gen2.Select.Target.Select; epcFilter.action = Gen2.Select.Action.ON_N_OFF; // Initialize multifilter with tagFilter array containing list of filters // In case of Network readers, ensure that bitLength is a multiple of 8. MultiFilter multiFilter = new MultiFilter(new TagFilter[] { tidFilter, epcFilter }); r.ParamSet("/reader/read/plan", new SimpleReadPlan(antennaList, TagProtocol.GEN2, multiFilter, 1000)); Console.WriteLine("Reading tags which matches multi filter criteria \n", filter.ToString()); filteredTagReads = r.Read(500); foreach (TagReadData tr in filteredTagReads) { Console.WriteLine(tr.ToString()); } Console.WriteLine(); } } finally { // Restore original settings Console.WriteLine("Restoring Session " + oldSession); r.ParamSet("/reader/gen2/session", oldSession); } // Shut down reader r.Destroy(); } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }