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 ((r is SerialReader) || (r is LlrpReader)) { 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]); } } Gen2.Password pass = new Gen2.Password(0x0); r.ParamSet("/reader/gen2/accessPassword", pass); // BlockWrite and read using ExecuteTagOp Gen2.BlockWrite blockwrite = new Gen2.BlockWrite(Gen2.Bank.USER, 0, new ushort[] { 0xFFF1, 0x1122 }); r.ExecuteTagOp(blockwrite, null); Gen2.ReadData read = new Gen2.ReadData(Gen2.Bank.USER, 0, 2); ushort[] readData = (ushort[])r.ExecuteTagOp(read, null); foreach (ushort word in readData) { Console.Write(String.Format(" {0:X4}", word)); } Console.WriteLine(); // BlockWrite and read using embedded read command SimpleReadPlan readplan; TagReadData[] tagreads; blockwrite = new Gen2.BlockWrite(Gen2.Bank.USER, 0, new ushort[] { 0x1234, 0x5678 }); readplan = new SimpleReadPlan(null, TagProtocol.GEN2, //null, new TagData("1234567890ABCDEF"), blockwrite, 0); r.ParamSet("/reader/read/plan", readplan); r.Read(500); readplan = new SimpleReadPlan(null, TagProtocol.GEN2, null, new Gen2.ReadData(Gen2.Bank.USER, 0, 2), 0); r.ParamSet("/reader/read/plan", readplan); tagreads = r.Read(500); foreach (TagReadData trd in tagreads) { foreach (byte b in trd.Data) { Console.Write(String.Format(" {0:X2}", b)); } Console.WriteLine(" " + trd.ToString()); } } else { Console.WriteLine("Error: This codelet works only for Serial Readers and Llrp Readers"); } } } 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]); } } // Read Plan byte length; string model = (string)r.ParamGet("/reader/version/model"); if ("M6e".Equals(model) || "M6e PRC".Equals(model) || "M6e Micro".Equals(model) || "Mercury6".Equals(model) || "Astra-EX".Equals(model)) { // Specifying the readLength = 0 will return full TID for any tag read in case of M6e varients, M6 and Astra-EX reader. length = 0; } else { length = 2; } // Embedded Secure Read Tag Operation - Standalone operation not supported Gen2.Password password = new Gen2.Password(0); Gen2.SecureReadData secureReadDataTagOp = new Gen2.SecureReadData(Gen2.Bank.TID, 0, (byte)0, Gen2.SecureTagType.HIGGS3, password); ; SimpleReadPlan plan = new SimpleReadPlan(null, TagProtocol.GEN2, null, secureReadDataTagOp, 1000); r.ParamSet("/reader/read/plan", plan); // Create and add tag listener r.TagRead += delegate(Object sender, TagReadDataEventArgs e) { Console.WriteLine("Background read: " + e.TagReadData); Console.WriteLine("Requested data: "+ByteFormat.ToHex(e.TagReadData.Data)); }; // Create and add read exception listener r.ReadException += r_ReadException; // Create and add read authenticate listener r.ReadAuthentication += r_ReadAuthenticationListener; // Search for tags in the background r.StartReading(); Console.WriteLine("\r\n<Do other work here>\r\n"); Thread.Sleep(500); Console.WriteLine("\r\n<Do other work here>\r\n"); Thread.Sleep(500); r.StopReading(); } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); Console.Out.Flush(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
/// <summary> /// execute a TagOp /// </summary> /// <param name="tagOP">Tag Operation</param> /// <param name="target">Tag filter</param> ///<returns>the return value of the tagOp method if available</returns> public override Object ExecuteTagOp(TagOp tagOP, TagFilter target) { TagProtocol oldProtocol = (TagProtocol)ParamGet("/reader/tagop/protocol"); try { if (tagOP is Gen2.ReadData) { ParamSet("/reader/tagop/protocol", TagProtocol.GEN2); return ReadTagMemWords(target, (int)(((Gen2.ReadData)tagOP).Bank), (int)((Gen2.ReadData)tagOP).WordAddress, ((Gen2.ReadData)tagOP).Len); } if (tagOP is Gen2.WriteData) { ParamSet("/reader/tagop/protocol", TagProtocol.GEN2); WriteTagMemWords(target, (int)(((Gen2.WriteData)tagOP).Bank), (int)((Gen2.WriteData)tagOP).WordAddress, (ushort[])((Gen2.WriteData)tagOP).Data); return null; } if (tagOP is Gen2.Lock) { ParamSet("/reader/tagop/protocol", TagProtocol.GEN2); Gen2.Password oldPassword = (Gen2.Password)(ParamGet("/reader/gen2/accessPassword")); if (((Gen2.Lock)tagOP).AccessPassword != 0) { ParamSet("/reader/gen2/accessPassword", new Gen2.Password(((Gen2.Lock)tagOP).AccessPassword)); } try { LockTag(target, ((Gen2.Lock)tagOP).LockAction); } finally { ParamSet("/reader/gen2/accessPassword", oldPassword); } return null; } if (tagOP is Gen2.Kill) { ParamSet("/reader/tagop/protocol", TagProtocol.GEN2); Gen2.Password auth = new Gen2.Password(((Gen2.Kill)tagOP).KillPassword); KillTag(target, auth); return null; } else if (tagOP is Gen2.WriteTag) { ParamSet("/reader/tagop/protocol", TagProtocol.GEN2); WriteTag(target, ((Gen2.WriteTag)tagOP).Epc); return null; } else if (tagOP is Gen2.BlockWrite) { throw new FeatureNotSupportedException("Gen2.BlockWrite not supported"); } else if (tagOP is Gen2.BlockPermaLock) { throw new FeatureNotSupportedException("Gen2.BlockPermaLock not supported"); } else if (tagOP is Iso180006b.ReadData) { ParamSet("/reader/tagop/protocol", TagProtocol.ISO180006B); return ReadTagMemBytes(target, 0, (int)(((Iso180006b.ReadData)tagOP).byteAddress), ((Iso180006b.ReadData)tagOP).length); } else if (tagOP is Iso180006b.WriteData) { ParamSet("/reader/tagop/protocol", TagProtocol.ISO180006B); WriteTagMemBytes(target, 0, (int)(((Iso180006b.WriteData)tagOP).Address), ((Iso180006b.WriteData)tagOP).Data); return null; } else if (tagOP is Iso180006b.LockTag) { ParamSet("/reader/tagop/protocol", TagProtocol.ISO180006B); Iso180006bLockTag(target, ((Iso180006b.LockTag)tagOP).Address); return null; } else { throw new Exception("Unsupported tagop."); } } finally { ParamSet("/reader/tagop/protocol", oldProtocol); } }
private static void LockFunc(Reader rdr, ArgParser pargs) { string[] args = pargs.commandArgs; int i = 0; TagLockAction action = (TagLockAction)ParseValue(args[i++]); uint pwval = Convert.ToUInt32(ParseValue(args[i++])); Gen2.Password password = new Gen2.Password(pwval); rdr.ParamSet("/reader/gen2/accessPassword",password); TagFilter target = (i >= args.Length) ? null : (TagFilter)ParseValue(args[i++]); rdr.LockTag(target, action); }
private static void KillFunc(Reader rdr, ArgParser pargs) { // kill password [target] string[] args = pargs.commandArgs; int i = 0; uint pwval = Convert.ToUInt32(ParseValue(args[i++])); Gen2.Password password = new Gen2.Password(pwval); TagFilter filt = (i < args.Length) ? (TagFilter)ParseValue(args[i++]) : null; rdr.KillTag(filt, password); }
/// <summary> /// Parse string representing a parameter value. /// </summary> /// <param name="name">Name of parameter</param> /// <param name="valstr">String to be parsed into a parameter value</param> private static Object ParseValue(string name, string valstr) { Object value = ParseValue(valstr); switch (name.ToLower()) { case "/reader/antenna/portswitchgpos": case "/reader/region/hoptable": value = ((ArrayList)value).ToArray(typeof(int)); break; case "/reader/gpio/inputlist": value = ((ArrayList)value).ToArray(typeof(int)); break; case "/reader/gpio/outputlist": value = ((ArrayList)value).ToArray(typeof(int)); break; case "/reader/antenna/settlingtimelist": case "/reader/antenna/txrxmap": case "/reader/radio/portreadpowerlist": case "/reader/radio/portwritepowerlist": value = ArrayListToInt2Array((ArrayList)value); break; case "/reader/region/lbt/enable": case "/reader/antenna/checkport": case "/reader/tagreaddata/recordhighestrssi": case "/reader/tagreaddata/uniquebyantenna": case "/reader/tagreaddata/uniquebydata": case "/reader/tagreaddata/reportrssiindbm": value = ParseBool(valstr); break; case "/reader/read/plan": // Special Case: If value is list of integers, automatically // interpret as SimpleReadPlan with list of antennas. if (value is ArrayList) { int[] antList = (int[])((ArrayList)value).ToArray(typeof(int)); SimpleReadPlan srp = new SimpleReadPlan(); srp.Antennas = antList; value = srp; } break; case "/reader/region/id": value = Enum.Parse(typeof(Reader.Region), (string)value, true); break; case "/reader/powermode": value = Enum.Parse(typeof(Reader.PowerMode), (string)value, true); break; case "/reader/tagop/protocol": if (value is string) { value = Enum.Parse(typeof(TagProtocol), (string)value, true); } break; case "/reader/gen2/accesspassword": value = new Gen2.Password((UInt32)(int)value); break; case "/reader/gen2/session": if (value is int) { switch ((int)value) { case 0: return Gen2.Session.S0; case 1: return Gen2.Session.S1; case 2: return Gen2.Session.S2; case 3: return Gen2.Session.S3; } } break; case "/reader/gen2/tagencoding": value = Enum.Parse(typeof(Gen2.TagEncoding), (string)value, true); break; case "/reader/iso180006b/blf": if (value is string) { value = Enum.Parse(typeof(Iso180006b.LinkFrequency), (string)value, true); } break; default: break; } return value; }
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 ((r is SerialReader)||(r is LlrpReader)) { 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]); } } Gen2.Password pass = new Gen2.Password(0x0); r.ParamSet("/reader/gen2/accessPassword", pass); /************************************************/ Gen2.BlockPermaLock blockpermalock1 = new Gen2.BlockPermaLock(0x01, Gen2.Bank.USER, 0x00, 0x01, new ushort[] { 0x0010 }); // r.ExecuteTagOp(blockpermalock1, null); Gen2.BlockPermaLock blockpermalock2 = new Gen2.BlockPermaLock(0x00, Gen2.Bank.USER, 0x00, 0x01, null); byte[] lockStatus = (byte[])r.ExecuteTagOp(blockpermalock2, null); foreach (byte i in lockStatus) { Console.WriteLine("Lock Status : {0:x2}", i); } } else { Console.WriteLine("Error: This codelet works only for Serial Readers and Llrp Readers"); } } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }