[英]Serial Port unauthorized access exception
I'm trying to read in some information from a serial port, but when I actually to open a connnection it throws a unauthorized access exception 我试图从串口读取一些信息,但当我实际打开一个连接时,它会抛出一个未经授权的访问异常
This code reads in the port names 此代码读入端口名称
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]);
}
This is the code which tries to the the information coming from the serial port 这是尝试来自串行端口的信息的代码
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();
Access is denied to the port. 访问被拒绝到端口。
The current process, or another process on the system, already has the specified COM port open either by a SerialPort instance or in unmanaged code. 当前进程或系统上的其他进程已经通过SerialPort实例或非托管代码打开指定的COM端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.