Pular para o conteúdo principal

JavaEE, JavaFX and RFID - Part 2: Reading RFID from Java

Hello, continuing our series of posts about RFID and JavaFX, today we are going to show you how we read the RFID tag information from the receptor using Java. Remember we are using the RFID USB Starter Kit, the information of this post is specific for this kit, however, I believe most of the information applies to others RFID readers.

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.

RFID Diagram

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

Comentários

  1. 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

Postar um comentário

Postagens mais visitadas deste blog

Genetic algorithms with Java

One of the most fascinating topics in computer science world is Artificial Intelligence . A subset of Artificial intelligence are the algorithms that were created inspired in the nature. In this group, we have Genetic Algorithms  (GA). Genetic Algorithms  To find out more about this topic I recommend the following MIT lecture and the Nature of Code book and videos created by Daniel Shiffman. Genetic Algorithms using Java After I remembered the basics about it, I wanted to practice, so I tried my own implementation, but I would have to write a lot of code to do what certainly others already did. So I started looking for Genetic Algorithm libraries and found Jenetics , which is a modern library that uses Java 8 concepts and APIs, and there's also JGAP . I decided to use Jenetics because the User Guide was so clear and it has no other dependency, but Java 8. The only thing I missed for Jenetics are more small examples like the ones I will show i...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.

Dancing lights with Arduino - The idea

I have been having fun with Arduino these days! In this article I am going to show how did I use an electret mic with Arduino to create a Dancing Lights circuit. Dancing Lights   I used to be an eletronician before starting the IT college. I had my own electronics maintenance office to fix television, radios, etc. In my free time I used to create electronic projects to sell and I made a few "reais" selling a version of Dancing lights, but it was too limited: it simply animated lamps using a relay in the output of a 4017 CMOS IC. The circuit was a decimal counter  controlled by a 555. 4017 decimal counter. Source in the image When I met Arduino a few years ago, I was skeptical because I said: I can do this with IC, why should I use a microcontroller. I thought that Arduino was for kids. But now my pride is gone and I am having a lot of fun with Arduino :-) The implementation of Dancing Lights with Arduino uses an electret mic to capture the sound and light leds...