QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: acjacques 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 ","
-
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.
-
i need to decode each incoming serial message . The messages are receiving at about 1 hz. It is to control data in the display.
-
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.