Data or DataLong, Read, Restore (Define Data, Read Data, Restore Data)
Data (or DataLong) is used to define a list of constants that can then be read (using Read) into a variable array later in the program.
Syntax
Data (or DataLong) list of constants
Read [VarExpr]
Restore
The program below uses Data to hold the data values and Read to transfer the values to variables.
Data 1, 2, 3, 4, 5 'data for x
Data 6, 7, 8, 9, 10 'data for y
Public X(5), Y(5) 'declare public variables
Dim I 'declare private variables
BeginProg
For I = 1 To 5
Read x( I ) 'Read first five constants into X array
Next I
For I = 1 To 5
Read y( I ) 'Read first five constants into Y array
Next I
EndProg
This next example uses Restore to read 1, 2, 3, 4 into both X( ) and Y( ) variables.
Data 1, 2, 3, 4 'data for x and y
Public X(4), Y(4) 'declare public variables
Dim I 'declare private variables
BeginProg
For I = 1 To 4
Read X( I ) 'Read all 4 constants into X array
Next I
Restore'Reset read pointer back to the first value in the list defined by data
For I = 1 To 4
Read Y( I )'Read all 4 constants into Y array
Next I
EndProg
This third example is the same as above except that DataLong is used instead of Data.
DataLong 18987653, 2147000000, 35800, 4500000 'data for x and y
Public X(4)As Long, Y(4) As Long 'declare public variables
Dim I 'declare private variables
BeginProg
For I = 1 To 4
Read X( I ) 'Read all 4 constants into X array
Next I
Restore'Reset read pointer back to the first value in the list defined by data
For I = 1 To 4
Read Y( I )'Read all 4 constants into Y array
Next I
EndProg
The program below uses Data to hold Steinhart-Hart coefficients and Read to transfer the values to variables.
' 2-wire half-bridge thermistor measurement using BrHalf() with 10 kΩ reference resistor and Steinhart–Hart coefficients.
'Steinhart–Hart coefficients (EXAMPLE values; replace with your thermistor’s coefficients)
' 1/T(K) = A + B*ln(R) + C*(ln(R))^3
Data 1.129241E-3, 2.341077E-4, 8.775468E-8
'Reference resistor (ohms) in the BrHalf
Data 10000
'Calibration/version tag (Long)
DataLong 20260219
Public BattV, PTemp
Public Ratio 'BrHalf Dest: Vmeas/Vexc (dimensionless)
Public Rt_Ohm 'thermistor resistance (ohms)
Public ThermT_K, ThermT_C
Public A, B, C
Public Rref_Ohm
Public CalID As Long
Dim lnR As Float
DataTable (Therm_1Min, True, -1)
DataInterval (0, 1, Min, 10)
Sample (1, CalID, Long)
Sample (1, Rt_Ohm, FP2)
Sample (1, ThermT_C, FP2)
EndTable
BeginProg
'Load constants
Read A
Read B
Read C
Read Rref_Ohm
'Read calibration tag
Read CalID
Scan (1, Sec, 0, 0)
Battery (BattV)
PanelTemp (PTemp, 15000)
BrHalf (Ratio, 1, mv5000C, U1, U5, 1, 2500, True, 0, 15000, 1.0, 0)
'-------------------------------------------------------
' Convert ratio from BrHalf -> thermistor resistance:
' Ratio = Vnode/Vexc = Rt_Ohm / (Rref_Ohm + Rt_Ohm)
' Rt_Ohm = Rref_Ohm * Ratio / (1 - Ratio)
'-------------------------------------------------------
If (Ratio > 0) AND (Ratio < 0.999999) Then
Rt_Ohm = Rref_Ohm * Ratio / (1 - Ratio)
Else
Rt_Ohm = NAN
ThermT_C = NAN
EndIf
'Steinhart–Hart conversion
If Rt_Ohm > 0 Then
lnR = Log(Rt_Ohm)
ThermT_K = 1.0 / (A + B*lnR + C*lnR*lnR*lnR)
ThermT_C = ThermT_K - 273.15
EndIf
CallTable Therm_1Min
NextScan
EndProg
Remarks
The Data statement is used to define a list of floating point constants. The DataLong statement is used to define a list of Long constants. Each constant in the list is separated by a comma. Data and DataLong can also use expressions if those expressions evaluate to a constant.
The Read statement is used to begin reading constants from the list defined by Data or DataLong into a variable array. A subsequent Read picks up where the last Read left off. The Read function does not assume a data type; therefore, it is up to the user to ensure that the variable/variable array into which the constants are loaded is the correct type (Float or Long).
The Restore statement is used to reset the location of the Read pointer back to the first value in the list defined by Data or DataLong. The next Read following Restore will begin with the first value of the data list.