• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

serial port access error

hi - I open a serial port on a windows form using the following code:
if (port == null)
                    port = new SerialPort(selectedPortName, 19200, Parity.None, 8, StopBits.One); //Com Port and Default Baud Rate
                if (!port.IsOpen)
                    port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
if I close the form and then reopen it, the code for the creation of the port is called again. when it is, it throws an access error. ("Access to the port 'COMxx' is denied.") is there an easy way to check whether the port has been configured once and doesn't need it again?
1 Solution
Miguel OzSoftware EngineerCommented:
When you close the form or the port you must call Dispose as shown in this link.
       if (port != null)
            port = null;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now