title: C# can fail to open STMicro virtual COM port
body: <p>I have an issue with opening an STMicro USB virtual COM port.</p>
  
  <p>When I plug the device into my PC, the COM port appears as it should, and the Windows Device Manager indicates it is working properly.</p>
  
  <p>I have a C# program on the PC which selects and opens this port.</p>
  
  <p>However, in about 1 in 10 attempts, the PC program sticks on the port.open() command, and after about half a minute, returns with the error "The semaphore timeout period has expired".</p>
  
  <p>I have written a tiny C# program that does nothing more than open the port. This still gives the behaviour noted.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      SerialPort port = new SerialPort();
      string portName = "COM1";  // Give it a default to start with
  
  
      public Form1()
      {
          InitializeComponent();
  
          // Populate the COM port selector combobox with available port names
          cmbPortSelect.Items.Clear();
  
          string[] activePorts = SerialPort.GetPortNames();
          foreach (string availablePort in activePorts)
          {
              cmbPortSelect.Items.Add(availablePort);
          }
  
          // Declare the serial port
          port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
          port.ReadTimeout = 100;
  
      }
  
      private void cmbPortSelect_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (cmbPortSelect.SelectedIndex != -1)
          {   // It will get set to -1 (i.e. no selection) in the catch below - we don’t want this selected item change to do anything
              if (port.IsOpen) port.Close();
              port.PortName = (string)cmbPortSelect.SelectedItem;
              System.Threading.Thread.Sleep(50);
              try
              {
                  port.Open();
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
                  cmbPortSelect.SelectedIndex = -1;  // Clear the selected item box
              }
          }
  
      }
  }
  </code></pre>
  
  <p>If instead of using my C# program to open the port, I use the communications program <a href="http://en.wikipedia.org/wiki/PuTTY" rel="nofollow noreferrer">PuTTY</a>, it works every time.</p>
  
  <p>In addition, if I plug in a device with an FDTI USB virtual COM port, it also works every time.</p>
  
  <p>I'm using Windows&nbsp;7, with the STMicro VCP drivers ver 1.3.1, but the same behaviour occurs with Windows&nbsp;10 and the generic Microsoft drivers, which STMicro recommend we use.</p>
  
  <p>There is a version 1.5.1 drivers for Windows&nbsp;7, but when I installed them, it reported that they had installed correctly, but the Device Manager still reported ver 1.3.1.</p>
  
  <p>Has anyone noted any similar behaviour?</p>