2014-04-06 62 views
0

我必須連接RFID閱讀器和我的java項目。我爲此設備安裝了所有必需的驅動程序,並導入了所有必需的庫。我使用Eclipse程序來編寫我的Java項目。 初學者使用RFID閱讀器。下面的代碼不起作用。請幫幫我。連接R1240IB qID穿戴式藍牙UHF RFID條碼閱讀器與Java程序通過USB?

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

我回來這個錯誤 – user3386169

+0

在線程異常 「主」 顯示java.lang.NullPointerException \t在com.caen.RFIDLibrary.CAENRFIDReader $ IOBuffer.access在com.caen.RFIDLibrary.CAENRFIDReader $ 1800(CAENRFIDReader.java:228) \t $ CAENRFIDOutPacket.AddHeader(CAENRFIDReader.java:2701) \t在com.caen.RFIDLibrary.CAENRFIDReader.GetReaderInfo(CAENRFIDReader.java:3183) \t在com.caen.RFIDLibrary.reader_com.main(reader_com.java:20) – user3386169

回答

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

+0

我有嘗試你建議,我又有了同樣的錯誤..... – user3386169

+0

那一行你你這一次的錯誤?你確定閱讀器已正確連接到COM13嗎? –

+0

現在錯誤是關於rxtxComm驅動程序 – user3386169