Hello,
Thanks in advance to anyone who chimes in. I'm sure this is a simple fix, but I'm still fairly new at this and, so far, it's eluded me.
At this point I can display incoming data in a msgbox but I would like to be able to display it in a label or textbox that updates with new data as it is read. If someone could provide me with a clue or two I'd appreciate it.
Again, thanks to anyone willing to assist,
-Zixxer
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
Dim runbtnClicked As Boolean = False
Dim stopbtnClicked As Boolean = False
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim NewTemp As String = SerialPort1.ReadExisting()
''This does Not work and pulls a cross-threading exception
''Cross-thread operation not valid: Control 'txtBx1' accessed from a thread other than the thread it was created on.
txtBx1.Text = NewTemp
''This Works and I can see the incoming data''
While runbtnClicked = True
MsgBox(NewTemp)
End While
End Sub
Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
MsgBox("Running")
Try
SerialPort1.Open()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
runbtnClicked = True
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
runbtnClicked = False
stopbtnClicked = True
SerialPort1.Close()
End Sub
End Class