java-native / jssc

Java library for talking to serial ports (with added build support for maven, cmake, MSVC)
https://discord.gg/RBsUfE9sX9
GNU Lesser General Public License v3.0
164 stars 53 forks source link

Cannot list COM Ports #170

Open nsiatras opened 1 month ago

nsiatras commented 1 month ago

Hello,

I am using String[] serialPorts = SerialPortList.getPortNames(); to get a list of the COM ports of the computer. This method works correctly and always returns the available COM ports of the PC.

Today I tested my software on a Lenovo desktop computer running Windows 10 and the result was missing a Port. The computer had an ESP32 Node MCU connected to COM11 but the result was missing that port. In fact the result was an array containing COM1. In COM1 there was an other USB device.

The ESP32 is connected correctly to the computer and I can send and receive data from it.

Have you ever noticed this problem again ?

PS. I have tested the software on multiple computers (desktops,laptops) including Windows, MacOS and Linux, even on Raspberry Pi and it works correctly

tresf commented 1 month ago

Have you ever noticed this problem again ?

No. I assume rebooting the computer didn't fix it either?

The native code is here:

https://github.com/java-native/jssc/blob/8dd99a4e6a945b29db4709ffd4dcdf80770068de/src/main/cpp/windows/jssc.cpp#L644-L688

nsiatras commented 1 month ago

Correct. We also formatted and re-installed windows with the same results

On Tue, Aug 6, 2024, 9:06 PM Tres Finocchiaro @.***> wrote:

Have you ever noticed this problem again ?

No. I assume rebooting the computer didn't fix it either?

The native code is here:

https://github.com/java-native/jssc/blob/8dd99a4e6a945b29db4709ffd4dcdf80770068de/src/main/cpp/windows/jssc.cpp#L644-L688

— Reply to this email directly, view it on GitHub https://github.com/java-native/jssc/issues/170#issuecomment-2271856135, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABN6V3VFBS2UDCHMUVSBEJTZQEGAXAVCNFSM6AAAAABMCYYCS6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZRHA2TMMJTGU . You are receiving this because you authored the thread.Message ID: @.***>

nsiatras commented 1 month ago

Well... the issue in my case are the drivers.

With the 11.3.0.176 (13-Apr-23) drivers for the CP210x USB to UART the port can be listed. but with the 11.4.0.317 (19-Jul-24) version for the drivers the port cannot be listed... Drivers

nsiatras commented 1 month ago

Better Issue Description: We recently upgraded the Windows version of the CP210x USB to UART Bridge drivers from version 11.3.0.176 to 11.4.0.317 Link to drivers: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads

After the drivers update we are not able to correctly list the COM ports of the computer using the Java jssc To be more specific after calling the String[] serialPorts = SerialPortList.getPortNames(); the result is an empty array.

The serial communication with the device works correctly the only problem is that the COM port cannot be listed.

tresf commented 1 month ago

@nsiatras,

@hiddenalpha has kindly provided a potential patch here: #171 can you test it? Here's a compile from my machine:

jssc-2.9.7-SNAPSHOT.jar.zip

nsiatras commented 1 month ago

Hello,

I get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/scijava/nativelib/JniExtractor
    at jssc.SerialPortList.<clinit>(SerialPortList.java:49)

Caused by: java.lang.ClassNotFoundException: org.scijava.nativelib.JniExtractor
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    ... 29 more
tresf commented 1 month ago

Hello,

I get the following exception:

Sorry, the build is missing this dependency. I'll try to make a fat jar containing this...

tresf commented 1 month ago

@nsiatras OK, this one should have the scijava dependencies included, can you please test?

jssc-2.9.7-SNAPSHOT.jar.zip

nsiatras commented 1 month ago

I just tested the snapshot. No exceptions on this one and data exchange works 100% correct but I still cannot list the COM ports correctly.

pietrygamat commented 1 month ago

@nsiatras you may want to check that the driver parameter SerialSkipExternalNaming is not set in your Windows machine

regedt -> Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\silabser\Parameters

and if it is - remove the key, then reboot the PC (or at least reconnect the device). image

source

SETUP REGISTRY KEY
------------------
Registry keys are used for setting some parameters of the serial port
For setting these parameters, we have 2 ways:
    - Modify registry value using registry editor of Windows
    - Modify registry value using INF file
The detail of each method as following.
### Modify registry value using registry editor of Windows ###

1. Edit the file UpdateParameters.reg according to your settings, save the file.
   Registry keys are allocated at 3 position:
   - Parameters keys: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\silabser
   - Software keys:   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\<ClassID>\
   - Hardware keys:   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\deviceID\
2. Right-click to UpdateParam.bat -> run as administrator, then your settings have been updated.
3. Restart you computer.
nsiatras commented 1 month ago

Hello,

I reported this issue on the SiliconLabs forum and I just get the following reply:

"*This behavior might be affected by some changes in the new VCP 11.4 driver. The Old VCP 11.3 will be back on the website for downloading.

I will let you know if I have any updates on it. Again, Thanks for your information*"

https://community.silabs.com/s/question/0D7Vm000003SrZ7KAK/detail?language=en_US

PS. I have not edit the registry yet, in order to test again. I will do so later today