Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

DataTable access


CTS Jun 7, 2010 04:05 PM

Hi,
I am new to CrBasic and the CR1000 Datalogger. I have gathered this much that the averaging of values is based on tbale form, similar to the sample below:

DataTable(Table1,True,-1)
DataInterval(0,60,Min,10)
Maximum(1,WS_ms,FP2,False,False)
Average (1,Amb_Temp,FP2,False)
EndTable

This table should average all values obtained during each hour (scan interval 10 seconds).

No comes the question, how do I access the averaged data? i want to send it via RS232 to a sat modem. The compile gives me an error message when I try to use the variable "Amb_Temp_Avg" which is compiler generated but not defined in the source code.

Thx a mil for any advice
CTS


Dana Jun 7, 2010 04:22 PM

Hello CTW,

Refer to the Help file under Data Table Access. You can use a field from a table with Tablename.Fieldname; e.g.,

Myvar=Table1.amb_temp_avg

Regards,

Dana


Sam Jun 7, 2010 04:51 PM

It sounds like I recently worked on something similar. This might help get you started.

'Purpose:
' An attempt is made to package and send any new records saved to the datatable
' over serial
' Operational Notes:
' * Record sending is based on record number and not timestamps

PreserveVariables

Const Port = COMRS232
Const Baud = -9600
Const Format = 0
Public PTemp, batt_volt
Public DataHold As Boolean = FALSE 'flag for pausing data sending
Public Rec As Long 'last record number in data table
Public LRecSent As Long = -1 'last record we tried to send
Public RecBack As Long 'number of records still need to send
Const GRDataMaxLen = 127 'max length of GRData string
Public GRData As String * GRDataMaxLen 'string for holding record data

DataTable (Test,1,-1)
DataInterval (0,5,Sec,10)
Sample (1,batt_volt,FP2)
Sample (1,PTemp,FP2)
EndTable

DataTable (ComsLog,1,100)
Sample (1,Port,FP2)
Sample (1,Baud,IEEE4)
Sample (1,Format,FP2)
Sample (1,Rec,FP2)
Sample (1,LRecSent,FP2)
Sample (1,RecBack,FP2)
Sample (1,GRData,String)
EndTable

BeginProg

Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)
CallTable Test
NextScan

SlowSequence
Do While TRUE 'inifinite loop

'Get number of last record in table
'Determine how far back need to go to catch up
Rec = Test.Record 'get number of last record in table
If Rec < LRecSent Then LRecSent = -1 'What if LRecSent is preserved but datatable has been reset? Reset LRecSent.
RecBack = Rec - LRecSent 'determine how much need to catch up

If NOT DataHold Then 'not holding sending of data
SerialOpen (Port,Baud,Format,0,1000) 'open serial port
If RecBack > 0 Then 'If recback is greater than zero then we have records to send
LRecSent = Rec - RecBack + 1 'calc new last record number sent
GetRecord (GRData,Test,RecBack) 'extract data from data table
GRData = Left (GRData,InStr (2,GRData,"""",2)) & "," & Test.Record(1,RecBack) & Mid (GRData,InStr (2,GRData,"""",2) + 1,1000) & CHR(13)
SerialOut (Port,GRData,"",0,0) 'send data out over socket
CallTable (ComsLog)
EndIf 'recback
Else
SerialClose (Port)
EndIf 'datahold

Loop
EndSequence

EndProg

* Last updated by: Sam on 6/7/2010 @ 10:52 AM *

Log in or register to post/reply in the forum.