110,561
社区成员
发帖
与我相关
我的任务
分享
private void GetSerialPort() //获取串口列表
{
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);
SerialToolStripMenuItem.DropDownItems.Add(sValue, null, new EventHandler(NoPorts_Click));
}
}
for (int i = 0; i < SerialToolStripMenuItem.DropDownItems.Count; i++)
{
if (SerialToolStripMenuItem.DropDownItems[i].Text == VariableLib.portName)
{
((ToolStripMenuItem)(SerialToolStripMenuItem.DropDownItems[i])).Checked = true;
SerialToolStripStatusLabel.Text = ((ToolStripMenuItem)(SerialToolStripMenuItem.DropDownItems[i])).Text;
}
}
}
string[] ports = System.IO.Ports.SerialPort.GetPortNames();