Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

javax.comm - getPortIdentifiers(); works only once..... need help

807589Nov 30 2004 — edited Sep 11 2008
Hi, I have a program which reads from a virtual comm port on windowsXP. At the beginning, the program lists all the serial ports on the system and asks the user to choose one. I have a "refresh" button - which should re-list the ports by calling CommPortIdentifier.getPortIdentifiers(); again. I need the refresh button because the virtual comm port only appears if my external device is plugged in.

Here's my "refresh" method:

CommPortIdentifier portId;
Enumeration portList = CommPortIdentifier.getPortIdentifiers();

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

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println(portId.getName());
}

}


The problem is that the first time I call this, it lists all the ports including the virtual one. However, if the virtual port then disappears (device unplugged) and I call refresh again - the list still shows the virtual port. If I close my java program and reopen it, the call to getPortIdentifiers() now reflects the actual state of the system - no virtual port. How can I get getPortIdentifiers() to return an up-to-date list on successive calls without having to close and reopen my app.?

Thanks for your advice
-Ben

Ps. It seems to me like CommPortIdentifiers class does something at load time that it doesn't ever redo. Is there some way to cause a class to get reloaded into the JVM?

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 9 2008
Added on Nov 30 2004
12 comments
703 views