I have recently purchased a USB Bar code scanner. It has 3 different interface selection options:
- RS-232C
- USB
- Wand Emulation
The requirement is only to receive the scanned bar-code using RS-232C interface with the help of Java (Rxtx API). So as far as I know, I will need a COM Port to be defined in RXTX to start interaction with the device
But the problem is I am not able to find out its COM Port while using in RS-232C interface.
Is there anything that I am missing while communicating a RS-232C port, How can I find the port number.
Please help me in this.
Update: As suggested I scanned my system for all the serial ports using the code below(using JSSC)
import jssc.SerialPortList;
public class Main {
public static void main(String[] args) {
String[] portNames = SerialPortList.getPortNames();
for(int i = 0; i < portNames.length; i++){
System.out.println(portNames[i]);
}
}
}
One thing to note: when I connect my barcode scanner and remove the scanner, there is no change in the port list obtained by the above code.
Output: COM3 COM11 COM18 COM32 COM33 COM34 COM35 COM36 COM37 COM38 COM39 COM40 COM42 COM45 COM52 COM53 COM59 COM60 COM61 COM62 COM63
After the output I tried to listen each of the above port one by one using the following code:
import jssc.SerialPort; import jssc.SerialPortException;
public class Main {
public static void main(String[] args) {
SerialPort serialPort = new SerialPort("COM63"); //manually setting all the ports above one by one
try {
serialPort.openPort();//Open serial port
byte[] buffer = serialPort.readBytes(10);
System.out.println(buffer.toString());
serialPort.closePort();//Close serial port
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
}
I got either the port is busy or no output (In the meanwhile I kept on scanning using my barcode scanner)