PxPlus User Forum
Main Board => Discussions => Language => Topic started by: Neal McKinney on February 27, 2021, 10:02:55 AM
-
I'm working with a stream of data over a serial COM port. Each 'message' in the stream of data ends with a $04$. Is there way to have the READ directive treat that character as the end of the data to read, so that no other data is read from the buffer? The number of characters in each message is variable, so just using a SIZ= option will not work either.
-
Don't know if it will work, but you could try:
def sep($04$)
You can capture the existing separator list with seps$=sep(*)
-
That gives me a field separator, not a record separator. I need a record separator.
-
You could do your own buffering.
open create (unt,isz=1)"testfile"
chan=lfo
for i=1 to 100
rec$="test block "+str(i)+$04$
write record(chan)rec$
next i
close(chan)
open input(chan,isz=1)"testfile"
buf$=""
while 1
read record(chan,end=*break,bsy=*continue,tim=1,siz=-128)block$
buf$+=block$
x=pos($04$=buf$)
while x>0
rec$=buf$(1,x-1),buf$=buf$(x+1)
recs$+=rec$+$0a$ ! do whatever with the record
x=pos($04$=buf$)
wend
wend
close(chan)
print recs$
-
You should be able to simply issue READ RECORD (chnl, SIZ=1) X$ to accept each character, one at a time, and build up the line/record until you received a $04$.
Something like:
line$=""
While 1
Read Record (channel, siz=1) X$
If X$=$04$ break
line$+=X$
wend