JVM Languages

Java & RFID Tags

Source Code Accompanies This Article. Download It Now.

The Java Communication API lets you send commands to and receive responses from RFID readers such as the TI S2000 Micro Reader.

November, 2005: Java & RFID Tags

Shamshad develops RFID systems in Java for the supply chain and mining industries. He can be contacted at infotechmin@gmail.com.

An RFID system consists of an antenna and transceiver, which read data transmitted by a transponder via radio frequency (RF). The combined transceiver and antenna are called the "RFID reader." The transponder, referred to as the "RFID tag," is an integrated circuit containing RF circuitry. It transmits data when it comes within the electric or magnetic field of the antenna. The antenna transmits data to a processing unit where it is manipulated according to whatever business needs. The reader is connected to the processing unit or a computer's communication port.

Commands are sent from the computer to the reader, which then activates the transponder. The transponder's response is read by the reader, which transmits the data to the PC's communication port.

In this article, I examine how you use the Java Communication API to send commands to and receive responses from the Texas Instruments S2000 Micro Reader (see Figure 1). The TI S2000 Micro Reader (see http://www.ti.com/rfid/docs/products/ evalKits/RI-K2A-001A.shtml) is an intelligent module providing RF and control functions to read and program TI-RFID transponders. It is equipped with a Serial Communications Interface (SCI) that can be directly connected to a PC. The computer's communication port in this case is the RS-232 serial port.

Micro Reader Communication Protocol

At the outset of RFID development, it is important that you understand the communication protocol involved in sending signal commands from PCs to micro readers, and from micro readers back to computers. Figure 2 presents the byte sequence and its meaning for sending commands from PCs to micro readers.

The "Command Field" (see Table 1) defines the mode in which the micro reader operates and determines the operation that is to be carried out in the transponder. Depending on the setting of the relevant bits, the corresponding information specified in the Data Fields will be sent to the transponder (or not). Thus all functions of each particular transponder type can be executed. Tables 1(a), 1(b), and 1(c) describe the available settings for the PC-to-micro reader communication protocol.

If bit 5 (Power Burst II) is set for, say, programming and locking (see Figure 3), the micro reader automatically operates in single mode. Thus, users are enabled to validate the programming or lock response before a further cycle is started. If bit 2 (FBCC calculation) and bit 6 (Data) are set, the micro reader automatically calculates a 2-byte BCC over the data to be sent to the transponder and adds it to the protocol. When bits 2 and 6 are set, the PC must not send the 2-byte FBCC to the micro reader. Bit 4 (Power Pause Duration) is for future use and must not be set when addressing standard TI-RFID transponders.

If Command Field (2) is not present, standard TI-RFID write timings are used and wireless synchronization is switched on/off according to the status of input line WLSC. Also, the settings specified in Command Fields (1) and (2) are only valid during the execution of the current command (see Figures 3 and 4).

The BCC field, see Byte N+4(3) in Figure 2, is a 1-byte value of the Longitudinal Redundancy Check calculation (XORed bytes) for the preceding message. The calculation is performed on the entire message, excluding the Start-Mark. Figure 5 is an example of the BCC calculation.

Tables 2(a), 2(b), and 2(c) describe the micro reader-to-PC communication protocol. In most of the cases, you are mainly interested in the data embedded in the transponder. The data sent by the micro reader to the PC is sequenced as described in Table 2(a). In Table 2(a), the BCC field is a 1-byte value of the Longitudinal Redundancy Check calculation (XORed bytes) for the preceding message. The calculation is performed on the entire message excluding the Start-Mark.

The TI transponder protocol needs to be sent by the PC to the transponder via the micro reader. For simplicity, I only consider the read operation of RO and W/R transponders; see Figure 6. Figure 7 illustrates the transponder response for read only and read/write transponders, while Figure 8 presents the read/write transponder data format.

The Java Communications API

The Java Communication API provides a means to communicate with the outside devices via serial or parallel ports. Classes and interfaces are packaged in the javax.comm package. Classes and Interfaces in the javax.com package are:

Listing One is a Java program that reads an RFID tag. The steps it implements to read RFID tags via serial ports are:

Identify the port to which the reader is attached to the PC.

Open and claim the ownership of the port.

Resolve port ownership contention between multiple Java applications.

Create an OutputStream associated with the port.

Write the stream of data to the port. The stream of the data must conform to the PC-to-micro reader protocol. After the data is successfully written to the port, the reader switches into one of the modes as specified in the data field of the stream.

Register an event listener to the port.

Specify an event type: notifyOnDataAvailable().

The event type calls the interface method serialEvent().

Within the serialEvent method, the RFID tag data is read. When the tag is in the reader's field, it transmits data to the reader, which in turn, transmits to the PC via serial port.

Open and take the ownership of the communication port, COM1, to which the reader is connected; see the code excerpt in Example 1.

Sending commands to switch the reader to one of its operating modes. In Listing One, a command is sent via the serial port to switch the reader to "continuous normal mode," where the reader continuously reads whenever a tag comes to its field. The code:

sends the command to the port by writing the bytestream detailed in Table 3.

Register an event listener to the port, specify an event type, and handle the event. The tag data is read when an RFID tag comes in the field of the reader. This makes data available at the port of the PC. Availability of the data triggers the notifyOnDataAvailable() event, which is listened by the serialEvent() method where the data is fetched from the reader to the PC.

Conclusion

The Java program I present here lets the reader operate in continuous normal mode by sending bytes of stream. The data read by the RFID reader is transmitted to the PC via serial port. Once the data is available in the processing unit, it all depends on the application as to how those data are manipulated.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!