串口未在Combobox中加载正确 [英] Serial Port not loading Correct in Combobox

查看:64
本文介绍了串口未在Combobox中加载正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们





我想在组合框中加载我的系统的串口号com1和com2加载正确表格,但其他像COM6COM7一样加载我没有得到什么是那个框符号后没有



这个代码我用来加载串口



Dear Friends


I am Trying To Load Serial port numbers of my system in combo box com1 and com2 are loaded in correct form but other loaded like COM6 COM7 i am not getting the what is that box Symbol after no

this Code I am using to load the serial port

string[] ports = SerialPort.GetPortNames();


            foreach (string port in ports)
            {
                cboPorts.Items.Add(port);
            }

推荐答案

您需要查看整个系统,并检查您已安装的端口 - 它会似乎他们中的一些人正在使用不正确报告名称的驱动程序 - 我们无法复制此处,因为我们无法访问您的系统。



如果可以什么都不做,然后一种隐藏问题的方法是使用regext来消除最后的垃圾。

You need to look at your system as a whole, and examine the ports you have fitted - it would seem that some of them are using drivers which report the name incorrectly - we can't duplicate that here as we do not have access to your system.

If you can't do anything about it, then one way to "hide" the problem would be to use a regext to get rid of any "rubbish" at the end.
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
    {
    string cleaned = Regex.Match(port, @"COM\d+").Value;
    cboPorts.Items.Add(cleaned);
    }


这篇关于串口未在Combobox中加载正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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