I'm looking to log data for four RS-232 serial devices that will burst data (CR/LF terminated ASCII strings) at 1 Hz for 10 seconds every XX minutes, where XX is probably 15. On each serial device, I can specify data rate (1 Hz), burst size (10 samples), and burst interval (15 min = 900 s). The devices are not synchronized.
Inelegant solution: Starting wtih just one sensor, I scan continuously a 1 Hz and test the value NBytesReturned from SerialInRecord. (NBytesReturned is guaranteed to be >= 42 if the sensor has valid output.) So, I conditionally CallTable based on the value of NBytesReturned.
The nice thing about this is that I don't have to change any code should I change the burst interval on any device.
This works reliably, I think I can do the same trick in the Main program with the other devices inside the same Scan loop. But is there a more elegant solution?
-- Eric
DataTable (EcoTriplet,1,-1) 'Set table size to # of records, or -1 to autoallocate. Sample (1,Chl470,Long) Sample (1,Beta700,Long) Sample (1,FDOM,Long) Sample (1,RawString,String) EndTable 'Define Subroutines 'Sub 'EnterSub instructions here 'EndSub 'Main Program BeginProg SerialOpen (PortEco,19200,0,0,200,0) Scan (1,Sec,3,0) 'Each Eco record is a tab-delimited string of 42-48 bytes plus : '99/99/99 99:99:99 695 xx38 700 xx49 460 xx41 999 SerialInRecord (PortEco,RawString,&h0A,0,&h0D,NBytesReturned,01) 'Get counts for each measurement by splitingt string at tabs CHR(09) SplitStr (SplitStrings(1),RawString,CHR(09),9,5) Chl470=SplitStrings(4) 'xx38, where xx are additional digits Beta700=SplitStrings(6) 'xx49 FDOM=SplitStrings(8) 'xx41 'Update table If NBytesReturned >= 42 Then CallTable EcoTriplet EndIf NextScan EndProg
This post is under review.
Ping
I think your program is about as simple as can be to get the job done. By definition of many programmers, that is elegant.
We can add complexity to do smarter data processing. If for example you want all 10 FDOM measurements from a burst in the same record, that is possible. It will take quite a bit more logic in the program. It could also be done in more than one way.
You would need arrays to hold the data values (ex. FDOM(10) ). You also need a start machine that picks up on the start of a burst, and the end of a burst. If there is something like a burst number in the data format, you could watch that. Without something in the data format to watch, you need a timer to know the burst is done.
This post is under review.
This post is under review.