Reputation: 423
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();
Upvotes: 3
Views: 5432
Reputation: 14376
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.
Upvotes: 2