How to scan for COM ports in C#?

前端 未结 3 829
梦谈多话
梦谈多话 2021-02-14 07:19

Does C# provide an effective means of scanning the available COM ports? I would like to have a dropdown list in my application wherein the user can select one of the detected C

3条回答
  •  没有蜡笔的小新
    2021-02-14 07:27

    System.IO.Ports is the namespace you want.

    SerialPort.GetPortNames will list all serial COM ports.

    Unfortunately, parallel ports are not supported directly from C#, as they're very infrequently used except in legacy situations. That said, you can list them by querying the following registry key:

    HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS
    

    See the Microsoft.Win32 namespace for details.

提交回复
热议问题