Reputation: 816
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.
Upvotes: 1
Views: 5541
Reputation: 1682
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
Upvotes: 0
Reputation: 6183
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();
Upvotes: 2
Reputation: 2975
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
Upvotes: 0