Part 1: The Application
Part 2: Reading RFID from Java
Part 3: REST API and Security
Part 4: The Client
The RFID reader
RFID is simply an identification that will be read using a Radio Frequency. The ID is in RFID tags which can be read using a RFID Reader. My purpose is only read the tag, so we won't go deep in the writing part, we will focus on reading a RFID tag.I used the simplest RFID Reader I could find since I was avoiding unnecessary trouble. The reader is connected by USB and we just have to connect it to a PC so we can start hearing the buzz when we approach a RFID tag to the reader.
Notice that the reader and the tags have some conditions such as frequency of operation. I won't go deep on these details on this post.
The reader I bought is integrated with the FTDI chip and it has total support for installation in the popular operating systems we have. Notice that the main duty of this chip was to interface the old RS232 interface with USB, so we need a driver.
Installing the library(driver)
Initially I found some issues to install the driver so I can perform the communication with the chip and simply read the incoming data. In another scenarios, it's usual to also write data, but today we will only read.First thing I did was to download the driver on D2XX web page, then I followed the instructions on the installation guide for linux, which was basically was run the following commands:
sudo cp /releases/build/arch/lib* /usr/local/lib
cd /usr/local/lib
sudo ln –s libftd2xx.so.1.1.12
libftd2xx.so
sudo chmod 0755 libftd2xx.so.1.1.12
* arch is the architecture of my operating system.
After this, I could see that a new directory was created under /dev when I connected my RFID reader using the USB cable:
So I opened the file(well, actually a symlink) under serial/by-id directory and I was able to read the content of my RFID when I approached the RFID tag to the reader:
After setting native stuff, it was time to find a way to read it from Java!
Reading FTDI from Java
In D2XX page we can find two libraries to read it from Java, however, I tried to use these and I had issues. The main issue was related to the native part and, as I said, I didn't want to waste time on this...Well, everything is a file in Linux, remember we were reading data using cat command. Why not read the content of that file from Java? Having this in mind, I created a simple program to read the content of that file, see the code:
Notice that it keeps the file open and busy(see method read), so it's not recommended to continuously read the file as did for test. A better implementation would be using the "new" WatchService, but it seems it doesn't work for symbolic links!
A reader from JavaFX
I tried to create a control that will perform the read for me. It's specific to the conditions I showed above, so I think it's not too reusable...
What I have it's a dialog and it lists the devices and then I can choose a device. After I choose it, it will accumulate the RFIDs that were read into a List. When you click a button, the dialog will dispose and a list of the read RFID will be available to the caller... See the source here and a screenshot:
Conclusion
Read RFID from Java is not a hard task on Linux. It could be, however, simpler if we had a library to make the operations for us.Source Code on github
thanks for giving this idea. i have download this source code but i am not able to working with this . i am using netbeans7.4 pls help me how to working with this . please send me details sagaralgundgi007@gmail.com
ResponderExcluir