0

I have recently purchased a USB Bar code scanner. It has 3 different interface selection options:

  1. RS-232C
  2. USB
  3. 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)

Deepak
  • 335
  • 1
  • 7
  • 21

2 Answers2

0

Here's a solution posted elsewhere on StackOverflow. Basically you need to cycle your available comports from your OS and display/select the intended one. If you're having trouble with this please post some code for us to review.

Community
  • 1
  • 1
Grambot
  • 4,370
  • 5
  • 28
  • 43
  • Well your code looks good from reviewing the jSSC documentation. Let's work backwards a bit. When you attach your barcode scanner to the PC are you able to detect what COM port it is using from a Device Manager? Are you on Windows/Linux/Mac? The barcode scanner I have plugged in currently gets recognized by my OS as a Keyboard Device and not a serial device. – Grambot Nov 05 '12 at 19:29
  • I am using windows and Yes you are right, in my computer also barcode scanner is recognized as keyboard i.e. its default interface, however I want to set the interface as RS-232C(Fortunately my device can switch to this interface) as need to develop some java application using that. and as soon as I switch its interface, device manager does not show it under Keyboard or COM sections – Deepak Nov 05 '12 at 20:44
0

I'm unfamiliar with those APIs, but fairly familiar with the electrical end of the COM port. There is no automatic "handshake" that indicates whether a device is attached or not, unlike a USB port. However, there are several status lines that are present in the interface.

In addition to the TD/RD signals (transmitted data/received data) there are RTS/CTS -- Request To Send and Clear To Send. RTS and CTS are such that they go "not ready" when nothing is connected.

The usual protocol is that the device asserts RTS and then the other end returns CTS to indicate that everything is ready. However, this is all complicated by the fact that the computer can appear as either a "device" or a "modem" (the only two things that RS-232 knows about). The result is that you can have several different configurations of pins and signals, depending on the assumed modes of the two pieces. (If you're lucky the scanner docs describe some of this.)

Further complicating things is that there are DSR/DTR signals -- Data Set (Modem) Ready and Data Terminal Ready. In most PC configurations these are ignored, but not always.

So, if you don't have luck soon with your scanning you may have to look at the pinouts and use a voltmeter and some jumpers to set you're physical port in a state that the scanner will find. Then there will be further experimentation to determine how to set up the status signals to get the scanner to talk.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • You are absolutely correct as I am also aware of the RS port working. My barcode scanner is a USB based device that means it does not has actual RS-232C plug. The thing is the manufacture has provided the interface switching functionality at the software level so that usb can work as RS232 also. But the issue is how one can identify that a RS232 device is using a particular port because only after that we can send RTS or CTS command to that device (please correct me if I am wrong) – Deepak Nov 05 '12 at 20:51
  • @Deepak -- Yep, it may be the old rock/hard place thing. One thought: Have you used Device Manager to display attached USB devices? At one time that would tell you what COM port was being used, though I don't know about the latest versions of Windows. – Hot Licks Nov 05 '12 at 21:33
  • yes as I have also updated the question "programmatically I got all the serial ports in my system and there is no change in these serial ports when I plug or remove the Scanner" i.e. a pretty strange thing – Deepak Nov 06 '12 at 05:12
  • My point is that it used to be, on W98, that when you plugged in a USB device the path to it could be seen in Device Manager, and if you followed the path it would tell you which COM port the specific USB device installed as. With Vista that changed, unfortunately, but it may have been restored with 7 or 8. If the function is working on your version of Windows you can see which USB device appears when you plug it in, and follow that to the device properties and COM port info. – Hot Licks Nov 06 '12 at 11:58
  • (Can you see the device at all on Device Manager when you plug it in?) – Hot Licks Nov 06 '12 at 12:00
  • That is the problem, I am unable to detect the device when switched to Rs232C interface in device manager. I am using Win7 – Deepak Nov 07 '12 at 05:14
  • I'm wondering if Windows is detecting the device at all. Does it make the "doo-deep" sound? Does Windows say "loading driver" or some such? – Hot Licks Nov 07 '12 at 12:58
  • @Deepak -- So probably there's a problem with the scanner being recognized by the computer at all. Have you tried it in USB mode, just to see if it beeps and loads a driver? – Hot Licks Nov 07 '12 at 18:41
  • yes in USB Mode it loads driver and work as a keyboard. Also I am able to see a additional USB input device & Keyboard in Device manager – Deepak Nov 08 '12 at 10:00