基于RFID的JAVA读写

我必须建立一个基于RFID的考勤系统,我必须在从标签读取数据后写入数据库并找出它是哪个学生。我的查询是如何从RFID标签中获取输入。是否为JAVA的输入缓冲类提供足够的输入和输出或我必须采取不同的方法。

您可以使用Java Communications API进行此操作。 我正在研究相同的java comm api和rxtx对此非常有效。 我有一个为此编写的程序。 干得好:

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; } } } 

自从我使用RFID(ThinkMagic阅读器)和Java以来​​,这已经是最后几年,但我当时使用的每个读者都拥有自己的专有API。 只有购买阅读器才能访问JAR。 时代可能已经改变,可能是开源阅读器/实现,但请查看供应商网站以获取您当前的品牌和型号。 一旦您访问它们,API就非常简单。