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

sraposo
Posts: 21
Joined: Mon Dec 14, 2020 4:42 pm

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

Postby sraposo » Fri Oct 18, 2024 11:01 am

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?
Last edited by sraposo on Sat Oct 19, 2024 11:51 am, edited 1 time in total.

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Fri Oct 18, 2024 12:01 pm

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.

sraposo
Posts: 21
Joined: Mon Dec 14, 2020 4:42 pm

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

Postby sraposo » Fri Oct 18, 2024 1:42 pm

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?

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Sat Oct 19, 2024 11:03 am

Yes, thats exactly what i am mean.
How to do it? I dont know, it all depends how you are creating your application.

sraposo
Posts: 21
Joined: Mon Dec 14, 2020 4:42 pm

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

Postby sraposo » Sat Oct 19, 2024 11:49 am

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.

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Sat Oct 19, 2024 12:34 pm

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.

horace99
Posts: 12
Joined: Mon Oct 14, 2024 10:38 am

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

Postby horace99 » 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")

sraposo
Posts: 21
Joined: Mon Dec 14, 2020 4:42 pm

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

Postby sraposo » Sat Oct 19, 2024 2:17 pm

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!

horace99
Posts: 12
Joined: Mon Oct 14, 2024 10:38 am

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

Postby horace99 » Sun Oct 20, 2024 5:02 am

what software are you running on the PC?
how do you tell it which COM port to use?

nopnop2002
Posts: 111
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

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

Postby nopnop2002 » Sun Oct 20, 2024 6:18 am

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

Who is online

Users browsing this forum: No registered users and 139 guests