Serial COMM port in windows remains owned after closing-Collection of common programming errors
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