B4J Question COM port names

Didier9

Well-Known Member
Licensed User
Longtime User
I use this
B4X:
For Each s As String In Serial1.ListPorts
    Log(s)
    lvPorts.Items.Add( s )
Next
to enumerate the serial ports that are currently installed.
It only returns COM1, COM3 ... instead of the more useful driver names as displayed in the Device Manager.
Is there a way to obtain the actual driver name like Windows displays in the Device Manager?
 

stevel05

Expert
Licensed User
Longtime User
I found some code here: https://stackoverflow.com/questions...ort-given-its-comx-name-under-windows-in-java

That requires jna to access. Latest version is available here: https://github.com/java-native-access/jna

You need to download the jna jar and the jna-platform jar and copy them to your additional libraries folder. The java code will only work for windows.

You may need to change the references in the #AdditionalJar declarations in the main module if the jna download is a newer version.

In the attached demo app the GetAll method returns a B4x Map, converted from the Hashmap returned by the java code and seems to contain connected devices, The Get method I left so you could try it, but it only appears to return registered devices and then only if it has a friendly name (which my COM1 doesn't) so I am not sure if it will be useful or not.
 

Attachments

  • ComPortFriendly.zip
    2.4 KB · Views: 508
Last edited:
Upvote 0
Top