Obtener la descripción de un dispositivo COM

I've been reading a lot of posts on SO about this but all of them are either in C# or MFC. I'm using the normal windows libraries and not the MFC shared libraries nor ATL.

I can easily enumerate the available COM ports but I don't know how to obtain the description as, for example, seen in the Device Manager within Windows. I've been reading through the MSDN and the closest I've come is SetupDiGetDeviceRegistryProperty() but I'd imagine there must be a quick way to do this. I've also found that Qt has QextSerialEnumerator::getPorts() but since I'm not using Qt I was hoping there would be something similar available from the WinAPI.

If someone has a snippet for doing so it would be greatly appreciated.

preguntado el 08 de noviembre de 11 a las 15:11

Thank you but again, I'm not using C# or any .NET for that matter. I know C# has some really simplified and easy-to-use static classes for the port description and all other information but I can't use this because I'm not using that language. -

The quick way is SetupDiGetDeviceRegistryProperty(), with the SPDRP_FRIENDLYNAME property. -

2 Respuestas

First of all, what kind of description are you really need? You can obtain different info about COM-ports by EnumPorts() & Registry-way. For example, registry-way will show virtual COM-port - this one EnumPorts can't do. The second thing - there is 9 different ways of enumerating COM-ports. The examples of their usage is here - http://www.naughter.com/enumser.html (i've used some code from here in my project). Also, note that the author use many msvc-specific features - atl containers for memory allocating and etc.

Respondido el 04 de junio de 20 a las 13:06

I've looked at the code from enumser already but it is really MSVC specific with ATL, like you said. The description I want it the one you see when you check the properties of any device in the device manager and look at Description. For my arduino, for example, it says "Arduino UNO". - Yonathan

I've also looked in the registry but this will say //device/bla and not the description the device has. - Yonathan

ATL containers are used here, in general, only for memory allocating. I have replaced them successfuly with "new" because i don't really like to use ATL. - Roman Kr

and registry-way can obtain whole information about registry key that you can see in regedit. I don't really know how to get an arduino name, but i know exactly that in enumser output of methods reduced to COM ID. If you modify enumser a little, you will got what you want. - Roman Kr

I've obtained the name from the registry but this is not the name from the device manager. I've been looking at enumser for a while now but it is really dependent on MFC classes. - Yonathan

All i can say is don't use the setupDI WDM functions if you don't know EXACTLY what you are doing, this is way back for me but check the windows DDK samples i think the dll implementation you see in device manager is in /ports...

The issue is that serial ports are very very old, so they've been dragged through the ages and hacked together into windows 7, so for example when you make a change to a COM port then you have to write to win.ini, but win.ini doesn't exist (wtf i hear you say) that's because any "changes" get bounced back into the registry.

Any how, good luck..

respondido 08 nov., 11:19

Yeah I've been reading up on it and indeed it seems that its a bit of an issue regarding to this. But however, for what I'm trying to achieve ( a simplified serial-port communication library ) I am in need of their properties. Basically I'm trying to build a list of the com devices including description so a user can select one from a dropdown menu. - Yonathan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.