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]); } 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(); } // Set the q value r.ParamSet("/reader/gen2/q", new Gen2.StaticQ(1)); // Set the number of tags to read StopOnTagCount sotc = new StopOnTagCount(); sotc.N = 1; // Prepare multireadplan. Comment the below code if only single readplan is needed; //StopTriggerReadPlan str1 = new StopTriggerReadPlan(sotc, new int[] { 1 }, //TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.TID, 0, 0), 1000); //StopTriggerReadPlan str2 = new StopTriggerReadPlan(sotc, new int[] { 2 }, //TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.EPC, 0, 0), 1000); //List<ReadPlan> plan = new List<ReadPlan>(); //plan.Add(str1); //plan.Add(str2); //MultiReadPlan readplan = new MultiReadPlan(plan); // Prepare single read plan. Comment the below code if multireadplan is needed StopTriggerReadPlan readplan = new StopTriggerReadPlan(sotc, antennaList, TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 0), 1000); // Set readplan r.ParamSet("/reader/read/plan", readplan); TagReadData [] tagReads; // Read tags tagReads = r.Read(1000); // Print tag reads foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString() + ", Protocol: " + tr.Tag.Protocol.ToString()); Console.WriteLine("Data: " + ByteFormat.ToHex(tr.Data)); } } } 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(); } } 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]); } string model = (string)r.ParamGet("/reader/version/model").ToString(); if (!model.Equals("M3e")) { if (r.isAntDetectEnabled(antennaList)) { Console.WriteLine("Module doesn't has antenna detection support please provide antenna list"); Usage(); } // Set the q value r.ParamSet("/reader/gen2/q", new Gen2.StaticQ(1)); } else { if (antennaList != null) { Console.WriteLine("Module doesn't support antenna input"); Usage(); } } // Set the number of tags to read StopOnTagCount sotc = new StopOnTagCount(); sotc.N = 5; StopTriggerReadPlan readplan; #if ENABLE_SIMPLE_READPLAN if (model.Equals("M3e")) { readplan = new StopTriggerReadPlan(sotc, antennaList, TagProtocol.ISO14443A, null, null, 1000); // Set readplan r.ParamSet("/reader/read/plan", readplan); } else { // Prepare single read plan. readplan = new StopTriggerReadPlan(sotc, antennaList, TagProtocol.GEN2, null, null, 1000); // Set readplan r.ParamSet("/reader/read/plan", readplan); } #else TagProtocol[] protocolList = (TagProtocol[])r.ParamGet("/reader/version/supportedProtocols"); if (model.Equals("M3e")) { #if ENABLE_DYNAMIC_SWITCHING //Set the multiple protocols using "/reader/protocolList" param for dynamic protocol switching r.ParamSet("/reader/protocolList", protocolList); // If param is set, API ignores the protocol mentioned in readplan. StopTriggerReadPlan plan = new StopTriggerReadPlan(sotc, antennaList, TagProtocol.ISO14443A, null, null, 1000); // Set readplan r.ParamSet("/reader/read/plan", plan); #else List <ReadPlan> planList = new List <ReadPlan>(); foreach (TagProtocol protocol in protocolList) { planList.Add(new StopTriggerReadPlan(sotc, antennaList, protocol, null, null, 1000)); } MultiReadPlan plan = new MultiReadPlan(planList); // Set read plan r.ParamSet("/reader/read/plan", plan); #endif } else { List <ReadPlan> planList = new List <ReadPlan>(); foreach (TagProtocol protocol in protocolList) { planList.Add(new StopTriggerReadPlan(sotc, antennaList, protocol, null, null, 1000)); } MultiReadPlan plan = new MultiReadPlan(planList); // Set readplan r.ParamSet("/reader/read/plan", plan); } #endif #if ENABLE_SYNC_READ TagReadData[] tagReads; // Read tags tagReads = r.Read(1000); // Print tag reads foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString() + ", Protocol: " + tr.Tag.Protocol.ToString()); } #endif #if ENABLE_ASYNC_READ // Create and add tag listener r.TagRead += delegate(Object sender, TagReadDataEventArgs e) { Console.WriteLine("Background read: " + e.TagReadData); }; // Create and add read exception listener r.ReadException += new EventHandler <ReaderExceptionEventArgs>(r_ReadException); // Search for tags in the background r.StartReading(); while (!r.isReadStopped()) { } #endif } } 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]); } } // Set the q value r.ParamSet("/reader/gen2/q", new Gen2.StaticQ(1)); // Set the number of tags to read StopOnTagCount sotc = new StopOnTagCount(); sotc.N = 1; // Prepare multireadplan. Comment the below code if only single readplan is needed; //StopTriggerReadPlan str1 = new StopTriggerReadPlan(sotc, new int[] { 1 }, //TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.TID, 0, 0), 1000); //StopTriggerReadPlan str2 = new StopTriggerReadPlan(sotc, new int[] { 2 }, //TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.EPC, 0, 0), 1000); //List<ReadPlan> plan = new List<ReadPlan>(); //plan.Add(str1); //plan.Add(str2); //MultiReadPlan readplan = new MultiReadPlan(plan); // Prepare single read plan. Comment the below code if multireadplan is needed StopTriggerReadPlan readplan = new StopTriggerReadPlan(sotc, new int[] { 1 }, TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 0), 1000); // Set readplan r.ParamSet("/reader/read/plan", readplan); TagReadData [] tagReads; // Read tags tagReads = r.Read(1000); // Print tag reads foreach (TagReadData tr in tagReads) { Console.WriteLine(tr.ToString() + ", Protocol: " + tr.Tag.Protocol.ToString()); Console.WriteLine("Data: " + ByteFormat.ToHex(tr.Data)); } } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }