Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot list COM Ports #170

Open
nsiatras opened this issue Aug 6, 2024 · 11 comments · May be fixed by #171
Open

Cannot list COM Ports #170

nsiatras opened this issue Aug 6, 2024 · 11 comments · May be fixed by #171

Comments

@nsiatras
Copy link

nsiatras commented Aug 6, 2024

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
Copy link

tresf commented Aug 6, 2024

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;
}

@nsiatras
Copy link
Author

nsiatras commented Aug 6, 2024 via email

@hiddenalpha hiddenalpha linked a pull request Aug 6, 2024 that will close this issue
@nsiatras
Copy link
Author

nsiatras commented Aug 7, 2024

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
Copy link
Author

nsiatras commented Aug 7, 2024

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
Copy link

tresf commented Aug 7, 2024

@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
Copy link
Author

nsiatras commented Aug 8, 2024

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
Copy link

tresf commented Aug 8, 2024

Hello,

I get the following exception:

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

@tresf
Copy link

tresf commented Aug 8, 2024

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

jssc-2.9.7-SNAPSHOT.jar.zip

@nsiatras
Copy link
Author

nsiatras commented Aug 9, 2024

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
Copy link
Collaborator

pietrygamat commented Aug 9, 2024

@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
Copy link
Author

nsiatras commented Aug 9, 2024

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants