Listening to the Serial Port - Need help

marcellus

New member
Joined
Sep 21, 2011
Messages
1
Programming Experience
1-3
Hello,
I am trying to listen to the COM3 port and display the output in the TextBox.
If I understood correctly I will have to implement this by using eventhandlers, delegates.
I tried following these articles:
InformIT: Creating Events and Delegates in VB.NET > Mapping Events to Delegates
Delegates in VB.Net - Xtreme Visual Basic Talk


And this is the code I came up with...
Unfortunately it doesn't display anything. App just starts display "True" and no data is being displayed.
I am monitoring Arduino platform which I know is sending data constantly.


VB.NET:
Imports System.IO.Ports
Imports System.Text


Public Class ArduinoSerial


    Public Event ReceivedSerialData(ByVal data As String)
    WithEvents Serial As SerialPort
    Dim data As String


    Private Sub ArduinoSerial_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Serial = My.Computer.Ports.OpenSerialPort("COM3", 9600)
        TextBox.AppendText(Serial.IsOpen & vbCrLf)
    End Sub


    Private Sub Serial_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Serial.DataReceived
        RaiseEvent ReceivedSerialData(data)
    End Sub


    Public Sub DisplaySerialData(ByVal data) Handles Me.ReceivedSerialData
        TextBox.AppendText(data & vbCrLf)
    End Sub


End Class


I am really new into the vb.net. I am sure there are some horrible mistakes with this code but I am kind of stuck for the past 2 days on this one. Maybe someone could point me in the right direction. Thanks! ;)
 
You haven't set up the Data Bits, Stop Bits, Parity, which version of flow control you are using (Handshake property), what is being expected as a New Line character(s) (NewLine property), or minimum buffer size (ReadBufferSize property).

If you are using a hardware flow control method for RTS/CTS, you will need to set DtrEnable = False and RtsEnable = True to allow the local serial port to receive data.

The method you have chosen to receive data is asynchronous and is a good thing. You will run into situations where you need to be able to send something out the serial port and wait for a specific response. You should stop async data reception when you do that to prevent getting NULL characters in your
 
Back
Top