PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Serial data stream  (Read 1102 times)

Neal McKinney

  • Member
  • **
  • Posts: 7
    • View Profile
Serial data stream
« 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.

Ken Sproul

  • Gold Member
  • ****
  • Posts: 60
    • View Profile
Re: Serial data stream
« Reply #1 on: February 27, 2021, 10:24:01 AM »

Don't know if it will work, but you could try:
def sep($04$)


You can capture the existing separator list with seps$=sep(*)

Ken Sproul
DPI Information Service, Inc.
Pivotal Systems LLC

Neal McKinney

  • Member
  • **
  • Posts: 7
    • View Profile
Re: Serial data stream
« Reply #2 on: February 27, 2021, 11:00:40 AM »
That gives me a field separator, not a record separator.  I need a record separator.

Allen Miglore

  • Silver Member
  • ***
  • Posts: 38
    • View Profile
    • UnForm
Re: Serial data stream
« Reply #3 on: February 27, 2021, 06:02:41 PM »
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$


Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Serial data stream
« Reply #4 on: February 28, 2021, 09:27:50 PM »
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:

Code: [Select]
  line$=""
  While 1
  Read Record (channel, siz=1) X$
  If X$=$04$ break
  line$+=X$
  wend

Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com