我必须将RFID阅读器与我的java项目连接起来。我为这个设备安装了所有必要的驱动程序并导入了所有必要的库。我用Eclipse程序编写了我的java项目。 我是RFID阅读器的初学者。以下代码不起作用。请帮帮我。
package com.caen.RFIDLibrary;
import com.caen.RFIDLibrary.CAENRFIDException;
import com.caen.RFIDLibrary.CAENRFIDLogicalSource;
import com.caen.RFIDLibrary.CAENRFIDPort;
import com.caen.RFIDLibrary.CAENRFIDReader;
import com.caen.RFIDLibrary.CAENRFIDReaderInfo;
import com.caen.RFIDLibrary.CAENRFIDTag;
public class reader_com {
public static void main (String[] args) throws CAENRFIDException{
CAENRFIDReader MyReader = new CAENRFIDReader(); //Create myObject
CAENRFIDReaderInfo Info = MyReader.GetReaderInfo(); // Create Object for reader info
String Model = Info.GetModel(); //Get info about model
String SerialNumber=Info.GetSerialNumber(); // Get info about serialNumber
String FWRelease = MyReader.GetFirmwareRelease(); // Get info about FW
MyReader.Connect(CAENRFIDPort.CAENRFID_USB, "COM13"); // Open a connection
CAENRFIDLogicalSource MySource = MyReader.GetSource("Source_0, Source_1"); // Choose Source 0-->RFID tags 1-->Barcode
MySource.SetQ_EPC_C1G2(3); // set Q Value
CAENRFIDTag[] MyTags = MySource.InventoryTag();
if (MyTags.length > 0){
System.out.println(Model);
System.out.println(SerialNumber);
System.out.println(FWRelease);
}
MyReader.Disconnect();
}
}
我收回了这个错误:
Exception in thread "main" java.lang.NullPointerException
at com.caen.RFIDLibrary.CAENRFIDReader$IOBuffer.access$1800(CAENRFIDReader.java:228)
at com.caen.RFIDLibrary.CAENRFIDReader$CAENRFIDOutPacket.AddHeader(CAENRFIDReader.java:2701)
at com.caen.RFIDLibrary.CAENRFIDReader.GetReaderInfo(CAENRFIDReader.java:3183)
at com.caen.RFIDLibrary.reader_com.main(reader_com.java:20)
答案 0 :(得分:0)
为了获取有关阅读器的任何信息(或调用CAENRFIDReader
对象的任何其他方法),首先需要连接到它。所以你的程序流程将是这样的:
CAENRFIDReader myReader = new CAENRFIDReader();
myReader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM13");
CAENRFIDReaderInfo info = MyReader.GetReaderInfo();
String model = info.GetModel();
String serialNumber = info.GetSerialNumber();
String fwRelease = myReader.GetFirmwareRelease();
CAENRFIDLogicalSource mySource = myReader.GetSource(...);
另请注意,如果您的阅读器在 COM13 上可用,您可能需要使用CAENRFIDPort.CAENRFID_RS232
而不是CAENRFIDPort.CAENRFID_USB
。