Quote Originally Posted by Vizier87 View Post
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:

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
The output textbox gives out a string of ????????? most of the time, sometimes numerical. Sometimes it's nothing.

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
I would double check the Baud Rate that the sensor uses. 2,000,000 seems a bit far fetched. I think the highest truly supported by serial ports is 256,000 and even so most devices only use 9,200 or 19,200. If you look into the details for your sensor they should mention the baud rate somewhere. (Also if the baud rate is wrong that causes exactly what you are describing)

Hope that helps!