问题
I have a problem with comm ports in JAVA. I'm using Java version, 1.5 because that version still have access to windows COMM ports (serials).
The problem is that the command throws the exception:
javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
The thing is that the application opens the comm port for the first time, then I close the comm when the user exits some window. But the user may return to that window, and therefore I try to open again the same port:
I close with:
if (puertoSerie != null) {
puertoSerie.removeEventListener();
puertoSerie.close();
puertoSerie = null;
}
So I added a PortOwnershipListener:
idPuerto.addPortOwnershipListener(new MyResolver());
And the error says:
Somebody else has the port
Somebody else has the port
That occurs when :
case PORT_OWNERSHIP_REQUESTED:
if (owned) {
System.out.println("Owned ... Somebody else has the port");
} else {
System.out.println("Somebody else has the port");
}
Any Idea how to work around this?
Best Regards
回答1:
The new java JDK 1.7 also has serial port programming using the java.comm and rxtx api's.
You can install them and run them if you like and you can use serialPort.close(); to end the connection.
来源:https://stackoverflow.com/questions/8478873/serial-comm-port-in-windows-remains-owned-after-closing