rxtx problem, please help!

J

joshua

Hello!

So I am trying to access a virtual serial port using the rxtx
library. I enumerate the ports, and loop through them attempting to
open each one. Although the portId.isCurrentlyOwned() returns false,
portId.open() still throws a PortInUseException, and when I call
portId.getCurrentOwner(), it returns null.

Here is relevant code:

portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {
portId = (CommPortIdentifier)portList.nextElement();

/* only iterate through serial ports */
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

/* attempt to open the port */
try {
if (portId.isCurrentlyOwned()) {
System.out.println(portId.getName() + " is owned");
} else {
System.out.println(portId.getName() + " is not
owned");
}
serialPort = (SerialPort)portId.open("Square2Plus",
2000);
} catch (PortInUseException e) {
//if the port is unavailable, move to the next one
System.out.println(portId.getName() + " is owned by " +
portId.getCurrentOwner());
continue;
}
}
}

if(portOpen) {
System.out.println(portId.getName() + "is open!");
serialPort.close();
} else {
System.out.println("port not found");
}


Running this code produces:

COM3 is not owned
COM3 is owned by null
COM5 is not owned
COM5 is owned by null
port not found

So if the ports aren't owned, why is it throwing this exception, and
what can I do about it?

Please and thank you all so much!
Joshua
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top