I'm using VB 2010 .NET to read the serial port so I can make something more useful than simply writing out the data but initially that is all I am trying to do.
I have taken some code I found called MAXIcom at Serial Communication with Visual Basic .NET and modified it to read simple output of "Hello" plus an incrementing number. The code works at 9600 baud but not at 115200. The supplied code uses event handler for the reading (and hence in a separate thread). I also rewrote it to do everything in the same thread (read and update the text box) using a timer which I eventually set ticking at 1 ms. It worked'ish but the GUI became unresponsive.
In all cases the speed is not as fast as the Arduino serial output... The program locks up... various woes.
At this time I'm not asking if someone could check my code I would just like to get my hands on some alternative to try. Does anyone have some source or links to something that may be useful.
Here is the VB source cut down to its minimum. The form has a single text box on it for displaying the output. This version writes just one character to the text box and clears it away.
The display changes characters pretty fast for about 2 seconds then each charactercomes up at about every .25 seconds... !!!
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
Public Class Form1
Dim WithEvents COMport As New SerialPort
Dim RXbyte As Byte
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
COMport.PortName = "COM8"
COMport.BaudRate = 9600
COMport.Open()
End Sub
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMport.DataReceived
RXbyte = COMport.ReadByte
Me.Invoke(New MethodInvoker(AddressOf Display))
End Sub
Private Sub Display()
txtReceived.Clear()
txtReceived.Text = (ChrW(RXbyte))
End Sub
End Class
and here is the Arduino code (util.h manages the printf support) and it speeds along on the Arduino serial output
The objective is to have a better tool than a simple print of values (eg a plotter or a visual representation)
To get there I have to make it work! Then I have to check its performance capabilities and envelop. I am obviously concerned about the performance/stability and my approach being wrong. Arduino manages the 'jamming' as does http://home.comcast.net/~hardandsoftware/enhanced_serial_port_object_for.htm so I'd like to get my version working too.
PaulS, what did you think the "Hello" was for? More useful than the number counter!