3
我试图读取从串口一些信息,但是当我真正打开connnection它抛出一个未经授权的访问异常串行端口未经授权的访问异常
这段代码在端口名称中读取
SerialPort port = new SerialPort();
string[] serialPorts = System.IO.Ports.SerialPort.GetPortNames();
public Page_Main()
{
InitializeComponent();
for (int i = 0; i < serialPorts.Count(); i++)
portBox.Items.Add(serialPorts[i]);
}
这是试图把从串口
port.PortName = portBox.SelectedItem.ToString();
port.BaudRate = 9600;
port.DataBits = 8;
port.Parity = Parity.None;
port.StopBits = StopBits.One;
port.Open();// This is where the exception is thrown
serialOutput.Text = port.ReadLine();
port.PortName的值是什么? – KevinDTimm 2012-04-26 21:37:26
值为COM3 – dbomb101 2012-04-26 21:39:57
因此,SerialPort.Open()的手册页说 - 拒绝访问端口或某个进程已经打开指定的COM端口 – KevinDTimm 2012-04-26 21:40:45