title: Vbnet 2017, first head shoot on modbus
body: <p>i need help for reading a serial port with modbus protocol.<br>
  Told me for reading a HEX value from chipset, need to send before reading: </p>
  
  <blockquote>
    <p>1E 03 00 0C 00 01 46 66  .. </p>
  </blockquote>
  
  <p>The respond example is: </p>
  
  <blockquote>
    <p>1E 03 02 xx yy ch cl</p>
  </blockquote>
  
  <pre><code>Imports System          'To Access Console.WriteLine()
  Imports System.IO.Ports 'To Access the SerialPort Object
  Module Module1
  
  Sub Main()
      Console.WriteLine(ReceiveSerialData())
      Console.Read()
  End Sub
  
  Function ReceiveSerialData() As String
      'modbas
      ' Receive strings from a serial port.
      Dim returnStr As String = ""
      Dim com9 As IO.Ports.SerialPort = Nothing
      Try
          com9 = My.Computer.Ports.OpenSerialPort("COM9")
          com9.ReadTimeout = 5000
          com9.BaudRate = 19200
          com9.Parity = Parity.None
          com9.DataBits = 8
          com9.StopBits = StopBits.One
         ' com9.Write("1E 03 00 0C 00 01 46 66") ' stringa che serve per farsi rispondere dal chip, obbligo di inviarla
          ' com9.Read("1E 03 00 0C 00 01 46 66",0,8)
          Do
              Dim Incoming As String = com9.ReadLine()
              If Incoming Is Nothing Then
                  Exit Do
              Else
                  returnStr &amp;= Incoming &amp; vbCrLf
              End If
          Loop
      Catch ex As TimeoutException
          returnStr = "Error: Serial Port read timed out."
      Finally
          If com9 IsNot Nothing Then com9.Close()
      End Try
      Return returnStr
  End Function
  
  End Module
  </code></pre>