Commportidentifier.Getportidentifiers with Zero Ports on Linux

CommPortIdentifier.getPortIdentifiers with zero ports on Linux

It was just becouse low priviligies. I had to add myself to a group which is supposed to work with ttyS0.

CommPortIdentifier.getPortIdentifiers is empty

Make sure that win32com.dll (comes with javax.com) is in the jre\bin directory.
Make sure javax.comm.properties (comes with javax.com) is in the jdk\lib directory.

RXTX can't list port on ubuntu

You need to have the .so file on your class-path as well.

You can download the pre-built binaries from http://rxtx.qbang.org/wiki/index.php/Download unfortunately they are only available in 32-bit.

If your using Eclipse you can just drop the .so files in the root of your project and it should work. If that doesn't work you could try setting the java.library.path VM argument. Instructions for that are available at How to set the java.library.path from Eclipse

RXTX getPortIdentifiers() stuck

How do you scan for available ports?

For instance, the code below will return string list of available serial ports:

public List<String> getAvailablePorts() {

List<String> list = new ArrayList<String>();

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
list.add(portId.getName());
}
}

return list;
}

Edit: since actual solution is digged in comments, I add it here:

It appears that commPortIdentifier.getPortIdentifier(portName) indeed does port rescan under certain circumstances; fast workaround is to set fixed port list manually via gnu.io.rxtx.SerialPorts system property.

Serial Port accessing code for linux platform

After a bit struggles, I got the code running.

One mistake I made was using RxTx 2.2 library for Fedora 13. It uses 2.2 version of libSerial and libParellal files and 2.1 RxTxComm jar file. When I removed it and used RxTx2.1 I got an error like following.

gnu.io.RXTXCommDriver cannot be cast to javax.comm.CommDriver

While checking for this error, I found the second mistake I made and solution for the above problem. I was using RxTx Driver with java Comm API. Actually the required class files in Java Comm API is already available in the RxTx library with in "gnu.io" package.

So I changed all the javax.comm.* packages to gnu.io.*. Now I can run the application without any error.



Related Topics



Leave a reply



Submit