Read Serial Port Data

Hi

I am trying to read data form a Serial Port, below is the VB Express Code Snippet that does this, as supplied in VB Express. This does work however I cannot get it to place the text in a multiline Textbox. The data is repeated as a 56 character string approx every 1 second. What I want to do is read the string place it in a textbox, go to next line, read the next 56 character string and write that to textbox. Ultimately I will have a textbox with multiple lines of text each being the string repeated many times, although the values in the string are constantly changing.

My question where in this code do I place the code, and what exactly is the correct code to achieve this, using Debug.Print(line) is showing me the correct data is being read, but to no avail can I get this written into the textbox, nothing appears although the scrollbars move as the data is 'written' invisibly to the textbox

I tried "TextBox1.Text = TextBox1.Text & vbCrLf & line" at many different places in the code below:

Dim buffer As New StringBuilder()

Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort("COM1")

Do

Dim line As String = comPort.ReadLine()

If line Is Nothing Then

Exit Do

Else

buffer.AppendLine(line)

End If

Loop

End Using



Answer this question

Read Serial Port Data

  • gdick

    If I understand your question, this is working for me. My actual code is more detailed as to its actions, but these are the primary statements. Hope this helps.

    [Note: I am reading lines from a *.txt file]

    Dim textline as String

    [Open and configure your Com Port # ]

    Do Until [whatever]

    textline = LineInput(1) ' get line from Com Port #

    If textline = "[whatever]" Then '( I use "END" as last line in a file)

    Exit Do

    End If

    ' ****************************************************************

    RichTextBox1.Text = RichTextBox1.Text & textline

    RichTextBox1.Refresh()

    ' ***************************************************************

    End If

    Loop


  • NathanP

    Thanks citrusguy, I will try this and et you know. Appreciate the help.
  • Read Serial Port Data