Here is the code that I am implementing for Enumeration of devices. I am able to detect and display all the Serial devices connected.But suppose I connected another device and then try to recall this function, It is always showing the devices that are connected during first run of the code.
Code Snipet:
public void Listports() {
Enumeration ports = null;
ports = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
{
while (ports.hasMoreElements()) {
portId = (CommPortIdentifier) ports.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
System.out.println(portId.getName());
}
}
}
}
i.e. For Example, in the first Call of the function , COM1 and COM3 are displayed.
Now suppose, a Serial Device connected is loaded on COM27. So If we re-run the code it is displaying only COM1 and COM3, and no COM27.
Another scenario, Before my first run of the code a Serial device is loade on COM27. Now on first run it shows COM1,COM3,COM27. Now remove the COM27 device and re-run the above piece of code, It still shows COM27 is connected.
Any Help in this regard is greatly Appreciated.
Thanks, Abhi