Pages: [1]   Go Down
Author Topic: Using Visual Basic for reading serial port... not going well :( GONE WELL NOW :)  (Read 5396 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm 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.

Cheers
« Last Edit: September 01, 2013, 02:01:37 pm by acboother » Logged

sig

UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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... !!!

Code:
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

Code:
#include <SPI.h>
#include <_util.h>

void setup() {
    Serial.begin(9600);

    printf_begin();

}
int i;
void loop() {
  printf("Hello %d\n", i);
  i++;
  //delay(200);

}
Logged

sig

UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Changing the read buffer like this

Code:
        COMport.PortName = "COM8"
        COMport.BaudRate = 9600
        COMport.ReadBufferSize = 16384
        COMport.Open()

just delays the onset of slow motion

and
Code:
        COMport.DtrEnable = True
        COMport.RtsEnable = True

seems to make no differnce
Logged

sig

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50319
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
void loop() {
  printf("Hello %d\n", i);
  i++;
  //delay(200);

}
Jamming data out the serial port as fast as possible hardly seems like a good idea. What does "Hello " add to the information being sent?
Logged

UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino output is generating test data.

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!
Logged

sig

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50319
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
PaulS, what did you think the "Hello" was for? More useful than the number counter!
I don't agree. I hardly see the benefit of a PC application receiving HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello

Your mileage may vary.
Logged

UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
PaulS, what did you think the "Hello" was for? More useful than the number counter!
I don't agree. I hardly see the benefit of a PC application receiving HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello

Your mileage may vary.

Ha ha ha.... You cannot be serious
Logged

sig

UK
Offline Offline
Sr. Member
****
Karma: 13
Posts: 280
pt
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking good now, please visit http://forum.arduino.cc/index.php?topic=185740.0 for a little serial monitor tool
Logged

sig

Pages: [1]   Go Up
Jump to: