Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / WinMobile

Use Psion Teklogix 753x SDKs to Read/Write RFID Tags

4.88/5 (10 votes)
2 Feb 2009CPOL2 min read 47K   1.6K  
Work with the PtxRfidNet.dll SDKs to read/write RFID tags and Farsi language in hand-helds.

Introduction

The goal of this article is to illustrate the use of Psion Teklogix provided libraries to read/write RFID Tags using 753x hand-held devices. The provided sample is intended to be easy to use, and hopefully a proper kick-start to use the device. It also includes a library (PDAFarsiLib) to make Farsi (Persian) language texts appear properly on the device. You can find more information about the language library from Mohamed Abdel-Monem's article. You can also find a very comprehensive support from the manufacturer company as you will.

Prerequisites

In order to use the Psion Tecklogix provided SDKs to work with the device, you should have at least the following prerequisites in place:

ActiveSync must be installed

Connect the device to the PC while installing the ActiveSync setup.

Setup the PsionTeklogixCE420\RfidDeviceManager CAB file on the device

Installing RfidDeviceManager.cab would place the required libraries on the device to let your .NET application use the provided SDKs.

Using the Code

Use the .NET PtxRfidNet.dll SDK library to program the device. (Note: As stated in the Prerequisites step above, RfidDeviceManager.cab should be installed on the device and the PtxRfid.dll library should exist on the device.) To read or write Tags using the Psion Teklogix 753x device, an instance of DeviceInterface must be constructed and the proper readers selected.

On the Smart Device project, create an instance of the DeviceInterface class and use it to find the readers on the device:

C#
DeviceInterface DevInt = new DeviceInterface();

Find the proper reader (or all the readers) in the list:

C#
ReaderId[] _readers = DevInt.CreateReader(readerId);

Used the above readers (_readers) to read/write and work with the device.

Write the RFID Tag

Tag IDs are in Hex format, and they should be 24 characters in length. In order to write a hex number like “absdefg0123456789”, it should be written to an array of 12 bytes length and each byte holding a four bits hex number. So, byte[0] holds “ab” which is 171. To construct the proper byte array from the UID string:

C#
byte[] bUID = new byte[12];
for (int i = 0, j = 0; i < UID.Length; i = i + 2, j++)
{
    bUID[j] = byte.Parse(UID.Substring(i, 2), 
                   System.Globalization.NumberStyles.HexNumber);
}

Construct an EpcClass1Gen2 Tag and set its UID to the byte array constructed above:

C#
Tag rfidTag = new Tag(TagType.EpcClass1Gen2);
rfidTag.Uid = new TagUid(bUID, 96);

Use the WriteUid API from the selected reader to write the UID on the Tag:

C#
WriteTagUidParams param = new WriteTagUidParams();
_reader.WriteUid(param, rfidTag);

Asynchronous RFID Tag Read

Handle the AsynchronousDataDelegate event to read the RFID tags placed in front of the device.

C#
ReadTagParams t = new ReadTagParams(ReadModes.Triggered, 2000);
_reader.StartAsynchronousRead(t);
_reader.AsynchronousDataEvent += 
   new AsynchronousDataDelegate(reader_AsynchronousDataEvent);

When the RFID read triggers on the device, the following event would raise, and you can add the read UIDs to a ListBox as follows:

C#
void reader_AsynchronousDataEvent(object source, AsynchronousDataEventArgs e)
{
    if (e.tagData.Format == TagDataFormats.UnparsedRaw)
    {
        foreach (Tag id in e.tagData.TagList)
        {
            string tagUidStr = "";
            foreach (byte tagUid in id.Uid.Data)
            {
                tagUidStr += string.Format("{0:x2}", tagUid);
            }
            if (getListBoxItem(lstFoundTags, tagUidStr) < 0)
            {
                setListBoxItem(lstFoundTags, tagUidStr);
                _readCount++;
            }
        }
    }
}

Points of Interest

Hopefully, it wasn't too painful to read, and can be useful for someone. I found a very welcoming support from the company as well. Thanks to the Psion Teklogix support team.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)