获取错误的串行端口名称从BluetoothDevice类(C#) [英] Getting wrong serial-port names from bluetoothdevice (c#)

查看:599
本文介绍了获取错误的串行端口名称从BluetoothDevice类(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从系统我用下面的命令得到所有avaliable Serialports。

To get all avaliable Serialports from the system i use the following command.

SerialPort.GetPortNames

它工作正常的主板串行端口,但与蓝牙设备我得到了错误的port名字。

It works fine for the mainboard serial port, but with the bluetooth device i get the wrong portnames.

例如:COM7而是我有时会COM70或COM7ö。它总是1个字母来得多。

For Example: Instead of COM7 i get sometimes COM70 or COM7ö. Its always 1 letter to much.

任何suggestens?

any suggestens?

PS:我使用最新的Visual Studio前preSS在Windows 7
PPS:肮脏的劈切的最后一个字母没有工作,因为我不知道哪一个是蓝牙串行端口(与各种bluetoothstick或设备它改变了COMPORT的数量),并尝试不同的棍棒我到达后COM10, ERGO COM100或COM10f

PS: I am using newest Visual Studio Express in Windows 7 PPS: The dirty hack to cut the last letter didn't work because i don't know which one is the bluetooth serial port (with various bluetoothstick or devices it changes the number of the comport) and after trying various sticks i reached COM10, ergo COM100 or COM10f

编辑:code我使用的现在。阅读regestry,但还是同样的问题。

the code i am using right now. reading the regestry, but still the same problem.

RegistryKey myRegistry = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
foreach (string valuename in myRegistry.GetValueNames())
{
    if (myRegistry.GetValue(valuename) is String)
    {
        if (valuename.Contains("BthModem"))
        {
            richTextBox1.AppendText(">" + myRegistry.GetValue(valuename) + "<" + Environment.NewLine);
        }
    }
} 

一般情况下,第二个或第三个请求正在与结果如

Normally the second or third request is working with a result like

&COM11ᯋLT;
  COM10S&LT;
  COM11&LT;
  COM10&LT;
  COM11&LT;
  COM10&LT;

COM11ᯋ< COM10S< COM11< COM10< COM11< COM10<

怎么可能呢?

推荐答案

这已经的报告错误与非空结尾的字符串:

This has been reported as a bug with non-null terminated strings:

您可以手动走注册表?

HKLM\Hardware\DeviceMap\SerialComm

这篇关于获取错误的串行端口名称从BluetoothDevice类(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆