I have to make a RFID based attendance system where i have to write into the database once reading from the tag and finding out which student it is.My query is how do i take input from the RFID tag.Does the input buffer classes of JAVA provided are enough for the input and output or do i have to take a different approach.
Microchips in RFID tags can be read-write or read-only. With read-write chips, you can add information to the tag or write over existing information when the tag is within range of a reader, or interrogator. Read-write tags usually have a serial number that can't be written over.
The RFID reader is a network-connected device that can be portable or permanently attached. It uses radio waves to transmit signals that activate the tag. Once activated, the tag sends a wave back to the antenna, where it is translated into data.
A direct example of this is the differentiation between reading an RFID tag and writing on an RFID tag. While reading only takes the tag to access a specific memory block inside the RFID chip, writing on the memory requires the RFID chip to use more power during longer times.
The data stored on the RFID chip comes pre-programmed (pre-encoded) directly from the manufacturer, but can easily be re-programmed. However, there are a few things to consider before re-programming an RFID tag, such as memory bank information, the memory format (the way the data is represented), and character limits.
You can use the Java Communications API for this. I am working on the same and java comm api and rxtx work perfectly well for this. I have a program written for this. Here you go:
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM13")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {System.out.println(e);}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {System.out.println(e);}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {
System.out.println(e);
}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
System.out.println(e);
}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {System.out.println(e);}
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {System.out.println(e);}
break;
}
}
}
It has been a last years since I worked with RFID (ThinkMagic reader) and Java but every reader I used at the time had its own proprietary API. The JAR was only accessible with the purchase of the reader. Times may have changed, may be open source readers / implementations but check out the vendor site for your current make and model. The APIs are very straightforward once you have access to them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With