public static List <byte> Get14443AMemory(Reader reader, Iso14443a.TagType tag, ref byte blockCount, string UID) { List <byte> data = new List <byte>(); byte[] _uid = ByteFormat.FromHex(UID); TagFilter tagFilter = new Select_UID((byte)(_uid.Length * 8), _uid); string[] block = Get14443AMemoryLayout(tag); data = GetTagData(reader, tagFilter, Convert.ToInt32(block[0]), 0, ref blockCount); return(data); }
/// <summary> /// Get the tag dat of the ISO15693 protocols tag. /// </summary> /// <param name="reader">Connected reader</param> /// <param name="tag">Selected tag of ISO15693</param> /// <param name="blockCount">No of memory blocks in the tag</param> /// <param name="blockSize">Size of each memory block</param> /// <param name="UID">UID of the tag for data to be read</param> /// <returns>Return list of data</returns> public static List <byte> Get15693Memory(Reader reader, Iso15693.TagType tag, byte blockCount, byte blockSize, string UID) { List <byte> data = new List <byte>(); byte[] _uid = ByteFormat.FromHex(UID); TagFilter tagFilter = new Select_UID((byte)(_uid.Length * 8), _uid); byte actualBlockCount = 0; data = GetTagData(reader, tagFilter, blockSize, blockCount, ref actualBlockCount); return(data); }
public static List <byte> MemoryLockStatus(Reader reader, byte blockLength, TagProtocol protocol, string uid) { List <byte> lockStatus = new List <byte>(); TagFilter filter; byte[] _uid = ByteFormat.FromHex(uid); switch (protocol) { case TagProtocol.ISO14443A: break; case TagProtocol.ISO14443B: break; case TagProtocol.ISO15693: //Iso15693.TagType tag = (Iso15693.TagType)tagType;//(Enum.GetName(typeof(Iso15693.TagType), tagType)); filter = new Select_UID((byte)(_uid.Length * 8), _uid); MemoryType type = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY; ReadMemory blockStatus = new ReadMemory(type, 0, blockLength); lockStatus.AddRange((byte[])reader.ExecuteTagOp(blockStatus, filter)); break; case TagProtocol.ISO180003M3: break; case TagProtocol.ISO180006B: break; case TagProtocol.ISO180006B_UCODE: break; case TagProtocol.ISO18092: break; case TagProtocol.LF125KHZ: break; case TagProtocol.LF134KHZ: break; case TagProtocol.NONE: break; default: break; } return(lockStatus); }
public static bool WriteTagMemory(uint address, byte[] data, string uid, Reader reader) { bool flag = false; byte[] _uid = ByteFormat.FromHex(uid); TagFilter filter = new Select_UID((byte)(_uid.Length * 8), _uid); MemoryType type = MemoryType.BLOCK_MEMORY; WriteMemory writeOp = new WriteMemory(type, address, data); try { reader.ExecuteTagOp(writeOp, filter); flag = true; } catch (Exception) { flag = false; //throw; } return(flag); }
/// <summary> /// Get the Memory Architecture of the ISO15693 tags. /// </summary> /// <param name="reader">Connected reader</param> /// <param name="tag">ISO15693 Tag type of the seclected tag</param> /// <param name="uid">UID of the selected tag</param> /// <returns>Returns memory organisation in String Array</returns> public static Dictionary <string, byte> Get15693AMemoryLayout(Reader reader, Iso15693.TagType tag, string uid) { Dictionary <string, byte> tagMemorystruct = new Dictionary <string, byte>(); //paramget to get the memory organisation //we will have the object which contains the tag info byte[] _uid = ByteFormat.FromHex(uid); TagFilter filter = new Select_UID((byte)(_uid.Length * 8), _uid); //TagFilter filter=new Select_TagType((UInt32)tag); MemoryType readType = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY; ReadMemory systemInfoOp = new ReadMemory(readType, 0, 0); byte[] systemInfo = (byte[])reader.ExecuteTagOp(systemInfoOp, filter); #region Info Flag byte infoFlag = systemInfo[0]; int systemInfoOffSet = 9; if ((infoFlag & 0x0001) == 0x0001) { byte dsfid = systemInfo[systemInfoOffSet++]; tagMemorystruct.Add("DSFID", dsfid); } if ((infoFlag & 0x0002) == 0x0002) { byte afi = systemInfo[systemInfoOffSet++]; tagMemorystruct.Add("AFI", afi); } if ((infoFlag & 0x0004) == 0x0004) { tagMemorystruct.Add("Block Size", systemInfo[systemInfoOffSet++]); tagMemorystruct.Add("Block Count", systemInfo[systemInfoOffSet++]); } #endregion return(tagMemorystruct); }
static void Main(string[] args) { // Program setup if (1 > args.Length) { Usage(); } 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 (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(); } //Use first antenna for operation if (antennaList != null) { r.ParamSet("/reader/tagop/antenna", antennaList[0]); } } else { if (antennaList != null) { Console.WriteLine("Module doesn't support antenna input"); Usage(); } } // This select filter matches all Gen2 tags where bits 32-48 of the EPC are 0x0123 #if ENABLE_FILTER TagFilter filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 16, new byte[] { 0x01, 0x23 }); #endif if (!model.Equals("M3e")) { //Gen2.TagData epc = new Gen2.TagData(new byte[] { // 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, // 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, //}); //Gen2.WriteTag tagop = new Gen2.WriteTag(epc); //r.ExecuteTagOp(tagop, null); } // Reads data from a tag memory bank after writing data to the requested memory bank without powering down of tag #if ENABLE_READ_AFTER_WRITE { //create a tagopList with write tagop followed by read tagop TagOpList tagopList = new TagOpList(); byte wordCount; ushort[] readData; //Write one word of data to USER memory and read back 8 words from EPC memory using WriteData and ReadData { ushort[] writeData = { 0x9999 }; wordCount = 8; Gen2.WriteData wData = new Gen2.WriteData(Gen2.Bank.USER, 2, writeData); Gen2.ReadData rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount); //Gen2.WriteTag wTag = new Gen2.WriteTag(epc); // assemble tagops into list tagopList.list.Add(wData); tagopList.list.Add(rData); Console.WriteLine("###################Embedded Read after write######################"); // uncomment the following for embedded read after write. embeddedRead(TagProtocol.GEN2, null, tagopList); // call executeTagOp with list of tagops //readData = (ushort[])r.ExecuteTagOp(tagopList, null); //Console.WriteLine("ReadData: "); //foreach (ushort word in readData) //{ // Console.Write(" {0:X4}", word); //} //Console.WriteLine("\n"); } //clearing the list for next operation tagopList.list.Clear(); //Write 12 bytes(6 words) of EPC and read back 8 words from EPC memory using WriteTag and ReadData { Gen2.TagData epc1 = new Gen2.TagData(new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, }); wordCount = 8; Gen2.WriteTag wtag = new Gen2.WriteTag(epc1); Gen2.ReadData rData = new Gen2.ReadData(Gen2.Bank.EPC, 0, wordCount); // assemble tagops into list tagopList.list.Add(wtag); tagopList.list.Add(rData); // call executeTagOp with list of tagops //readData = (ushort[])r.ExecuteTagOp(tagopList, null); //Console.WriteLine("ReadData: "); //foreach (ushort word in readData) //{ // Console.Write(" {0:X4}", word); //} //Console.WriteLine("\n"); } } #endif // Perform read and print UID and tagtype of tag found SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.ISO15693, null, null, 1000); r.ParamSet("/reader/read/plan", plan); TagReadData[] tagReads = r.Read(1000); Console.WriteLine("UID: " + tagReads[0].EpcString); Console.WriteLine("TagType: " + (Iso15693.TagType)(tagReads[0].TagType)); MemoryType type; MultiFilter mulfilter = null; UInt32 address; byte length; #if ENABLE_M3E_FILTER //Initialize filter // Filters the tag based on tagtype TagFilter tagTypeFilter = new Select_TagType((UInt64)((Iso15693.TagType)(tagReads[0].TagType))); // Filters the tag based on UID TagFilter uidFilter = new Select_UID(32, ByteFormat.FromHex(tagReads[0].Tag.EpcString.Substring(0, 8))); // Initialize multi filter mulfilter = new MultiFilter(new TagFilter[] { tagTypeFilter, uidFilter }); #endif #if ENABLE_M3E_BLOCK_READ_WRITE //Initialize all the fields required for Read Data Tag operation type = MemoryType.BLOCK_MEMORY; address = 0; length = 1; // Read memory before write ReadMemory bRead = new ReadMemory(type, address, length); byte[] dataRead = (byte[])r.ExecuteTagOp(bRead, mulfilter); // prints the data read Console.WriteLine("Read Data before performing block write: "); foreach (byte i in dataRead) { Console.Write(" {0:X2}", i); } Console.WriteLine("\n"); // Uncomment this to enable Embedded read memory //embeddedRead(TagProtocol.ISO15693, mulfilter, bRead); // Initialize write memory byte[] data = new byte[] { 0x11, 0x22, 0x33, 0x44 }; WriteMemory writeOp = new WriteMemory(type, address, data); // Execute the tagop r.ExecuteTagOp(writeOp, mulfilter); // Uncomment this to enable Embedded write data //embeddedRead(TagProtocol.ISO15693, mulfilter, writeOp); //Read memory after block write ReadMemory readOp = new ReadMemory(type, address, length); byte[] readData = (byte[])r.ExecuteTagOp(readOp, mulfilter); // prints the data read Console.WriteLine("Read Data after performing block write operation: "); foreach (byte i in readData) { Console.Write(" {0:X2}", i); } Console.WriteLine("\n"); #endif #if ENABLE_M3E_SYSTEM_INFORMATION_MEMORY //Get the system information of tag. Address and length fields have no significance if memory type is BLOCK_SYSTEM_INFORMATION_MEMORY. type = MemoryType.BLOCK_SYSTEM_INFORMATION_MEMORY; address = 0; length = 0; ReadMemory sysInfoOp = new ReadMemory(type, address, length); byte[] systemInfo = (byte[])r.ExecuteTagOp(sysInfoOp, mulfilter); // parsing the system info response if (systemInfo.Length > 0) { parseGetSystemInfoResponse(systemInfo); } #endif #if ENABLE_M3E_SECURE_ID // Read secure id of tag. Address and length fields have no significance if memory type is SECURE_ID. type = MemoryType.SECURE_ID; address = 0; length = 0; ReadMemory secureIdOp = new ReadMemory(type, address, length); byte[] rspData = (byte[])r.ExecuteTagOp(secureIdOp, mulfilter); // parse secure id operation response. if (rspData.Length > 0) { parseSecureIdResponse(rspData); } #endif #if ENABLE_M3E_BLOCK_PROTECTION_STATUS // Get the block protection status of block 0. type = MemoryType.BLOCK_PROTECTION_STATUS_MEMORY; address = 0; length = 1; ReadMemory blkProtectionOp = new ReadMemory(type, address, length); byte[] statusData = (byte[])r.ExecuteTagOp(blkProtectionOp, mulfilter); // parse the block protection status response. if (statusData.Length == length) { parseGetBlockProtectionStatusResponse(statusData, address, length); } #endif } } catch (ReaderException re) { Console.WriteLine("Error: " + re.Message); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }