如何从 C# 程序识别哪些 COM 端口连接到蓝牙?

发布于 2024-11-07 03:37:21 字数 180 浏览 9 评论 0原文

如何从 C# 程序识别哪些 COM 端口连接到蓝牙?

这是我的要求。让我们假设我的计算机中的 COM 端口连接到各种设备。假设我们有 COM 端口 1 到 9,并且目前已连接 2、3、4、5 和 7。现在我需要确定端口2、3、4、5和7中哪些端口连接了蓝牙设备?

我需要使用 C# 程序来完成此操作。有什么建议吗?

How to identify which COM ports are connected to BlueTooth from a C# Program?

Here is my requirement. Let us assume the COM ports in my computer are connected to various devices. Let's say we have COM ports 1 through 9, and 2, 3, 4, 5, and 7 are connected at the moment. Now I need to identify, among ports 2, 3, 4, 5 and 7, which ports are connected to BlueTooth devices?

I need to do this using a C# program. Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十雾 2024-11-14 03:37:21

请参阅 http://32feet.codeplex.com/wikipage?title= Getting%20Virtual%20COM%20Port%20Names 简而言之使用WMI查看端口硬件id中的BluetoothAddress。

C:\> Get-WmiObject -query "select DeviceID,PNPDeviceID from Win32_SerialPort"
DeviceID     : COM66 
PNPDeviceID  : BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}\7&1D80ECD3&0&00803A686519_C00000003
… …

当然,我不喜欢虚拟 COM 端口,并且始终建议尽可能使用直接套接字/API 连接。 http://32feet.codeplex.com/wikipage?title=Bluetooth%20Serial%20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

See http://32feet.codeplex.com/wikipage?title=Getting%20Virtual%20COM%20Port%20Names In brief use WMI to see the BluetoothAddress in the port hardware id.

C:\> Get-WmiObject -query "select DeviceID,PNPDeviceID from Win32_SerialPort"
DeviceID     : COM66 
PNPDeviceID  : BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}\7&1D80ECD3&0&00803A686519_C00000003
… …

Of course I'm not a fan of virtual COM port and always recommend using a direct sockets/API connection where possible. http://32feet.codeplex.com/wikipage?title=Bluetooth%20Serial%20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

月牙弯弯 2024-11-14 03:37:21

您可以在注册表中查看。

string commport =(string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM",     @"\Device\BthModem0", "");

如果您有多个设备,还可以有“\Device\BthModem1”或“\Device\BthModem2”等。

You can look in the registry.

string commport =(string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM",     @"\Device\BthModem0", "");

If you have more than one device, there can also be "\Device\BthModem1" or "\Device\BthModem2" ect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文