Reputation: 5386
I'm writing a java program, and right now I have a setup-file which contains a COM port number. which has to be changed if the device changes COM port number.
This is not very user friendly. Therefore I want to be able to get a list of COM port ID's and let the user select the right device by its ID. I've tried googling, but without much success.
By ID I mean if you check the Device Manager: "COM Port ID (COM<#>)". Check the with red marked text seen in the following picture:
I have tried the following libraries:
But I have been unable to find out if it is possible to get the COM port ID, as the two above methods just return the number of the COM Port. Does anyone know of a way to get the COM port IDs?
Upvotes: 3
Views: 4056
Reputation: 837
I used rxtxcomm.jar and rxtxSerial.dll to communicate with an Arduino. This snippet should get you the available ports:
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = portEnum.nextElement();
System.out.println(currPortId.getName() + " - " + currPortId.getCurrentOwner());
}
Here's an article with some further details: https://blog.henrypoon.com/blog/2010/12/25/installing-rxtx-for-serial-communication-with-java/
Upvotes: 2