Author Topic: Help with Serial Port Capture data  (Read 1339 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
Help with Serial Port Capture data
« on: May 10, 2020, 11:54:42 am »
How capture a serial port data as strings  starting with an specific character, fields coma separated  and  ending with CR/LF  ?

Example raw data :   "#XYZ, 123.567, ABCD, 48*FF" followed by CR/LF" 

fields to be captured after  starting character "#"
string 1    =  XYZ
string 2    =  123.567
string 3    =  ABCD
string 4    =  48
string 5    =  FF

after "ABCD", need the capture the  "48" and "FF" fields as separated strings . Then the "*" should also be considered same as a coma ","

Offline Mad Axeman

  • Newbie
  • Posts: 74
    • My web site - Harrythetrout
Re: Help with Serial Port Capture data
« Reply #1 on: May 10, 2020, 03:48:51 pm »
If I was doing that I would capture the whole string up to the CR/LF, save to a temp file, then capture the next string, save and continue until there's no more data on the serial port. Once there's no more data you can read in each line from the temp file and split it into whatever strings you want.
Oh look - a sig file :-)

Offline acjacques

  • Newbie
  • Posts: 33
Re: Help with Serial Port Capture data
« Reply #2 on: May 10, 2020, 04:07:14 pm »
i need to decode each incoming serial message .  The messages are  receiving at  about 1 hz. It is to control data in the display.
« Last Edit: May 10, 2020, 04:08:46 pm by acjacques »

Offline Mad Axeman

  • Newbie
  • Posts: 74
    • My web site - Harrythetrout
Re: Help with Serial Port Capture data
« Reply #3 on: May 10, 2020, 04:30:42 pm »
If you need to decode in real time I would still input a single string up to the CR/LF and then split the string.

Other way would be to input one character at a time. If it's not a comma then add it to a string. If it's a comma chuck it into the next string. Hmmm....that's a pretty poor way to explain things. Something like

DIM bytestr AS STRING * 1
DIM fin$(5)

' set up your port# (port$) and speed (comms$) here

I=0
OPEN "COM" + port$ + ":" + comms$ + ",N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1
    IF LOC(1) THEN
        GET #1, , bytestr
         IF (bytestr <> ",") THEN fin$(I) = fin$(i)+bytestr
            elseif (bytestr = ",") then I = I+1
         endif
      endif

fin$(4) will contain 48*FF so you'll have to split that.
That probably won't work as I've been working with PHP for the last few days and I keep getting the syntax mixed up but the basic idea is there.
Oh look - a sig file :-)