Hi guys,
I'm attempting at just displaying the raw values from a COM serial port from a sensor, which gives around 4000 rows of data per cycle.
Here's the code:
The output textbox gives out a string of ????????? most of the time, sometimes numerical. Sometimes it's nothing.Code:Imports System Imports System.IO.Ports Imports System.Threading Public Class Form1 Dim readThread As Thread = New Thread(AddressOf ReadFromCom) Dim abortThread As Boolean Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SerialPort2.Open() readThread.Start() End Sub Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With SerialPort2 .PortName = "COM9" .BaudRate = 2000000 .Parity = Parity.None .DataBits = 8 .StopBits = 1 .ReadTimeout = Nothing .DtrEnable = True .RtsEnable = True End With End Sub Public Sub ReadFromCom() While abortThread = False Try Dim message As String = SerialPort2.ReadExisting updateStatus("Received: " & message) Catch ex As TimeoutException updateStatus(ex.ToString) End Try End While End Sub Public Delegate Sub updateStatusDelegate(ByVal newStatus As String) Public Sub updateStatus(ByVal newStatus As String) If Me.InvokeRequired Then Dim upbd As New updateStatusDelegate(AddressOf updateStatus) Me.Invoke(upbd, New Object() {newStatus}) Else TextBox1.Text = newStatus & vbCrLf & vbCrLf & TextBox1.Text End If End Sub End Class
Anything I should read more into? It seems not many thread discusses this at length so I'm tweaking about other people's code hoping for the best.
Anyhow an independent Python code with MatPlotLib, with the same settings for the serial port outputs the data quite nicely.
Thanks.
Vizier87




Reply With Quote
