B-1
Appendix B. Example Programs
B.1 CR1000X Program for Measuring 15 Temperature
Sensors
In this example, a CS230/CS231 is connected to control terminal 1 on a
CR1000X. The CS230/CS231 includes 15 sensors with SDI-12 addresses 1
through 9 and A through F. Every 60 s, the
aR0!
command polls each
temperature sensor, then the data is stored in a table. Other common station
data is measured every 60 seconds and stored to a daily data table.
CRBasic Example B-1. CR1000X Program for Reading CS230/CS231 with 15 Sensors
'CR1000X Series Datalogger
'This program reads a CS230/CS231 probe that has 15 temperature Sensors
'Declare Public Variables
Public
PTemp, batt_volt
'Enter the number of temperature sensors that are in the probe (will need to be
'adjusted to fit specific application)
Const
NumTempSensors=15
'Uses the control terminal C1 on the CR1000X
Const
SDI12_Port=C1
Public
TempC(NumTempSensors)
As
Float
Dim
i
As
Long
'Define Data Tables
DataTable
(Daily,1,-1)
DataInterval
(0,1440,Min,10)
Minimum
(1,batt_volt,FP2,0,False)
Maximum
(1,batt_volt,FP2,0,False)
Average
(1,batt_volt,FP2,0)
Minimum
(1,PTemp,FP2,0,False)
Maximum
(1,PTemp,FP2,0,False)
Average
(1,PTemp,FP2,0)
EndTable
DataTable
(TempSample,1,-1)
DataInterval
(0,60,Sec,10)
Sample
(NumTempSensors,TempC(),IEEE4)
EndTable
'Define Subroutines
'*****************************************************************************
'* ------------------------- ConvertSDI12addr() -------------------------- *
'* Convert SDI-12 character address (0->9, A->Z, and a->z) to number value *
'* (0->61). *
'*****************************************************************************
Function
ConvertSDI12addr(address
As
Long
) As
String
* 1
Select
Case
address
Case
0
To
9
'ASCII Code 48->57 = 0->9
Return
(
CHR
(a 48))
Case
10
To
35
'ASCII Code 65->90 = A->Z = 10->35
Return
(
CHR
(a 55))
Case
36
To
61
'ASCII Code 97->122 = a->z = 36->61
Return
(
CHR
(a 61))