title: Reciving data from Cell counter through rs232
body: <p>I have a cell counter machine that sends data automatically after test end through a rs232 cable. I tried the following code to receive that data but I get nothing although I changed the <code>BaudRate</code> value many times. What is the problem?</p>
  
  <p>My code:</p>
  
  <pre><code>Imports System
  Imports System.Threading
  Imports System.IO.Ports
  Imports System.ComponentModel
  
  Public Class ComReadWrite
      Dim myPorts As Array
      Dim txtline As String
      Dim txtchar As String
      Dim txtbyte As String
      Dim txtexisting As String
      Delegate Sub setTextCallBack(ByVal txt As String)
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          myPorts = IO.Ports.SerialPort.GetPortNames()
          portnamecombo.Items.AddRange(myPorts)
          WriteButton.Enabled = False
          CloseButton.Enabled = False
          BaudRateBox.Items.Add(110)
          BaudRateBox.Items.Add(300)
          BaudRateBox.Items.Add(600)
          BaudRateBox.Items.Add(1200)
          BaudRateBox.Items.Add(2400)
          BaudRateBox.Items.Add(4800)
          BaudRateBox.Items.Add(9600) 'Populate the baudratebox Combo box to common baud rates used 
          BaudRateBox.Items.Add(14400)
          BaudRateBox.Items.Add(19200)
          BaudRateBox.Items.Add(38400)
          BaudRateBox.Items.Add(57600)
          BaudRateBox.Items.Add(115200)
          BaudRateBox.Items.Add(128000)
          BaudRateBox.Items.Add(256000)
          BaudRateBox.Text = 38400
      End Sub
  
      Private Sub Start_Click(sender As Object, e As EventArgs) Handles Start.Click
          SerialPort1.PortName = portnamecombo.Text
          SerialPort1.BaudRate = BaudRateBox.Text
          SerialPort1.ReadTimeout = 500
  
          SerialPort1.Parity = Parity.None
          SerialPort1.DataBits = 8
          SerialPort1.StopBits = StopBits.One
  
          SerialPort1.Open()
  
          Start.Enabled = False
          WriteButton.Enabled = True
          CloseButton.Enabled = True
      End Sub
  
      Private Sub WriteButton_Click(sender As Object, e As EventArgs) Handles WriteButton.Click
          SerialPort1.Write(Chr(6))
      End Sub
  
      Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles CloseButton.Click
          SerialPort1.Close()
          Start.Enabled = True
          WriteButton.Enabled = False
          CloseButton.Enabled = False
      End Sub
  
      Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
          Try
              RecievedText(SerialPort1.ReadExisting())
  
          Catch ex As Exception
              MessageBox.Show(ex.Message)
          End Try
      End Sub
  
      Private Sub RecievedText(ByVal txt As String)
          If Me.ReadBox.InvokeRequired Then
              Dim x As New setTextCallBack(AddressOf RecievedText)
              Me.Invoke(x, New Object() {(txt)})
          Else
  
              Me.ReadBox.Text &amp;= txt
          End If
      End Sub
  End Class
  </code></pre>