title: Cannot receive data over serial port in VB.net while using virtual com port driving FTDI USB chip
body: <h2>My setup:</h2>
  
  <ol>
  <li>Hardware device using FTDI FT2232D chip connected to my pc using USB.</li>
  <li>I have installed the VCP (virtual com port) driver installed which shows up the FTDI chip connected over USB as a COM port in windows.</li>
  <li>I am using a simple VB.net program to read the com port.</li>
  </ol>
  
  <h2>Behaviour:</h2>
  
  <p>When I use realterm to send data to my device over the com port, the device always replies successfully.</p>
  
  <p>When I use my VB.net test program and then use realterm, tx works, but realterm does not receive any reply. </p>
  
  <p>I can get realterm to receive data again by unplugging usb, replugging and then resend command.</p>
  
  <p>Unplugging and replugging usb does not fix the problem when using my vb.net program.
  My vb.net program sometimes works, but not always.</p>
  
  <p>It looks like something in my program is causing the com port to break and the only way to fix it is to unplug the usb cable and plug it back in again.</p>
  
  <p>My code looks something like this:</p>
  
  <pre><code>Public Class SerialConnection
  
      Private MSerialPort As SerialPort
      Private Const StartByte As Byte = &amp;H5B
  
      Public Sub New(ByVal Port As String)
          MSerialPort = New SerialPort()
          MSerialPort.PortName = Port
          MSerialPort.BaudRate = 9600
          MSerialPort.ReadTimeout = 5000
          MSerialPort.WriteTimeout = 5000
          MSerialPort.Open()
      End Sub
  
      Public Function SerialPacketTransaction()
          Dim SendPacketBytes = New List(Of Byte)
          Dim ReceivePacketBytes As List(Of Byte)
  
          MSerialPort.DiscardInBuffer()
      MSerialPort.DiscardOutBuffer()
  
          SendPacketBytes.Add(StartByte)
  
          MSerialPort.Write(SendPacketBytes.ToArray, 0, SendPacketBytes.Count)
  
          Dim TimeoutTime As DateTime = Now().AddMilliseconds(MSerialPort.ReadTimeout)
          Dim readbyte As Byte
          Do
              If Now() &gt; TimeoutTime Then Throw New TimeoutException("Timeout waiting for response")
              Thread.Sleep(50)
              readbyte = ReadSerialByte()
          Loop Until (readbyte = StartByte)
      End Sub
  End Class
  </code></pre>