Hi, I'm writing a program that when I click, I send various codes to a microcontroller and it sends back a response followed by a special character ( a semicolon character;). My problema is that I send the first code, and I don't know how to wait until I read the whole information of the microcontroller before sending the seconde code. Here is the program:
Thnx
Code:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Serialport1.DataReceived, Serialport1.DataReceived
Try
If Serialport1.BytesToRead > 0 Then
Dim bytsToRead As Integer = Serialport1.BytesToRead
Dim buf(bytsToRead - 1) As Byte
bytsToRead = Serialport1.Read(buf, 0, bytsToRead)
Dim outString = (Encoding.ASCII.GetString(buf))
Me.Invoke(New mydel(AddressOf read), outString)
End If
Catch ex As Exception
End Try
End Sub
Private Sub btnLoop_Click(sender As Object, e As EventArgs) Handles btnLoop.Click
If Serialport1.IsOpen Then
incoming = "" 'data received from Serial Port
Dim string_end As Char = ";"
Dim code0 As String = "TG"
Dim askForInformation0 As String = code0 + string_end.ToString
Serialport1.Write(askForInformation0)
While (outstring.EndsWith(string_end) = False)
End While
Dim code1 As String = "?P1"
Dim askForInformation1 As String = code1 + string_end.ToString
Serialport1.Write(askForInformation1)
While (outString.EndsWith(string_end) = False)
End While
End If
End Sub