1

I have a requirement where i have to read data streams coming on serial port. I am using javax.comm API for same.

When I try to list ports, using below code I never get any port list.

portList = CommPortIdentifier.getPortIdentifiers();
System.out.println("start: "+portList.hasMoreElements());

It returns false.

Can anyone help me if I am missing anything?


My PS2 port didn't came in list. Is there any other way to list PS2 port??

My full code is as below,

    while (portList.hasMoreElements()) {
       portId = (CommPortIdentifier) portList.nextElement();
       System.out.println("portid: "+portId.getName());
    }

output

portid: COM1
portid: COM3
portid: LPT1

My actual requirement is to read data on USB port. I was facing issues using JUSB and it didn't work. So I decided to get serial to USb converter and read on serial port. But, there is no such convertable available in market.

Now, thinking of another work around I was able to get a PS2 to usb converter. It would be great if you could help me listing PS2 port using Java and read/write to it or suggest some API for same on windows platform.

Any help in this regard is highly appreciated.

Mayank
  • 796
  • 1
  • 10
  • 12
  • which javax.comm library you are using and what is your system? I am using rxtx and it works well. – Salil Jun 29 '12 at 08:07
  • I am also using rxtx and it worked for me too. The thing missing was configuration in eclipse related to .dll file as explained in link below, http://www.intellog.com/blog/?p=255 – Mayank Jun 29 '12 at 08:35

3 Answers3

2

Take a look at RXTX. Then you can use something like that:

 CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/tty1");
 CommPort commPort = portIdentifier.open("owner-name", 2000);
 SerialPort serialport;
 if (commPort instanceof SerialPort) {
   serialPort = (SerialPort)commPort;
   serialPort.setSerialPortParams(rate, databits, stopbits, parity);
 }
 InputStream in = serialPort.getInputStream();
 OutputStream out = serialPort.getOutputStream(); 
Ortwin Angermeier
  • 5,957
  • 2
  • 34
  • 34
0

Please see: http://www.intellog.com/blog/?p=255 and http://www.coderanch.com/t/535173/Streams/java/CommPortIdentifier-getPortIdentifiers-empty (the latter points to the first)

Oracle does not offer the binaries for windows (assuming that you're on windows): http://www.oracle.com/technetwork/java/index-jsp-141752.html

heikkim
  • 2,955
  • 2
  • 24
  • 34
0

I'm using ubuntu and my computer does not have any serial/pararel port but I need to develop on it.

You need to simulate this ports in this case.

My answer:

serial port identification with java on ubuntu

Community
  • 1
  • 1
Marcelo Amorim
  • 1,662
  • 23
  • 23