Go Down

Topic: [SOLVED] Serial print issue (Read 942 times) previous topic - next topic

beic

Sep 18, 2018, 02:03 pm Last Edit: Sep 18, 2018, 11:42 pm by beic
Hi there,

I have some simle sketch and I made also a simble vb6 application, but something is not right about serial output from the Arduino side, or maybe I wrong?

Code: [Select]

void setup()
{
  Serial.begin(9600);
  while (!Serial)
  {
    delay(10);
  }

  delay(500);

  Serial.print(F("RDW Remote Control"));
  Serial.println(F(""));
  Serial.println(F("FWVER=1.2"));
  Serial.println(F("DATE=Sep 18 2018"));
  Serial.println(F("TIME=13:34:23"));
  Serial.println(F(""));
}


After I upload the mentioned code above to the legit Arduino:

(Serial port detected as - Arduino Uno)

I got this kind of Debug from my vb6 application:

Code: [Select]

RDW Rem
ote Cont
rol


FWV
ER=1.2

DATE
=Sep
 18
2018

T
IME=
13:3
4:23








but if I upload the same code to the clone Arduino:

(Serial port detected as - USB-SERIAL CH340)

I got this kind of Debug from my vb6 application:

Code: [Select]

RDW Remote Control
FWVER=1.2
D
ATE=Sep 18 2018
TIME=13:34:23







And I don't really know why those lines getting splited.

Now in this case I can't parse any of mentioned output in my vb6 application, because the lines got break on random positions.

Thank you for your help!
..:: <3 I love this beautiful world <3 ::..

sterretje

#1
Sep 18, 2018, 02:21 pm Last Edit: Sep 18, 2018, 02:23 pm by sterretje
Serial is slow. Your receiving end (VB code) needs to collect the data before printing it.

Use Serial Monitor for testing, I'm quite sure it will display as expected.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

PaulS

The problem is your VB6 application and its NOT waiting for the end of packet marker. This is NOT a VB6 forum.
The art of getting good answers lies in asking good questions.

beic

The problem is your VB6 application and its NOT waiting for the end of packet marker. This is NOT a VB6 forum.
I like your "tested answers" as always! :D
..:: <3 I love this beautiful world <3 ::..

beic

Serial is slow. Your receiving end (VB code) needs to collect the data before printing it.

Use Serial Monitor for testing, I'm quite sure it will display as expected.
Do you have maybe some expertise in vb6, any suggestion for me?
..:: <3 I love this beautiful world <3 ::..

PaulS

Do you have maybe some expertise in vb6, any suggestion for me?
There are plenty of people here that know something about VB6. If only you had posted the code that doesn't seem to be working...
The art of getting good answers lies in asking good questions.

sterretje

Read till you receive a '\n'. Next print it.

No experience with VB6; if you post it here, someone can have a look at it; maybe it's obvious.

I wanted to suggest that your report your post and ask it to be moved to the Interfacing w/ Software on the Computer section; but I see that that already has happened.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

beic

There are plenty of people here that know something about VB6. If only you had posted the code that doesn't seem to be working...
Oh, okay, I will post it right now, sorry...
..:: <3 I love this beautiful world <3 ::..

beic

#8
Sep 18, 2018, 07:22 pm Last Edit: Sep 18, 2018, 07:23 pm by beic Reason: typo
Read till you receive a '\n'. Next print it.

No experience with VB6; if you post it here, someone can have a look at it; maybe it's obvious.

I wanted to suggest that your report your post and ask it to be moved to the Interfacing w/ Software on the Computer section; but I see that that already has happened.
Okay, I aready have a topic on VBForums opened, but I will post the VB6 code here too...and, yes I see that my post was moved there, good choice!


Code: [Select]

Private Sub comRS232_OnComm()
 
 Dim vrBuffer As String
 
 Dim lgFwV As Long
 Dim lgFwDate As Long
 Dim lgFwTime As Long
 
 comRS232.InputLen = 0
 
 vrBuffer = ""
 
 vrBuffer = comRS232.Input
 
 lgFwV = InStr(vrBuffer, "FWVER=")
 
 lgFwDate = InStr(vrBuffer, "DATE=")
 lgFwTime = InStr(vrBuffer, "TIME=")
 
 If lgFwV > 0 Then
  lblFwVer.Caption = Mid$(vrBuffer, lgFwV + 6, 3)
 End If
 
 If lgFwDate > 0 Then
  lblFwDate.Caption = Mid$(vrBuffer, lgFwDate + 5, 11)
 End If
 
 If lgFwTime > 0 Then
  lblFwTime.Caption = Mid$(vrBuffer, lgFwTime + 5, 8)
 End If
 
 Debug.Print vrBuffer
 
 txtSerial.Text = txtSerial.Text + vrBuffer
 txtSerial.SelStart = Len(txtSerial.Text)
 
 Exit Sub
End Sub
..:: <3 I love this beautiful world <3 ::..

ron_sutherland

#9
Sep 18, 2018, 11:12 pm Last Edit: Sep 18, 2018, 11:18 pm by ron_sutherland Reason: was not clear what event should do
I don't recall how VB5 and VB6 worked very well now, but I did use it for some time. I think the OnComm event was run whenever the GUI had a chance to test if the serial buffer had data available. The OnComm event should be used to empty the serial buffer each time the VB dispatch loops through the events.

So I think you need to collect the chunks of data from as many OnComm events as it takes until you have a command line.

The way I define commands nowadays is probably based on what I learned back then. To me, a command starts with the character after a newline ("\n"), and ends with a newline. Once I have a command line I can check if it is valid and then process it.

I recall using lots of string functions for testing the commands and chomping out data.

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/functions/string-functions

The modern way to do this is to have the Arduino output JSON and then the computer can decode that into a database-ish object (e.g. Python's Dictionary object).
my projects: https://github.com/epccs

beic

Read till you receive a '\n'. Next print it.
Indeed it was the end data termination char, in my case it was a double row.
..:: <3 I love this beautiful world <3 ::..

Go Up