Skip to content

Cannot list COM Ports #170

Closed
Closed

Description

@nsiatras

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

Activity

  1. tresf commented on Aug 6, 2024

    @tresf

    Have you ever noticed this problem again ?

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

    The native code is here:

    JNIEXPORT jobjectArray JNICALL Java_jssc_SerialNativeInterface_getSerialPortNames
    (JNIEnv *env, jobject){
    HKEY phkResult;
    LPCSTR lpSubKey = "HARDWARE\\DEVICEMAP\\SERIALCOMM\\";
    jobjectArray returnArray = NULL;
    if(RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, &phkResult) == ERROR_SUCCESS){
    boolean hasMoreElements = true;
    DWORD keysCount = 0;
    char valueName[256];
    DWORD valueNameSize;
    DWORD enumResult;
    while(hasMoreElements){
    valueNameSize = 256;
    enumResult = RegEnumValueA(phkResult, keysCount, valueName, &valueNameSize, NULL, NULL, NULL, NULL);
    if(enumResult == ERROR_SUCCESS){
    keysCount++;
    }
    else if(enumResult == ERROR_NO_MORE_ITEMS){
    hasMoreElements = false;
    }
    else {
    hasMoreElements = false;
    }
    }
    if(keysCount > 0){
    jclass stringClass = env->FindClass("java/lang/String");
    returnArray = env->NewObjectArray((jsize)keysCount, stringClass, NULL);
    char lpValueName[256];
    DWORD lpcchValueName;
    byte lpData[256];
    DWORD lpcbData;
    DWORD result;
    for(DWORD i = 0; i < keysCount; i++){
    lpcchValueName = 256;
    lpcbData = 256;
    result = RegEnumValueA(phkResult, i, lpValueName, &lpcchValueName, NULL, NULL, lpData, &lpcbData);
    if(result == ERROR_SUCCESS){
    env->SetObjectArrayElement(returnArray, i, env->NewStringUTF((char*)lpData));
    }
    }
    }
    CloseHandle(phkResult);
    }
    return returnArray;
    }

  2. nsiatras commented on Aug 6, 2024

    @nsiatras
    Author
  3. nsiatras commented on Aug 7, 2024

    @nsiatras
    Author

    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

  4. nsiatras commented on Aug 7, 2024

    @nsiatras
    Author

    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.

  5. tresf commented on Aug 7, 2024

    @tresf

    @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

  6. nsiatras commented on Aug 8, 2024

    @nsiatras
    Author

    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
    
  7. tresf commented on Aug 8, 2024

    @tresf

    Hello,

    I get the following exception:

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

  8. tresf commented on Aug 8, 2024

    @tresf

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

    jssc-2.9.7-SNAPSHOT.jar.zip

  9. nsiatras commented on Aug 9, 2024

    @nsiatras
    Author

    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.

  10. pietrygamat commented on Aug 9, 2024

    @pietrygamat
    Collaborator

    @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.
    
  11. nsiatras commented on Aug 9, 2024

    @nsiatras
    Author

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions