Serial port unauthorized access exception

I'm trying to read some information from the serial port, but when I really open the connection, it throws an unauthorized access exception

This code reads in 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 that is trying to get information 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();
+3
source share
1 answer

Access denied to port.

  • or -

The current process or another process in the system already has the specified COM port, opened either by a SerialPort instance or by an unmanaged code.

+2
source

All Articles