我正在尝试从手机发送短信到手机.第一步:让所有的COM端口使用它.我使用了这段代码,但没有任何好处:
private void Form1_Load(object sender, EventArgs e)
{
string[] Ports = SerialPort.GetPortNames();
foreach (string prt in Ports)
{
comboBox1.Items.Add(prt);
}
}
Run Code Online (Sandbox Code Playgroud)
它什么都不返回.我能做什么?
我刚刚在我的电脑上运行以下代码并返回"COM1":
string[] ports = SerialPort.GetPortNames();
Console.WriteLine("The following serial ports were found:");
foreach(string port in ports)
{
Console.WriteLine(port);
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
所以,它是权限,或者你没有任何串口.或者您的注册表可能已损坏?
注意:
端口名称从系统注册表获取(例如,HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM).如果注册表包含陈旧或不正确的数据,则GetPortNames方法将返回不正确的数据.
| 归档时间: |
|
| 查看次数: |
3231 次 |
| 最近记录: |