Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何管理RFID_Java_Arraylist - Fatal编程技术网

Java 如何管理RFID

Java 如何管理RFID,java,arraylist,Java,Arraylist,实际上,我正在编写一个程序,通过记录员工的到达日期、工作时间和下班时间来控制RFID。我希望程序在第一次读取标记时首先获取日期和小时,并在第二次读取标记时给出退出时间。 您好,我正在编写一个程序,通过记录员工的到达日期、工作时间和下班时间来控制RFID。我希望程序在第一次读取标记时首先获取日期和小时,并在第二次读取标记时给出退出时间 import java.io.*; import java.util.*; import javax.comm.*; class RFIDTagRead impl

实际上,我正在编写一个程序,通过记录员工的到达日期、工作时间和下班时间来控制RFID。我希望程序在第一次读取标记时首先获取日期和小时,并在第二次读取标记时给出退出时间。 您好,我正在编写一个程序,通过记录员工的到达日期、工作时间和下班时间来控制RFID。我希望程序在第一次读取标记时首先获取日期和小时,并在第二次读取标记时给出退出时间

import java.io.*;
import java.util.*;
import javax.comm.*;

class RFIDTagRead implements Runnable, SerialPortEventListener, extend Transportation {
static CommPortIdentifier portId;
static Enumeration portList;

InputStream inputStream;



SerialPort serialPort;
Thread readThread;
//tableau consisting of SOH, length, command, data, BCC
static byte[] bytearray = {0x01, 0x02, 0x09, 0x32, 0x39};

static OutputStream outputStream;
static int n =0;

public static void main(String[] args) {
//Enumerate a list of available ports
portList = CommPortIdentifier.getPortIdentifiers();
// Identify the ports. I connected the reader with COM1
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
System.out.println("The port is: " + portId.getName());
RFIDTagRead reader = new RFIDTagRead();
}
}

}
}
public RFIDTagRead() {
try {
//Open the COM1 port and name it MicroReader with timeout 2000ms
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (Exception e) {System.out.println("Port Error");}
try {
outputStream = serialPort.getOutputStream();
// Write the stream of data conforming to PC to reader protocol
outputStream.write(bytearray);
outputStream.flush();

System.out.println("The following bytes are being written");
for(int i=0; i<bytearray.length; i++)
System.out.println(bytearray[i]);
System.out.println("Tag will be read when its in the field of the reader");
} catch (IOException e) {}
// Set Serial Port parameter
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
//Register an event listener object to the port
serialPort.addEventListener(this);
} catch (TooManyListenersException e)
{System.out.println("Too Many Listeners");
}
//Specify an event type. On data availability, triggers serialEvent method
serialPort.notifyOnDataAvailable(true);
try {
//Associate an InputStream object with this port.
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
//Start a thread to handle the time-to-read the tag
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(56);
} catch (InterruptedException e) {}
}
//This method is called by notifyOnDataAvailabe()
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:
n++; //to count the number of readings
System.out.println("The reading description of RFID Tag" + " " + n);
//array size must not be less than the number of bytes to be read
byte[] readBuffer = new byte[20]; // to store the read data
int numbyte = 0;
try {
while(inputStream.available() >0) {
// Read the RFID data and store in the byte array
numbyte = inputStream.read(readBuffer);
System.out.println("Number of Bytes read: " + numbyte);
}
} catch (IOException e) {}
if( readBuffer[0] == 1) /*check if start bit is detected */
{
int length = readBuffer[1];
// Identify the Transponder type
switch(readBuffer[2]) {
case 12 :
{
System.out.print("RFID is RO:" + "\t");
break;
}
case 13 :
{
System.out.print("RFID is R/W:" + "\t");
break;
}
case 14:
{
System.out.print("RFID is MPT/SAMPT:" + "\t");
break;
}
case 15:
{
System.out.print("RFID is Other:" + "\t");
break;
}
}
// Write the actual tag reading in Hexadecimal
for( int m = length+1; m > 2; m--)
System.out.print(Integer.toHexString(readBuffer[m] & 255));
}
System.out.println(" ");
System.out.println("\t" + "Read Sucessful");
System.out.println("----------------------------------");
break;
}
}
}
import java.io.*;
导入java.util.*;
导入javax.comm.*;
类RFIDTagRead实现可运行、SerialPortEventListener、扩展传输{
静态通信识别器端口;
静态枚举端口列表;
输入流输入流;
串行端口串行端口;
线程读取线程;
//由SOH、长度、命令、数据、密件抄送组成的表格
静态字节[]字节数组={0x01、0x02、0x09、0x32、0x39};
静态输出流输出流;
静态int n=0;
公共静态void main(字符串[]args){
//枚举可用端口的列表
portList=CommPortIdentifier.getPortIdentifiers();
//识别端口。我用COM1连接了读卡器
while(portList.hasMoreElements()){
portId=(CommPortIdentifier)portList.nextElement();
if(portId.getPortType()==CommPortIdentifier.PORT_串行){
if(portId.getName().equals(“COM1”)){
System.out.println(“端口为:+portId.getName());
RFIDTagRead reader=新的RFIDTagRead();
}
}
}
}
公共RFIDTagRead(){
试一试{
//打开COM1端口,并将其命名为MicroReader,超时时间为2000ms
serialPort=(serialPort)portId.open(“simpleradapp”,2000);
}catch(异常e){System.out.println(“端口错误”);}
试一试{
outputStream=serialPort.getOutputStream();
//写入符合PC-to-reader协议的数据流
outputStream.write(bytearray);
outputStream.flush();
System.out.println(“正在写入以下字节”);
对于(int i=0;i0){
//读取RFID数据并存储在字节数组中
numbyte=inputStream.read(readBuffer);
System.out.println(“读取的字节数:“+numbyte”);
}
}捕获(IOE){}
if(readBuffer[0]==1)/*检查是否检测到起始位*/
{
int length=readBuffer[1];
//识别应答器类型
开关(读缓冲区[2]){
案例12:
{
System.out.print(“RFID是RO:+”\t”);
打破
}
案例13:
{
系统输出打印(“RFID是R/W:“+”\t”);
打破
}
案例14:
{
System.out.print(“RFID是MPT/SAMPT:“+”\t”);
打破
}
案例15:
{
System.out.print(“RFID是其他的:“+”\t”);
打破
}
}
//以十六进制写入实际的标记读数
对于(int m=长度+1;m>2;m--)
System.out.print(Integer.toHexString(readBuffer[m]&255));
}
System.out.println(“”);
System.out.println(“\t”+“读取成功”);
System.out.println(“---------------------------------------------”);
打破
}
}
}

好的,你被困在哪里了?你能说明你的问题是什么吗?我不知道如何让扫描仪在第一次读取标签时输出到达日期和时间,在第二次读取标签时输出离开日期。换句话说,你不知道如何读取rfid扫描仪?