title: Access to the port 'COM5' is denied
body: <p>I get the following error message <code>Access to the port 'COM5' is denied.</code> when running the method below from my form. I have tried entering the right baud rate of 9600 from the port setting of my device manager. I have also tried accessing the devices through Portmon but there is a bug that prevents me from being connected. Any alternative to solve this problem?</p>
  
  <pre><code>      //Fields
      List&lt;string&gt; myReceivedLines = new List&lt;string&gt;();
  
      //subscriber method for the port.DataReceived Event
      private void DataReceivedHandler(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
      {
          SerialPort sp = (SerialPort)sender;
          while (sp.BytesToRead &gt; 0)
          {
              try
              {
                  myReceivedLines.Add(sp.ReadLine());
              }
              catch (TimeoutException)
              {
                  break;
              }
          }
      }
  
      protected override void SolveInstance(IGH_DataAccess DA)
      {
  
          string selectedportname = default(string);
          DA.GetData(1, ref selectedportname);
          int selectedbaudrate = default(int);
          DA.GetData(2, ref selectedbaudrate);
          bool connecttodevice = default(bool);
          DA.GetData(3, ref connecttodevice);
  
          port.DtrEnable = true;   //enables the Data Terminal Ready (DTR) signal during serial communication (Handshaking)
          port.Open();             //Open the port
          if (!(port.IsOpen == true)) port.Open();
  
  
          if (connecttodevice == true)
          {
              port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
              DA.SetDataList(0, myReceivedLines);
          }
  </code></pre>