Serial COMM port in windows remains owned after closing

点点圈 提交于 2019-12-11 23:21:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!