获取串口信息 [英] Getting Serial Port Information

查看:33
本文介绍了获取串口信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以将串行端口加载到组合框中:

I have some code that loads the serial ports into a combo-box:

     List<String> tList = new List<String>(); 

     comboBoxComPort.Items.Clear();

     foreach (string s in SerialPort.GetPortNames())
     {
        tList.Add(s);
     }

     tList.Sort();
     comboBoxComPort.Items.Add("Select COM port...");
     comboBoxComPort.Items.AddRange(tList.ToArray());
     comboBoxComPort.SelectedIndex = 0;

我想将端口描述(类似于设备管理器中为COM端口显示的内容)添加到列表并对列表中索引0之后的项目进行排序(已解决:见上面的片段).有没有人对添加端口描述有任何建议?我使用的是 Microsoft Visual C# 2008 Express Edition (.NET 2.0).您的任何想法将不胜感激.谢谢.

I would like to add the port descriptions (similar to what are shown for the COM ports in the Device Manager) to the list and sort the items in the list that are after index 0 (solved: see above snippet). Does anyone have any suggestions for adding the port descriptions? I am using Microsoft Visual C# 2008 Express Edition (.NET 2.0). Any thoughts you may have would be appreciated. Thanks.

推荐答案

有一个在 MSDN 上发布关于相同问题的帖子:

在 C# 中获取有关串行端口的更多信息

Ravenb,

我们无法通过 SerialPort 类型获取信息.我不知道为什么您的应用程序中需要此信息.但是,有一个 已解决的线程 和你有同样的问题.您可以查看那里的代码,看看它是否可以帮助您.

We can't get the information through the SerialPort type. I don't know why you need this info in your application. However, there's a solved thread with the same question as you. You can check out the code there, and see if it can help you.

如果您有任何其他问题,请随时告诉我.

If you have any further problem, please feel free to let me know.

最好的问候,周小龙

那篇文章中的链接指向这个:

The link in that post goes to this one:

如何使用 System.IO.Ports.SerialPort 获取有关端口的更多信息

您可能可以从 WMI 查询中获取此信息.查看这个工具 帮助您找到正确的代码.你为什么会在意?这只是 USB 仿真器的一个细节,普通的串口不会有这个.串口仅通过COMx"识别,仅此而已.

You can probably get this info from a WMI query. Check out this tool to help you find the right code. Why would you care though? This is just a detail for a USB emulator, normal serial ports won't have this. A serial port is simply know by "COMx", nothing more.

这篇关于获取串口信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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