0

I have to connect RFID reader with my java project. I installed all necesary driver for this device and imported all necesary Libraries. I used Eclipse program to writing my java project. Am beginner with RFID readers. The below code doesn't work. Please help me.

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

And i get back this error:

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)
  • "Doesn't work" is not very helpful - can you be more specific ? – Paul R Apr 06 '14 at 11:00
  • i get back this error – user3386169 Apr 06 '14 at 11:03
  • 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) – user3386169 Apr 06 '14 at 11:03
  • You should add this exception message to your question, along with any other relevant information that might help someone debug your problem for you. – Paul R Apr 06 '14 at 11:05

1 Answers1

0

In order to get any information about the reader (or call any other method of the CAENRFIDReader object), you first need to connect to it. So the flow of your program would be like this:

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(...);

Also note, that if your reader is available on COM13, you would likely need to use CAENRFIDPort.CAENRFID_RS232 and not CAENRFIDPort.CAENRFID_USB.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • On what line you you get the error this time? Are you sure the reader is correctly connected to COM13? – Michael Roland Apr 07 '14 at 18:23
  • java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver Exception in thread "main" com.caen.RFIDLibrary.CAENRFIDException: @ No RS232 native support (install rxtxComm driver?) at com.caen.RFIDLibrary.CAENRFIDReader.Connect(CAENRFIDReader.java:3303) at com.caen.RFIDLibrary.reader_com.main(reader_com.java:18) – user3386169 Apr 07 '14 at 18:28
  • Well, then I would suggest you read the error message and do what it tells you. I.e. add the [rxtxComm library](http://www.caenrfid.it/en/faq.jsp?Id=9&keywords=rs232) to your application class path. See [this answer](http://stackoverflow.com/questions/21568729/do-you-know-an-alternative-site-for-rxtx-download) on how to get rxtxComm. – Michael Roland Apr 08 '14 at 08:02
  • i add rxtxComm library but now have this error---> CommPortIdentifier:static initialization() RXTXCommDriver {} Have not implemented native_psmisc_report_owner(PortName)); in CommPortIdentifier java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver Exception in thread "main" com.caen.RFIDLibrary.CAENRFIDException: @ No RS232 native support (install rxtxComm driver?) at com.caen.RFIDLibrary.CAENRFIDReader.Connect(CAENRFIDReader.java:3303) at com.caen.RFIDLibrary.reader_com.main(reader_com.java:12) – user3386169 Apr 08 '14 at 19:55
  • Have you followed [these instructions](http://www.caenrfid.it/en/faq.jsp?Id=9&keywords=rs232)? If yes, are you using a 32 bit version of Java? – Michael Roland Apr 08 '14 at 20:14
  • Have you tried to use different versions of the rxtxSerial library? E.g. the one included [here](http://code.google.com/p/serialcommx/). – Michael Roland Apr 10 '14 at 15:39