Good evening all! I am working on a VB program that communicates with a micro-controller and processes the information via this VB program. I have the communication working and now I need to take the received information and populate it into specific fields in different tabs. Accessing the object directly does not seem to work.
Any help is appreciated!
Code:
Public Sub DataReceivedHandler(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
SerialPort1.ReadTimeout = 500
Dim indata As String
Try
indata = SerialPort1.ReadLine
SetText(Label20, indata)
Parsed_String = indata.Substring(1, indata.Length - 1)
If Parsed_String <> String.Empty Then
Parsed_String.Trim()
SetText(Label21, Parsed_String)
Parsed_String = Parsed_String.Substring(0, Parsed_String.Length - 1)
If Parsed_String <> String.Empty Then
Dim Strt = New Thread(AddressOf Update_Tabs)
Strt.Start()
End If
End If
'SetText(Label19, System.Text.Encoding.ASCII.GetString(buff).Length)
Catch ex As Exception
SetText(Label20, ex.Message & ex.StackTrace)
End Try
End Sub
Public Sub Update_Tabs()
Dim values() As String
values = Parsed_String.Split(":")
If task = 2 Then
If values.Length > 2 Then
' Do stuff with the array
SetText(inbound_txt, InStr(BufferStr, StartChar)) ' set text via thread
Parsed_String = String.Empty
End If
ElseIf task = 1 Then
Label50.Text = values(1) ' --------------------------------------------- This throws an error about cross thread operation not valid
status_txt.Text = values(0) & ":" & values(1) & ":" & values(2) & ":" & values(3) & ":"
SerialPort1.WriteLine("Y") ' All data received and updated to PC
task = 0
Else
task = 0
SerialPort1.WriteLine("S")
End If
'
End Sub