通过USB连接R1240IB qID可穿戴蓝牙UHF RFID条形码阅读器和Java程序?

时间:2014-04-06 10:55:07

标签: java bluetooth usb rfid

我必须将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)

1 个答案:

答案 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