October 22, 2016
Hot Topics:

RFID Programming Made Simple and Cheap

  • August 29, 2006
  • By Bradley L. Jones
  • Send Email »
  • More Articles »

RFID in Action

To repeat the key point, using RFID is simply a matter of reading the associated tag to get the unique ID. Once you have the unique ID, it is simple data. You need a reader to do the reading and tags to read. In the rest of this article, I'll walk through what it takes to use the Phidgets RFID reader mentioned above to read standard 125 KHz tags.

The RFID Hardware

The Phidgets RFID reader simply plugs into a USB port. Once plugged in, the hardware side of the example is set up. It can't get easier than that.

Reading a tag, however, does require a few more steps. For you to be able to tap into the hardware, you will need to install the Phidgets application programming interface (API). You can download this code from here. You also can download example programs and documentation from the site as well. While I'm using .NET on a Microsoft Windows XP machine, you will also find that there are APIs for Linux, the Mac, and other platforms as well.

Install the API by running the Phidgets21.msi file. This will install a dynamic link library that you will then be able to reference from your application. I used the 2.1 beta version of the library. If you use a different version, my code may not work because the libraries are not backward compatible. This version, however, seemed much easier to use than prior versions.

The RFID Program

Once you have the library installed, you are ready to begin building an RFID application. I'll be using Visual Studio 2005 and C# to build the application shown in Figure 3.

Figure 3: A simple RFID application

This application simply reads tags and displays their unique IDs in the form. If you read a tag, it will be shown in the Tag text field while it is being read, and then added to the listbox once the read is complete. In this way, the listbox will maintain a history of what has been read. Figure 4 shows the dialog after the reader has been turned on (by checking the box in the form) and after a few tags have been read.

Figure 4: Having read a few tags

To build this application, you start by creating a new C# Windows Application in Visual Studio 2005. You then should add a reference to the Phidgets API you installed earlier.

Add a reference by going to the Project menu and selecting Add Reference. Choose the COM tag and search for Phidgets Library 2.1. If it isn't there, use the Browse option and locate the DLL on you system. It is most likely to be at C:Program Files\Phidgets\PhidgetsCOM.dll. Once you've added this reference, you are ready to begin building the form.

The form in Figure 3 contains the following controls:

        Type                Name                Text        
CheckboxcboxAntennaTurn Reader On
LabellblAttachedNot Attached

Most of the other property values for the controls are left at the defaults. You can modify these in any way you want. I've included the full source code for this application in the download at the end of this article, so if you have trouble creating the form, just pull it from there.

Within the form class, which I called RFIDReader, I also set up three additional fields:

RFID   rfid1;string lastRFIDTag;Int32  TagCtr;

RFID creates an RFID object called rfid1. This object will be assigned to the RFID reader so that we can pull information from it. The lastRFIDTag string field simply stores the unique ID from the last tag read. Finally, TagCtr is used to store a simple count of the number of tags read. As you could see in Figure 4, this counter is used to display the count on the listbox. After setting up these variables, the lastRFIDTag is set to blanks and the TagCtr should be set to 0 when you first initialize your form variables.

With a form set up and variables declared, you should do one more thing before getting to the fun code. Add a couple of references to the Phidgets namespaces to the top of your listing:

using Phidgets;using Phidgets.Events;

Page 2 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel