/// <summary> /// This sends the Access Password to the tag to put it in Secure Mode. /// </summary> /// <param name="reader"></param> /// <param name="password"></param> /// <returns></returns> public bool SendTagPassword(STPv3Reader reader) { byte[] data = new byte[4]; int numRetries = retries; if (numRetries == 0) { numRetries = 1; } /* Copy the password and swap the lower and higher words */ data[0] = password[2]; data[1] = password[3]; data[2] = password[0]; data[3] = password[1]; for (int i = 0; i < numRetries; i++) { if (reader.SendTagPassword(tag, data) == true) { return(true); } } return(false); }
/// <summary> /// This function will read all the contents of the User Memory Bank. The function /// returns when no more data can be read. /// </summary> /// <param name="reader"></param> /// <returns></returns> public byte[] ReadUserData(STPv3Reader reader) { UInt16 address = 0x3000; // Starting Address for the User Memory Bank UInt16 blocks = 0x0001; byte[] data = new byte[1024]; byte[] tempData = new byte[2]; int i = 0, j = 0; while (i < 1024) { if ((tempData = ReadTagMemory(reader, address, blocks)) == null) { break; } address++; i += 2; data[j++] = tempData[0]; data[j++] = tempData[1]; } if (i == 0) { return(null); } /* Send the byte buffer back with the data read */ byte[] newDataBuf = new byte[j]; System.Buffer.BlockCopy(data, 0, newDataBuf, 0, j); return(newDataBuf); }
/// <summary> /// This function Writes the data to the EPC Memory Bank. It will calculate the PC /// value to be written automatically. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns the actual number of bytes written.</returns> public int WriteEPC(STPv3Reader reader, byte[] data) { UInt16 address = 0x1001; UInt16 blocks = 0x0001; byte[] tempData = new byte[2]; int i = 0; /* Check the Length of the EPC (Data Length) and calculate the PC bits */ tempData[0] = (byte)((data.Length / 2) << 3); tempData[1] = 0; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return(i); } /* Write the EPC to the tag one block at a time */ for (i = 0; i < data.Length; i += 2) { tempData[0] = data[i]; tempData[1] = data[i + 1]; /* Update address to write to the next block. */ address++; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return(i); } } return(i); }
/// <summary> /// This sends the EPC Class1 Gen2 Lock Value to the tag. The lock value would be the /// different memory banks lock protection values ORed together into a single 32-bit value. /// </summary> /// <param name="reader"></param> /// <param name="lockVal"></param> /// <returns></returns> public bool LockTag(STPv3Reader reader, UInt32 lockVal) { byte[] data = new byte[4]; UInt16 address = 0x0000; // Always set to 0 UInt16 blocks = 0x0000; // Always set to 0 int numRetries = retries; if (numRetries == 0) { retries = 1; } data[0] = (byte)((lockVal & 0xFF000000) >> 24); data[1] = (byte)((lockVal & 0x00FF0000) >> 16); data[2] = (byte)((lockVal & 0x0000FF00) >> 8); data[3] = (byte)(lockVal & 0x000000FF); if (this.SendTagPassword(reader) == true) { for (int i = 0; i < numRetries; i++) { if (reader.LockTagData(tag, data, address, blocks) == true) { return(true); } } } return(false); }
/// <summary> /// This will write the data to the User Memory Bank. The function will exit with a Pass /// if all the data was written. If not, then a failure message is returned. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns the actual number of bytes written.</returns> public int WriteUserData(STPv3Reader reader, byte[] data) { UInt16 address = 0x3000; // Starting Address for the User Memory Bank UInt16 blocks = 0x0001; byte[] tempData = new byte[2]; int i = 0; /* Keep writing data till we encounter a failure */ for (i = 0; i < data.Length; i += 2) { tempData[0] = data[i]; tempData[1] = data[i + 1]; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return(i); } /* Update address to write to the next block. */ address++; } return(i); }
/// <summary> /// This function will read the Kill Password from the Reserved Memory Bank of the /// EPC Tag /// </summary> /// <param name="reader"></param> /// <returns></returns> public byte[] ReadKillPassword(STPv3Reader reader) { UInt16 address = 0x0000; // Starting Address for the Kill Password UInt16 blocks = 0x0002; return(ReadTagMemory(reader, address, blocks)); }
/// <summary> /// Resets the Read Protection that was set on an NXP G2XL or G2XM tag. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if the operation passes. Else it returns False</returns> public bool ResetReadProtection(STPv3Reader reader) { byte[] dataBuf = new byte[5]; int numRetries = retries; byte[] data = new byte[4]; if (numRetries == 0) retries = 1; data[0] = password[2]; data[1] = password[3]; data[2] = password[0]; data[3] = password[1]; /* Data - Config Command (1-byte) + Access Password (4-bytes) */ dataBuf[0] = 0x02; // Command Code for Resetting Read Protection System.Buffer.BlockCopy(data, 0, dataBuf, 1, data.Length); for (int i = 0; i < numRetries; i++) { /* Send the Write Tag Config Command to the Reader */ if (reader.WriteTagConfig(tag, 0, 1, dataBuf) == true) return true; } return false; }
static void Main(string[] args) { SerialDevice sd; STPv3Reader reader; STPv3Request request; STPv3Response response; Tag tag = new Tag(); tag.Type = TagType.AUTO_DETECT; string port; byte[] resp; float temp; if (args.Length < 1) port = "COM1"; else port = args[0]; sd = new SerialDevice(); reader = new STPv3Reader(sd); try { sd.Address = port; sd.BaudRate = 38400; sd.Open(); // read product code, reader name, hw version, fw version, and reader ID Console.Out.WriteLine(String.Format("Product Code: {0}", reader.ProductCode)); Console.Out.WriteLine(String.Format("Reader Name: {0}", reader.ReaderName)); Console.Out.WriteLine(String.Format("Hardware Version: {0}", reader.HardwareVersion)); Console.Out.WriteLine(String.Format("Firmware Version: {0}", reader.FirmwareVersion)); Console.Out.WriteLine(String.Format("Reader ID: {0}", String.Join("", Array.ConvertAll<byte, string>(reader.ReaderID, delegate(byte value){ return String.Format("{0:X2}", value); })))); //scan for tags request = new STPv3Request(); request.Tag = tag; request.Command = STPv3Commands.SELECT_TAG; request.Inventory = true; request.Issue(sd); while (((response = request.GetResponse()) != null) && (response.Success)) { if (response.ResponseCode == STPv3ResponseCode.SELECT_TAG_PASS) { Console.Out.WriteLine(String.Format("Tag found: {0} -> {1}", Enum.GetName(typeof(SkyeTek.Tags.TagType), response.TagType), String.Join("", Array.ConvertAll<byte, string>(response.TID, delegate(byte value) { return String.Format("{0:X2}", value); })))); } } } catch (Exception ex) { Console.Out.WriteLine(ex.ToString()); } Console.In.ReadLine(); }
/// <summary> /// This will write the 4-byte Kill Password to the Reserved Memory Bank. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns True if Password written correctly else returns False.</returns> public bool WriteKillPassword(STPv3Reader reader, byte[] data) { UInt16 address = 0x0000; // Starting Address for the Reserved Memory Bank and Kill Password UInt16 blocks = 0x0002; if (WriteTagMemory(reader, address, blocks, data) == true) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <returns></returns> public MUXType DetectMultiplexer(STPv3Reader reader) { MUXType muxType; byte[] data; data = reader.ReadSystemParameter((ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1); muxType = MUXType.FOUR_PORT_HF + data[0] - 1; return(muxType); }
/// <summary> /// /// </summary> /// <returns></returns> public MUXType DetectMultiplexer(STPv3Reader reader) { MUXType muxType; byte[] data; data = reader.ReadSystemParameter((ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1); muxType = MUXType.FOUR_PORT_HF + data[0] - 1; return muxType; }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="portVal"></param> /// <returns></returns> public bool SetMultiplexerPort(STPv3Reader reader, byte portVal) { byte[] data = new byte[1]; byte[] muxPorts = MuxPortList(multiplexerType); if (multiplexerType.Equals(MUXType.FOUR_PORT_HF) || multiplexerType.Equals(MUXType.FOUR_PORT_UHF)) { if ((portVal != 0) && (portVal != 2) && (portVal != 5) && (portVal != 7)) { return(false); } if (portVal == 0) { portIndex = 0; } if (portVal == 2) { portIndex = 1; } if (portVal == 5) { portIndex = 2; } if (portVal == 7) { portIndex = 3; } } else { if (portVal > maxPort) { return(false); } } data[0] = portVal; currentPort = portVal; if (reader.WriteSystemParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) { return(true); } else { return(false); } }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <returns></returns> public bool EnableMultiplexer(STPv3Reader reader) { /* This requires that the Mux System Parameter be set to 02 in Non-Volatile Memory */ byte[] data = new byte[1] { 0x02 }; if (reader.StoreDefaultParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) { return(true); } else { return(false); } }
/// <summary> /// This function will detect a tag in the field and will return the tag or /// just return Null. /// </summary> /// <param name="reader"></param> /// <param name="newTag">Reference which will be updated it a tag is detected.</param> /// <returns>Tag if True else it returns Null</returns> public Tag DetectTag(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { if (reader.SelectTag(ref tag) == true) return tag; } return null; }
/// <summary> /// This function scans for EAS Alarms that would be sent out by the NXP G2XL and G2XM /// tags that have the EAS functionality Enabled. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if EAS Alrm is detected. Else it returns False</returns> public bool ScanEAS(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { /* Send the Scan EAS Command to the reader */ if (reader.scanEAS(tag) == true) return true; } return false; }
/// <summary> /// This function is used to Write Any Data to Any of the Meory banks. The calling /// function will have to select the correct starting address block information /// and data to be written.This can also be used for writing the Lock Values to /// the EPC Tag. /// </summary> /// <param name="reader"></param> /// <param name="address"></param> /// <param name="blocks"></param> /// <param name="data"></param> /// <returns>Returns True if data written correctly else returns False.</returns> public bool WriteTagMemory(STPv3Reader reader, UInt16 address, UInt16 blocks, byte[] data) { int numRetries = retries; if (numRetries == 0) { retries = 1; } for (int i = 0; i < numRetries; i++) { if (reader.WriteTagData(tag, data, address, blocks) == true) { return(true); } } return(false); }
/// <summary> /// This function will detect a tag in the field and will return the tag or /// just return Null. /// </summary> /// <param name="reader"></param> /// <param name="newTag">Reference which will be updated it a tag is detected.</param> /// <returns>Tag if True else it returns Null</returns> public Tag DetectTag(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) { retries = 1; } for (int i = 0; i < numRetries; i++) { if (reader.SelectTag(ref tag) == true) { return(tag); } } return(null); }
/// <summary> /// This function is used to disable the EAS functionality for the NXP G2XM and G2XM tags. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if the operation passes. Else it returns False</returns> public bool DisableEAS(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) retries = 1; /* Send the Access Password to the tag first */ if (this.SendTagPassword(reader) == true) { for (int i = 0; i < numRetries; i++) { /* If Send Tag Password passes, then send the Disable EAS Command to the tag */ if (reader.disableEAS(tag) == true) return true; } } return false; }
/// <summary> /// This function is used to read data from Any Memory bank, address and any number /// of blocks. /// The function will return a NULL if no data was read, else it will return the /// data read and set the length to the data read. (?) /// </summary> /// <param name="reader"></param> /// <param name="address"></param> /// <param name="blocks"></param> /// <returns></returns> public byte[] ReadTagMemory(STPv3Reader reader, UInt16 address, UInt16 blocks) { byte[] data; int numRetries = retries; if (numRetries == 0) { retries = 1; } for (int i = 0; i < numRetries; i++) { if ((data = reader.ReadTagData(tag, address, blocks)) != null) { return(data); } } return(null); }
/// <summary> /// This function is used to disable the EAS functionality for the NXP G2XM and G2XM tags. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if the operation passes. Else it returns False</returns> public bool DisableEAS(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) retries = 1; /* Send the Access Password to the tag first */ if (this.SendTagPassword(reader) == true) { for (int i = 0; i < numRetries; i++) { /* If Send Tag Password passes, then send the Disable EAS Command to the tag */ if (reader.disableEAS(tag) == true) return true; } } return false; }
/// <summary> /// This function checks the current port and switches to the next port. If the max port is reached, /// then /// </summary> /// <param name="reader"></param> /// <returns></returns> public bool IncrementMultiplexerPort(STPv3Reader reader) { byte[] data = new byte[1]; byte[] muxPorts = MuxPortList(multiplexerType); currentPort++; if (portIndex >= maxPort) { portIndex = 0; } data[0] = muxPorts[portIndex]; if (reader.WriteSystemParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) { return(true); } else { return(false); } }
/// <summary> /// This function performs Inventory on the type of Tag Passes in and returns with a list of /// tags detected. If no tags detected or if another error encountered, then Null is returned. /// </summary> /// <param name="reader"></param> /// <returns>An ArrayList of Tags detected</returns> public ArrayList DetectTags(STPv3Reader reader) { ArrayList x; x = new ArrayList(); int numRetries = retries; if (numRetries == 0) { retries = 1; } for (int i = 0; i < numRetries; i++) { try { x = reader.InventoryTags(tag); } catch (Exception ex) { Debug.WriteLine(ex); } if (x != null) { return(x); } //if ((x = reader.InventoryTags(tag)) != null) //{ // return x; //} } return(null); }
/// <summary> /// This function will read all the contents of the User Memory Bank. The function /// returns when no more data can be read. /// </summary> /// <param name="reader"></param> /// <returns></returns> public byte[] ReadUserData(STPv3Reader reader) { UInt16 address = 0x3000; // Starting Address for the User Memory Bank UInt16 blocks = 0x0001; byte[] data = new byte[1024]; byte[] tempData = new byte[2]; int i = 0, j = 0; while (i < 1024) { if ((tempData = ReadTagMemory(reader, address, blocks)) == null) { break; } address++; i += 2; data[j++] = tempData[0]; data[j++] = tempData[1]; } if (i == 0) return null; /* Send the byte buffer back with the data read */ byte[] newDataBuf = new byte[j]; System.Buffer.BlockCopy(data, 0, newDataBuf, 0, j); return newDataBuf; }
/// <summary> /// This function is used to read data from Any Memory bank, address and any number /// of blocks. /// The function will return a NULL if no data was read, else it will return the /// data read and set the length to the data read. (?) /// </summary> /// <param name="reader"></param> /// <param name="address"></param> /// <param name="blocks"></param> /// <returns></returns> public byte[] ReadTagMemory(STPv3Reader reader, UInt16 address, UInt16 blocks) { byte[] data; int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { if ((data = reader.ReadTagData(tag, address, blocks)) != null) return data; } return null; }
/// <summary> /// This function will read the Kill Password from the Reserved Memory Bank of the /// EPC Tag /// </summary> /// <param name="reader"></param> /// <returns></returns> public byte[] ReadKillPassword(STPv3Reader reader) { UInt16 address = 0x0000; // Starting Address for the Kill Password UInt16 blocks = 0x0002; return (ReadTagMemory(reader, address, blocks)); }
/// <summary> /// This sends the EPC Class1 Gen2 Lock Value to the tag. The lock value would be the /// different memory banks lock protection values ORed together into a single 32-bit value. /// </summary> /// <param name="reader"></param> /// <param name="lockVal"></param> /// <returns></returns> public bool LockTag(STPv3Reader reader, UInt32 lockVal) { byte[] data = new byte[4]; UInt16 address = 0x0000; // Always set to 0 UInt16 blocks = 0x0000; // Always set to 0 int numRetries = retries; if (numRetries == 0) retries = 1; data[0] = (byte)((lockVal & 0xFF000000) >> 24); data[1] = (byte)((lockVal & 0x00FF0000) >> 16); data[2] = (byte)((lockVal & 0x0000FF00) >> 8); data[3] = (byte)(lockVal & 0x000000FF); if (this.SendTagPassword(reader) == true) { for (int i = 0; i < numRetries; i++) { if (reader.LockTagData(tag, data, address, blocks) == true) return true; } } return false; }
/// <summary> /// This function performs Inventory on the type of Tag Passes in and returns with a list of /// tags detected. If no tags detected or if another error encountered, then Null is returned. /// </summary> /// <param name="reader"></param> /// <returns>An ArrayList of Tags detected</returns> public ArrayList DetectTags(STPv3Reader reader) { ArrayList x; x = new ArrayList(); int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { try { x = reader.InventoryTags(tag); } catch (Exception ex) { Debug.WriteLine(ex); } if (x != null) { return x; } //if ((x = reader.InventoryTags(tag)) != null) //{ // return x; //} } return null; }
/// <summary> /// This will write the data to the User Memory Bank. The function will exit with a Pass /// if all the data was written. If not, then a failure message is returned. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns the actual number of bytes written.</returns> public int WriteUserData(STPv3Reader reader, byte[] data) { UInt16 address = 0x3000; // Starting Address for the User Memory Bank UInt16 blocks = 0x0001; byte[] tempData = new byte[2]; int i = 0; /* Keep writing data till we encounter a failure */ for (i = 0; i < data.Length; i += 2) { tempData[0] = data[i]; tempData[1] = data[i + 1]; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return i; } /* Update address to write to the next block. */ address++; } return i; }
/// <summary> /// This will write the 4-byte Kill Password to the Reserved Memory Bank. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns True if Password written correctly else returns False.</returns> public bool WriteKillPassword(STPv3Reader reader, byte[] data) { UInt16 address = 0x0000; // Starting Address for the Reserved Memory Bank and Kill Password UInt16 blocks = 0x0002; if (WriteTagMemory(reader, address, blocks, data) == true) return true; return false; }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <param name="portVal"></param> /// <returns></returns> public bool SetMultiplexerPort(STPv3Reader reader, byte portVal) { byte[] data = new byte[1]; byte[] muxPorts = MuxPortList(multiplexerType); if (multiplexerType.Equals(MUXType.FOUR_PORT_HF) || multiplexerType.Equals(MUXType.FOUR_PORT_UHF)) { if ((portVal != 0) && (portVal != 2) && (portVal != 5) && (portVal != 7)) { return false; } if (portVal == 0) portIndex = 0; if (portVal == 2) portIndex = 1; if (portVal == 5) portIndex = 2; if (portVal == 7) portIndex = 3; } else { if (portVal > maxPort) return false; } data[0] = portVal; currentPort = portVal; if (reader.WriteSystemParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) return true; else return false; }
/// <summary> /// This function checks the current port and switches to the next port. If the max port is reached, /// then /// </summary> /// <param name="reader"></param> /// <returns></returns> public bool IncrementMultiplexerPort(STPv3Reader reader) { byte[] data = new byte[1]; byte[] muxPorts = MuxPortList(multiplexerType); currentPort++; if (portIndex >= maxPort) portIndex = 0; data[0] = muxPorts[portIndex]; if (reader.WriteSystemParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) return true; else return false; }
public byte GetMultiplexerPort(STPv3Reader reader) { return (byte)currentPort; }
static void Main(string[] args) { STPv3Reader reader = null; string s; MFDevice myDevice = null; MFDevice[] ar = MFDeviceFactory.Enumerate(); if (ar.Length != 0) { foreach (MFDevice mfd in ar) { s = ""; Debug.Print(""); Debug.Print("Begin Report"); Debug.Print("************************"); Debug.Print("IP Address:" + mfd.MFIPEndPoint); s = BitConverter.ToString(mfd.MacAddr).Replace("-", ""); Debug.Print("MAC ADDRESS:" + s); Debug.Print("ADDRESS FAMILY:" + mfd.AddrFamily); Debug.Print("REMOTE SOCKET PORT:" + mfd.RemotePort.ToString()); if (s == "00409D3D4897") //<--your Device Mac Address here { myDevice = mfd; break; } } try { //System parameter reads if (myDevice == null) { //My Device is not on the Network Debug.Print("NULL OBJECT ERROR"); return; } myDevice.SetReadTimeOut = 500; reader = new STPv3Reader(myDevice); reader.Open(); Debug.Print("Hardware Version:" + reader.HardwareVersion); Debug.Print("Product Code:" + reader.ProductCode); Debug.Print("Reader Firmware:" + reader.FirmwareVersion); Debug.Print(String.Format("Reader ID: {0}", String.Join("", Array.ConvertAll <byte, string>(reader.ReaderID, delegate(byte value) { return(String.Format("{0:X2}", value)); })))); Debug.Print("Reader Start Frequency:" + reader.StartFrequency); Debug.Print("Reader Stop Frequency: " + reader.StopFrequency); Debug.Print("Reader Power Level:" + reader.PowerLevel); Debug.Print("INVENTORY EXAMPLE"); byte[] r = new byte[1]; r[0] = 20; //20 retries, anticipate 10 tags in the field STPv3Response response = null; STPv3Request requestTag = new STPv3Request(); requestTag.Command = STPv3Commands.WRITE_SYSTEM_PARAMETER; // set reader retries, usually the number of retries should be twice as much as //the anticipated tags in the field! requestTag.Address = 0x0011; requestTag.Blocks = 0x01; requestTag.Data = r; requestTag.Issue(myDevice); response = requestTag.GetResponse(); if (!response.Success) { Debug.Print("Cannot set retries"); } STPv3Response stpresponse = null; STPv3Request request = new STPv3Request(); request.Command = STPv3Commands.SELECT_TAG; request.Inventory = true; Tag tag = new Tag(); tag.Type = TagType.AUTO_DETECT; request.Tag = tag; //change the time out for Inventory and Loop modes myDevice.SetReadTimeOut = 20; try { request.Issue(myDevice); while (true) { stpresponse = request.GetResponse(); if (stpresponse == null) { Debug.Print("NULL RESPONSE"); } if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_PASS) { Debug.Print(String.Format("Tag found: {0} -> {1}", Enum.GetName(typeof(SkyeTek.Tags.TagType), stpresponse.TagType), String.Join("", Array.ConvertAll <byte, string>(stpresponse.TID, delegate(byte value) { return(String.Format("{0:X2}", value)); })))); } if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_INVENTORY_DONE) { Debug.Print("RECEIVED SELECT_TAG_INVENTORY_DONE"); break; } //Readers return select tag fail as inventory end, if no tags in field if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_FAIL) { Debug.Print("RECEIVED SELECT_TAG_FAIL"); break; } } } catch (Exception ee) { Debug.Print("Exception " + ee.Message); } Debug.Print(""); Debug.Print("*************** End Report ************************"); reader.Close(); } catch (SocketException ex) { Debug.Print(ex.ToString()); } catch (Exception e) { Debug.Print("Exception " + e.ToString()); reader.Close(); } } }
/// <summary> /// This sends the Access Password to the tag to put it in Secure Mode. /// </summary> /// <param name="reader"></param> /// <param name="password"></param> /// <returns></returns> public bool SendTagPassword(STPv3Reader reader) { byte[] data = new byte[4]; int numRetries = retries; if (numRetries == 0) numRetries = 1; /* Copy the password and swap the lower and higher words */ data[0] = password[2]; data[1] = password[3]; data[2] = password[0]; data[3] = password[1]; for (int i = 0; i < numRetries; i++) { if (reader.SendTagPassword(tag, data) == true) return true; } return false; }
/// <summary> /// This function Writes the data to the EPC Memory Bank. It will calculate the PC /// value to be written automatically. /// </summary> /// <param name="reader"></param> /// <param name="data"></param> /// <returns>Returns the actual number of bytes written.</returns> public int WriteEPC(STPv3Reader reader, byte[] data) { UInt16 address = 0x1001; UInt16 blocks = 0x0001; byte[] tempData = new byte[2]; int i = 0; /* Check the Length of the EPC (Data Length) and calculate the PC bits */ tempData[0] = (byte)((data.Length / 2) << 3); tempData[1] = 0; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return i; } /* Write the EPC to the tag one block at a time */ for (i = 0; i < data.Length; i += 2) { tempData[0] = data[i]; tempData[1] = data[i + 1]; /* Update address to write to the next block. */ address++; if (WriteTagMemory(reader, address, blocks, tempData) == false) { return i; } } return i; }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <returns></returns> public bool DisableMultiplexer(STPv3Reader reader) { /* This requires that the Mux System Parameter be set to 00 in Non-Volatile Memory */ byte[] data = new byte[1] { 0x00 }; if (reader.StoreDefaultParameter(data, (ushort)SYS_PARAMS.SYS_MUX_CONTROL, 1) == true) return true; else return false; }
/// <summary> /// This function is used to Write Any Data to Any of the Meory banks. The calling /// function will have to select the correct starting address block information /// and data to be written.This can also be used for writing the Lock Values to /// the EPC Tag. /// </summary> /// <param name="reader"></param> /// <param name="address"></param> /// <param name="blocks"></param> /// <param name="data"></param> /// <returns>Returns True if data written correctly else returns False.</returns> public bool WriteTagMemory(STPv3Reader reader, UInt16 address, UInt16 blocks, byte[] data) { int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { if (reader.WriteTagData(tag, data, address, blocks) == true) return true; } return false; }
//Create a skyetek reader from a skyetek device. Set default tag type. public void CreateReader() { device.Open(); reader = new STPv3Reader(device); }
public byte GetMultiplexerPort(STPv3Reader reader) { return((byte)currentPort); }
static void Main(string[] args) { STPv3Reader reader = null; string s; MFDevice myDevice = null; MFDevice[] ar = MFDeviceFactory.Enumerate(); if (ar.Length != 0) { foreach (MFDevice mfd in ar) { s = ""; Debug.Print(""); Debug.Print("Begin Report"); Debug.Print("************************"); Debug.Print("IP Address:" + mfd.MFIPEndPoint); s=BitConverter.ToString(mfd.MacAddr).Replace("-", ""); Debug.Print("MAC ADDRESS:" + s); Debug.Print("ADDRESS FAMILY:" + mfd.AddrFamily); Debug.Print("REMOTE SOCKET PORT:" + mfd.RemotePort.ToString()); if (s == "00409D3D4897") //<--your Device Mac Address here { myDevice = mfd; break; } } try { //System parameter reads if (myDevice == null) { //My Device is not on the Network Debug.Print("NULL OBJECT ERROR"); return; } myDevice.SetReadTimeOut = 500; reader = new STPv3Reader(myDevice); reader.Open(); Debug.Print("Hardware Version:" + reader.HardwareVersion); Debug.Print("Product Code:" + reader.ProductCode); Debug.Print("Reader Firmware:" + reader.FirmwareVersion); Debug.Print(String.Format("Reader ID: {0}", String.Join("", Array.ConvertAll<byte, string>(reader.ReaderID, delegate(byte value) { return String.Format("{0:X2}", value); })))); Debug.Print("Reader Start Frequency:" + reader.StartFrequency); Debug.Print("Reader Stop Frequency: " + reader.StopFrequency); Debug.Print("Reader Power Level:" + reader.PowerLevel); Debug.Print("INVENTORY EXAMPLE"); byte[] r = new byte[1]; r[0] = 20; //20 retries, anticipate 10 tags in the field STPv3Response response = null; STPv3Request requestTag = new STPv3Request(); requestTag.Command = STPv3Commands.WRITE_SYSTEM_PARAMETER; // set reader retries, usually the number of retries should be twice as much as //the anticipated tags in the field! requestTag.Address = 0x0011; requestTag.Blocks = 0x01; requestTag.Data = r; requestTag.Issue(myDevice); response = requestTag.GetResponse(); if(!response.Success) Debug.Print("Cannot set retries"); STPv3Response stpresponse = null; STPv3Request request = new STPv3Request(); request.Command = STPv3Commands.SELECT_TAG; request.Inventory = true; Tag tag = new Tag(); tag.Type = TagType.AUTO_DETECT; request.Tag = tag; //change the time out for Inventory and Loop modes myDevice.SetReadTimeOut = 20; try { request.Issue(myDevice); while (true) { stpresponse = request.GetResponse(); if (stpresponse == null) Debug.Print("NULL RESPONSE"); if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_PASS) { Debug.Print(String.Format("Tag found: {0} -> {1}", Enum.GetName(typeof(SkyeTek.Tags.TagType), stpresponse.TagType), String.Join("", Array.ConvertAll<byte, string>(stpresponse.TID, delegate(byte value) { return String.Format("{0:X2}", value); })))); } if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_INVENTORY_DONE) { Debug.Print("RECEIVED SELECT_TAG_INVENTORY_DONE"); break; } //Readers return select tag fail as inventory end, if no tags in field if (stpresponse.ResponseCode == STPv3ResponseCode.SELECT_TAG_FAIL) { Debug.Print("RECEIVED SELECT_TAG_FAIL"); break; } } } catch (Exception ee) { Debug.Print("Exception " + ee.Message); } Debug.Print(""); Debug.Print("*************** End Report ************************"); reader.Close(); } catch (SocketException ex) { Debug.Print(ex.ToString()); } catch (Exception e) { Debug.Print("Exception " + e.ToString()); reader.Close(); } } }
//Create a skyetek reader from a skyetek device. Set default tag type. public void CreateReader() { device.Open(); reader = new STPv3Reader(device); }
/// <summary> /// This function scans for EAS Alarms that would be sent out by the NXP G2XL and G2XM /// tags that have the EAS functionality Enabled. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if EAS Alrm is detected. Else it returns False</returns> public bool ScanEAS(STPv3Reader reader) { int numRetries = retries; if (numRetries == 0) retries = 1; for (int i = 0; i < numRetries; i++) { /* Send the Scan EAS Command to the reader */ if (reader.scanEAS(tag) == true) return true; } return false; }
static void Main(string[] args) { SerialDevice sd; STPv3Reader reader; STPv3Request request; STPv3Response response; Tag tag = new Tag(); tag.Type = TagType.AUTO_DETECT; string port; byte[] resp; float temp; if (args.Length < 1) { port = "COM1"; } else { port = args[0]; } sd = new SerialDevice(); reader = new STPv3Reader(sd); try { sd.Address = port; sd.BaudRate = 38400; sd.Open(); // read product code, reader name, hw version, fw version, and reader ID Console.Out.WriteLine(String.Format("Product Code: {0}", reader.ProductCode)); Console.Out.WriteLine(String.Format("Reader Name: {0}", reader.ReaderName)); Console.Out.WriteLine(String.Format("Hardware Version: {0}", reader.HardwareVersion)); Console.Out.WriteLine(String.Format("Firmware Version: {0}", reader.FirmwareVersion)); Console.Out.WriteLine(String.Format("Reader ID: {0}", String.Join("", Array.ConvertAll <byte, string>(reader.ReaderID, delegate(byte value){ return(String.Format("{0:X2}", value)); })))); //scan for tags request = new STPv3Request(); request.Tag = tag; request.Command = STPv3Commands.SELECT_TAG; request.Inventory = true; request.Issue(sd); while (((response = request.GetResponse()) != null) && (response.Success)) { if (response.ResponseCode == STPv3ResponseCode.SELECT_TAG_PASS) { Console.Out.WriteLine(String.Format("Tag found: {0} -> {1}", Enum.GetName(typeof(SkyeTek.Tags.TagType), response.TagType), String.Join("", Array.ConvertAll <byte, string>(response.TID, delegate(byte value) { return(String.Format("{0:X2}", value)); })))); } } } catch (Exception ex) { Console.Out.WriteLine(ex.ToString()); } Console.In.ReadLine(); }
/// <summary> /// Sets the Read Protection on the NXP G2XL and G2XM tags. This puts the tag in a mode /// so that the tag will respond with all 0s in place of its actual EPC. /// </summary> /// <param name="reader">SkyeTek UHF Reader used to send commands to the tag</param> /// <returns>Returns True if the operation passes. Else it returns False</returns> public bool SetReadProtection(STPv3Reader reader) { byte[] dataBuf = new byte[5]; int numRetries = retries; byte[] data = new byte[4]; if (numRetries == 0) retries = 1; data[0] = password[2]; data[1] = password[3]; data[2] = password[0]; data[3] = password[1]; /* Data - Config Command (1-byte) + Access Password (4-bytes) */ dataBuf[0] = 0x01; // Command Code for Setting Read Protection System.Buffer.BlockCopy(data, 0, dataBuf, 1, data.Length); for (int i = 0; i < numRetries; i++) { /* Send the Write Tag Config Command to the Reader */ if (reader.WriteTagConfig(tag, 0, 1, dataBuf) == true) return true; } return false; }