Page 1 of 2

Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Fri Oct 18, 2024 11:01 am
by sraposo
Hi!

My current project ESP32-S3 uses CDC and it's working properly.

But the only way to know the number assigned to the COM port (example: COM10) is referring to the device manager, what makes it inconvenient to a remote application that intends to be fully user-independent.

So, the question is: is there a way to programmatically get the number assigned to the COM or to specify the desired number during CDC setup time?

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Fri Oct 18, 2024 12:01 pm
by chegewara
Hi, there is no way to find out, unless you can check in your app VID and PID of each USB device connected and filter it.

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Fri Oct 18, 2024 1:42 pm
by sraposo
If I get you right, it would be enough to receive (part of) descriptor of the current USB devices attached to the PC!
How can I do it?

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sat Oct 19, 2024 11:03 am
by chegewara
Yes, thats exactly what i am mean.
How to do it? I dont know, it all depends how you are creating your application.

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sat Oct 19, 2024 11:49 am
by sraposo
This COM port number is likely assigned by Windows, exclusively.
I could not find any data structure in TinyUSB that contains an obvious, nor intuitive, reference to this.

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sat Oct 19, 2024 12:34 pm
by chegewara
sraposo wrote: This COM port number is likely assigned by Windows, exclusively.
I could not find any data structure in TinyUSB that contains an obvious, nor intuitive, reference to this.
Thats true. Do, like i mentioned, you have to get somehow VID and PID on windows and then select the port which match your esp32 device.
Im pretty sure you can do it with command line script, for sure with windows app if you build one etc.
You can also filter by name, since your device will have device name string descriptor. But all of this is a windows related problem.

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sat Oct 19, 2024 12:47 pm
by horace99
when connecting microcontrollers to PCs where the Windows COM port or Linux /dev/ttyUSB* port is unknown I usually have the host software (implemented in C++, C#, Java, etc) cycle thru the connected serial ports transmitting a prompt (e.g. a "?") to each device in turn
the target device would be programmed to respond with a specific acknowledgement (e.g. "ESP32 Klystron simulator")

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sat Oct 19, 2024 2:17 pm
by sraposo
horace99 wrote:
Sat Oct 19, 2024 12:47 pm
when connecting microcontrollers to PCs where the Windows COM port or Linux /dev/ttyUSB* port is unknown I usually have the host software (implemented in C++, C#, Java, etc) cycle thru the connected serial ports transmitting a prompt (e.g. a "?") to each device in turn
the target device would be programmed to respond with a specific acknowledgement (e.g. "ESP32 Klystron simulator")
I see, but I can't depend on some resident sw running on PC to help on this... I mean, it's not a option for while...

Thanks for your suggestion!

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sun Oct 20, 2024 5:02 am
by horace99
what software are you running on the PC?
how do you tell it which COM port to use?

Re: Is there a way to get the number assigned to a COM port emulated by CDC?

Posted: Sun Oct 20, 2024 6:18 am
by nopnop2002
If I get you right, it would be enough to receive (part of) descriptor of the current USB devices attached to the PC!
How can I do it?
Some languages ​​have APIs to get USB's hwid and USB's vid.
This is hwid and vid of ESP32's CDC port.

Code: Select all

device=COM24
hwid=USB VID:PID=303A:4001 SER=8
vid=12346