Serial port enumeration in Delphi using SetupDiGetClassDevs

前端 未结 5 793
情书的邮戳
情书的邮戳 2021-01-01 04:32

I\'m trying to enumerate \"friendly names\" for COM ports. The ports may dynamically change as USB-serial devices are connected and disconnected at runtime.

Based on

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 05:08

    For easier operation you might consider simply using the registry where those names are listed eg:

      ErrCode := RegOpenKeyEx(
        HKEY_LOCAL_MACHINE,
        'HARDWARE\DEVICEMAP\SERIALCOMM',
        0,
        KEY_READ,
        KeyHandle);
    

    (I've ommited the hand-waving stuff).

    You might also consider using WMI - see this example from Magenta Systems - you can get a pretty much everything hardware-related now.

提交回复
热议问题