Windows Mobile app to read and write RFID TAGs
Hello
this time I would publish my code for a full blown RFID application: IP4-Scan-N-Tag-BRI. The app is written in C# (compact framework) for the ITC Handheld readers IP4 and IP30 and either ITC 700 color or CN3 devices.
At first, how does the app work in general and look:
The app starts and waits for reading a barcode. Secondly the app looks for a single TAG and thirdly writes the barcode data into the TAG.
The encoding and decoding of the TAGs data is done using a class called vwTag. Please forgive me with all the conversions between hex and binary inside this class, I would like to see how the TAG data looks like during the development cycles.
After you started the app, you will first have to select file-connect reader, so the device will connect with the portable RFID reader (either a IP4 or IP30). When the RFID reader is connected, the applications waits for a barcode. Both portable readers have a pull switch and you just have to trigger it to read a barcode. If the barcode is validated, the application switches to another state, it waits for a single TAG read now. Again just pull the trigger and target the RFID antenna towards a single TAG. If the application finds a single TAG, its data is validated against the encoding scheme in the vwTag class. This avoids reading/writing to unwanted TAGs. If the readed TAG is valid, pull the trigger a third time to write the barcode data into the TAG.
The application uses a ‘state machine’ (I like this nice term) to switch from one state to another. The known states are:
enum eStatus { Offline, ReadTag, ReadBarcode, WriteTag, TooManyTags, BarCodeErr, WriteTagError, InvalidTag, InvalidData, TagReadError, ReadBarcodeBoxID, BarcodeBoxIDError, //new with v3 ReadTwoTags, ReadTwoTagsError, WriteTwoTags, WriteTwoTagsError } eStatus CurrentStatus=eStatus.Offline;
As you can see, the app also supports one other feature: Two TAGs mode: the app will read/write two TAGs in parallel with two different BOXids (see vwTag class for the definition of BOXid). In real the app writes the two TAGs one by one, you cannot write two TAGs with different data within one WRITE command.
Here is a snippet from vwTAG class to show you the encoding of the TAG data:
#region version2 comment //VERSION 2 //String: 1J UN 049977473 123456789 .. //########### B I N A R Y ############### //EPC-Header 00110100 // Bit 88 to 95 //Filter 3 Bit xxx // Bit 85 to 87 zzz //Partition 110 // Bit 82 to 84 //Box-Ident 20 Bit 00000000010000000001 // Bit 62 to 81 // NEW: old Filter is renamed to DataID //DataID (Data identifier + Agency code) yy // Bit 60 to 61 00 = 1JUN // 01 = 5JUN // 10 = 6JUN // 11 = NDEF //Supplier-ID 30 Bit 000000000100000000010000000001 // Bit 30 to 59 //Item-Number 30 Bit 000000000100000000010000000001 // Bit 0 to 29 //"3400000040BEA620475BCD15" //Binary: 001101000000000000000000000000000100000010111110101001100010000001000111010110111100110100010101 //string: 101010001011001111011010111000100000010001100101011111010000001000000000000000000000000000101100 //1J UN 049977473 123456789 #endregion
The TAG data field and barcode definitions:
Valid TAGs
A valid TAG has following data (highest bit first, ro=readonly, rw=readwrite):
8 Bit EPC-Header: 00110100 ro Filter: 3 bit ro to distinguish two TAGs at the same box. see also Box-ID Partition: 011 ro Box ID: 20 bit ro BOX-ID (0- 1048574) Data ID 2 bit rw Data Identifier (1J, 6J oder 6J) and Issuing Agency Code (UN) SupplierID: 30 bit rw Delivery-Identification according to DUNS (0- 1073741822) ItemNumber: 30 bit rw Package Number (0- 1073741822)Valid Barcodes
License-Plate Barcode A valid Code128-barcode with License-Plate Scheme: Data Id: 1J, 5J or 6J Agency Code: UN SupplierID: [9 digits], spaces and hyphens will be ignored ItemNumber: [9 digits]Box-ID und TAG-Nr Barcodes
Exactly 5 digits number. First digit for TAG-No 1 or 2. The rest (4 digits) will be used as box number (Box-ID). Barcodetyp has to be Code39.
Source Code (VS 2005, compact framework 2, Mobile 2003):
[Download not found]