Generic Logging Program 7/1/99 (C) 1999 Enertech Consultants 17 Main St. P.O. Box 770 Lee, MA 01238 (413) 243-2800 Tom Sullivan etceast@bcn.net This program is made available by Onset Computer as a courtesy to our customers. All technical support with regard to this program should be directed to Enertech Consultants at the contact information above. Onset makes no claims as to the functionality, correctness or suitability for this application, and can not be held liable for any problems, loss or damages resulting from the use. In choosing to use this software, the user does so at his/her own risk, assuming full responsibility for any and all problems, loss or damage resulting from its use. Furthermore, Onset does not provide any technical support with regard to this program. Revision History ---------------- 7/1/99 - Original Version 1.0 tested with TFBASIC version 1.00 -- tps This logging program performs 12 bit A/D conversions and stores the resulting data to the TFX-11 SFLASH. Calibration factors are entered (optionally) at the program start. The calibration factors are stored in the TFX-11 EEPROM memory. Also stored in the EEPROM is a serial number that is also entered (optionally ) by the user. A rate is also entered at program start. A rate of 100 represents 1 second between samples. If no calibration factor is needed, enter a value of 1. All calibration data is stored as a floating point number. All A/D data is stored as 16 bit integer values. IMPORTANT NOTE: This software demonstrates using the ONSET TFX-11 for data logging. The software is provided for demonstration purposes ONLY and no warranties are expressed or implied. The software is provide AS IS. Having said that, I hope you find it useful as a starting point for your logging application. Data File Format ---------------- The following is the format of the data written to the SFLASH. The data is stored as Header then Data. The Header is written once when the session begins (and data is always appended to the end of the data file). Then, data is written at a rate determined by Srate (entered at program start). Unless the data is offloaded between launches, A new header and data will be written to the SFLASH the next time a session is started. Byte 0 - Month Byte 1 - Day Byte 2 - Year Byte 3 - Hour Byte 4 - Min Byte 5 - Second Byte 6 - Serial Number (msb) Byte 7 - Serial Number Byte 8 - Serial Number Byte 9 - Serial Number (lsb) Byte 10 - Calibration Factor for Channel 0 (float) Byte 11 - Calibration Factor for Channel 1 Byte 12 - Calibration Factor for Channel 2 Byte 13 - Calibration Factor for Channel 3 .... Byte 50 - Calibration Factor for Channel 7 Byte 51 - Calibration Factor for Channel 8 Byte 52 - Calibration Factor for Channel 9 Byte 53 - Calibration Factor for Channel 10 Byte 54 - A/D Channel 0 Byte 55 - A/D Channel 0 Byte 56 - A/D Channel 1 Byte 57 - A/D Channel 1 ... Byte XX - A/D Channel 10 Byte XX+1 - A/D Channel 10 Byte XX+2 - A/D Channel 0 Byte XX+3 - A/D Channel 0 Byte XX+4 - A/D Channel 1 Byte XX+5 - A/D Channel 1 ...etc. Initialization Enter the logging rate and calibration data Some large number we won't probably find memory initialized to. InitialValue = 9999999 Input "Enter the Rate: " Srate print "The Rate is: ",Srate print " " print "Do you want to enter calibration data? [N]" Input "Enter Y or N: " answer$,#1 if answer$ = "Y" | answer$ = "y" Gosub EnterCalData else if Vget(0) = InitialValue Gosub LoadCalData else print "Calibration data is not available in EEPROM. It must be entered." Gosub EnterCalData endif endif Set the time, serial#, and calibration factors in the header record SetHeader: ReadRTC rtime print " " print "The current date and time is "; print #02,?(4),"/",?(3),"/",?(5)," ",?(2),":",?(1),":",?(0) print " " print "Do you want to enter a new date and time? [N]" Input "Enter Y or N: "ans$,#1 if ans$ = "Y" | ans$ = "y" Input "Month: "?(4) Input "Day: "?(3) Input "Year: "?(5) Input "Hour: "?(2) Input "Minute: "?(1) Input "Second: "?(0) if ?(4) <> 0 stime SetRTC endif endif ReadRTC Rtime print " " print "The current serial number is ",str(vget(12)) print "Do you want to enter a new serial number? [N]" Input "Enter Y or N: "ans$,#1 if ans$ = "Y" | ans$ = "y" Input "serial #: "SerialNumber if SerialNumber = 0 SerialNumber = Vget(12) else vstore 12, SerialNumber endif else SerialNumber = Vget(12) endif print " " print "Current Date and Time: "; print #02, ?(4), "/", ?(3), "/", ?(5), " "; print #02, ?(2), ":", ?(1), ":", ?(0) print "Serial Number: "; print SerialNumber print "Calibration Factor 1: ", CalFactor0! print "Calibration Factor 2: ", CalFactor1! print "Calibration Factor 3: ", CalFactor2! print "Calibration Factor 4: ", CalFactor3! print "Calibration Factor 5: ", CalFactor4! print "Calibration Factor 6: ", CalFactor5! print "Calibration Factor 7: ", CalFactor6! print "Calibration Factor 8: ", CalFactor7! print "Calibration Factor 9: ", CalFactor8! print "Calibration Factor 10: ", CalFactor9! print "Calibration Factor 11: ", CalFactor10! store #1,?(5),?(4),?(3),?(2),?(1),?(0) store #4,SerialNumber store #4,CalFactor0!,CalFactor1!,CalFactor2!,CalFactor3!,CalFactor4!,CalFactor5!,CalFactor6!,CalFactor7!,CalFactor8!,CalFactor9!,CalFactor10! print " " print " " print "Logging....." print "Hit 'ctrl C' to stop" Sync the sleep system sleep 0 CBREAK alldone Until someone hits control-C Log the data while Srate > 0 ChanData0 = chan(0) ChanData1 = chan(1) ChanData2 = chan(2) ChanData3 = chan(3) ChanData4 = chan(4) ChanData5 = chan(5) ChanData6 = chan(6) ChanData7 = chan(7) ChanData8 = chan(8) ChanData9 = chan(9) ChanData10 = chan(10) store #2,ChanData0,ChanData1,ChanData2,ChanData3,ChanData4,ChanData5,ChanData6,ChanData7,ChanData8,ChanData9,ChanData10 sleep Srate wend Enter the new calibration factors EnterCalData: vstore 0, InitialValue Print "Enter the calibration factors: " Input " Channel 0 [1]: " CalFactor0! if CalFactor0! = 0 CalFactor0! = 1 endif vstore 1, CalFactor0! Input " Channel 1 [1]: " CalFactor1! if CalFactor1! = 0 CalFactor1! = 1 endif vstore 2, CalFactor1! Input " Channel 2 [1]: " CalFactor2! if CalFactor2! = 0 CalFactor2! = 1 endif vstore 3, CalFactor2! Input " Channel 3 [1]: " CalFactor3! if CalFactor3! = 0 CalFactor3! = 1 endif vstore 4, CalFactor3! Input " Channel 4 [1]: " CalFactor4! if CalFactor4! = 0 CalFactor4! = 1 endif vstore 5, CalFactor4! Input " Channel 5 [1]: " CalFactor5! if CalFactor5! = 0 CalFactor5! = 1 endif vstore 6, CalFactor5! Input " Channel 6 [1]: " CalFactor6! if CalFactor6! = 0 CalFactor6! = 1 endif vstore 7, CalFactor6! Input " Channel 7 [1]: " CalFactor7! if CalFactor7! = 0 CalFactor7! = 1 endif vstore 8, CalFactor7! Input " Channel 8 [1]: " CalFactor8! if CalFactor8! = 0 CalFactor8! = 1 endif vstore 9, CalFactor8! Input " Channel 9 [1]: " CalFactor9! if CalFactor9! = 0 CalFactor9! = 1 endif vstore 10, CalFactor9! Input " Channel 10 [1]: " CalFactor10! if CalFactor10! = 0 CalFactor10! = 1 endif vstore 11, CalFactor10! Return LoadCalData: CalFactor0! = asflt(vget(1)) CalFactor1! = asflt(vget(2)) CalFactor2! = asflt(vget(3)) CalFactor3! = asflt(vget(4)) CalFactor4! = asflt(vget(5)) CalFactor5! = asflt(vget(6)) CalFactor6! = asflt(vget(7)) CalFactor7! = asflt(vget(8)) CalFactor8! = asflt(vget(9)) CalFactor9! = asflt(vget(10)) CalFactor10! = asflt(vget(11)) Return alldone: stop