Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serial Port unauthorized access exception

Tags:

c#

io

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();
like image 451
dbomb101 Avatar asked May 03 '26 06:05

dbomb101


1 Answers

Access is denied to the port.

  • or -

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.

like image 89
KevinDTimm Avatar answered May 05 '26 19:05

KevinDTimm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!