您的位置:首页 > 编程语言 > C#

C#获取串口列表(可用于实现实时监控串口)

2011-02-25 12:32 363 查看
常用的两种方法
方法一:
view plaincopy to clipboardprint?
using Microsoft.Win32;

RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
if (keyCom != null)
{
string[] sSubKeys = keyCom.GetValueNames();
foreach (string sName in sSubKeys)
{
string sValue = (string)keyCom.GetValue(sName);
this.textBox1.Text = this.textBox1.Text + sValue + "\r\n";
}
}
using Microsoft.Win32;
RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
if (keyCom != null)
{
string[] sSubKeys = keyCom.GetValueNames();
foreach (string sName in sSubKeys)
{
string sValue = (string)keyCom.GetValue(sName);
this.textBox1.Text = this.textBox1.Text + sValue + "\r\n";
}
}
方法二:
view plaincopy to clipboardprint?
using System.IO.Ports;

foreach (string vPortName in SerialPort.GetPortNames())
{
this.textBox2.Text = this.textBox2.Text + vPortName + "\r\n";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: