'ATS1.CR1 'CR1000 Series 'Created by Short Cut (4.0) 'Modified by Joel Bailey '3-20-2019 '8/16/2022 - Changed to allow external AT/RH sensor, changed SR50A measure to use external AT sensor, added camera on/off control ConstTable Const PAKBUS_INFO = 386 Const PB_MODL = "CS106" Const PB_SN = "xxx" Const PB_UNITS = "mBar" Const PB_MULT = 0.24 Const PB_OFS = 500 Const PB__SE = 1 Const PB_EN__CP = 3 Const SR50_MODL = "SR50A" Const SR50_SN = "xxx" Const SR50__CP = 1 Const RH_RELAY_CP = 2 Const RH_MODL = "HC2S3" Const RH_SN = "XX" Const RH_MULT = 0.1 Const RH_OFS = 0 Const AT_MULT = 0.1 Const AT_OFS = -50 Const AT_SE = 3 Const RH_SE = 4 Const CAM_TRIG_CP = 6 Const CAM_MODL = "CCFC" Const CAM_SN = "XXX" Const CAM_COM_CP = Com4 Const CAM_PWR_CP = 4 Const CAM_ON_MIN = 57 Const CAM_OFF_MIN =3 Const CAM_PERIOD = 60 Const CAM_V_LIM = 12.0 EndConstTable 'Declare Variables and Units Public progSig As Long Public Battery Public PTemp_C Public SW12State As Boolean Public SW12_2State As Boolean Public Pb Public AT Public RH 'Single measured values. Public SR50A_M(2) Alias SR50A_M(1) = MDT : Units MDT = meters 'Distance from the SR50AT. Alias SR50A_M(2) = MQ : Units MQ = unitless 'Quality number. 'Array to hold 11 SR50AT measurements composed of a distance and 'quality number, and air temperature. Public SR50A(11,2) 'Sorted array of 11 SR50AT measurements composed of a distance and 'quality number, and temperature. Measurements are sorted by the 'distance value from smallest to largest. Public Result_SR50A(11,2) Public TCDT : Units TCDT = meters 'Temperature corrected distance Public Q : Units Q = unitless 'Quality number Public Inital_Dist = 100 : Units Inital_Dist = meters 'Distance to ground. Public Stage : Units Stage = meters 'water stage 'Controls SR50AT measurement. This flag can be manually controlled to 'run tests in the field or is automatically set 2 minutes before the 'hourly data storage interval. This is done so 11 measurements can 'be made and sorted before the values are stored. Public SR50ACtrl As Boolean 'Set this flag to measure and store the initial distance from the 'SR50AT to the ground. Public SR50A_MID As Boolean Dim n 'used as a counter Units Battery=Volts Units PTemp_C=Deg C Units Pb=mbar Units AT=Deg C Units RH=% 'Define Data Tables DataTable(Hydro,True,-1) DataInterval(0,15,Min,10) Sample(1,progSig,uint2) Sample(1,AT,FP2) Average(1,AT,FP2,False) Sample(1,TCDT,FP2) Sample(1,Q,FP2) Sample(1,Stage,IEEE4) Average(1,Stage,IEEE4,False) Average(1,Pb,FP2,False) Sample(1,Pb,FP2) EndTable DataTable(HrlyDiag,True,-1) DataInterval(0,60,Min,10) Sample(1,progSig,uint2) Sample(1,Battery,FP2) Average(1,Battery,FP2,False) Average(1,PTemp_C,FP2,False) EndTable 'Main Program BeginProg ' for camera communication SerialOpen(CAM_COM_CP,115200,4,0,1000) ' for base: progSig = status.ProgSignature n=1 'Main Scan Scan(60,Sec,1,0) 'Default CR1000X Datalogger Battery Voltage measurement 'BattV' Battery(Battery) 'Default CR1000X Datalogger Wiring Panel Temperature measurement 'PTemp_C' PanelTemp(PTemp_C,15000) 'H2SC3 (panel switched power) Temperature & Relative Humidity Sensor measurements 'AT' and 'RH' PortSet(RH_RELAY_CP,1) Delay(0,3,Sec) VoltSe(AT,1,mV2500,AT_SE,True,0,250,AT_MULT,AT_OFS) VoltSe(RH,1,mV2500,RH_SE,True,0,250,RH_MULT,RH_OFS) PortSet(RH_RELAY_CP,0) If RH>100 AND RH<103 Then RH=100 'Automated Water stage measurement. Must occur two minutes before 'actual storage time to get 11 measurements completed. If TimeIntoInterval (3,15,Min) Then SR50ACtrl = True EndIf 'Set this flag to true to get the initial distance from the SR50AT 'to the ground. If SR50A_MID Then SR50ACtrl = True 'Logic to make 11 water stage measurements, sort them, and store 'the corrected values. If SR50ACtrl Then 'SR50A Sonic Ranging Sensor (SDI-12 Output) measurements 'MDT, MQ, & MAir SDI12Recorder(SR50A_M(),SR50__CP,"0","M1!",1,0) 'Load the array to be sorted. SR50A(n,1) = SR50A_M(1)*SQR((AT+273.15)/273.15) SR50A(n,2) = SR50A_M(2) n += 1 If n > 11 Then n = 1 SR50ACtrl = False SortSpa (Result_SR50A(1,1),11,SR50A(1,1),2) TCDT = Result_SR50A(6,1) Q = Result_SR50A(6,2) If SR50A_MID Then Inital_Dist = TCDT SR50A_MID = False EndIf Stage = Inital_Dist - TCDT EndIf EndIf 'CS106 Barometric Pressure Sensor measurement 'Pb' If TimeIntoInterval(59,60,Min) Then PortSet(PB_EN__CP,1) If TimeIntoInterval(0,60,Min) Then VoltSe(Pb,1,mV5000,PB__SE,True,0,15000,PB_MULT,PB_OFS) PortSet(PB_EN__CP,0) EndIf 'SW12 Timed Control 'Turn ON SW12 between 0000 hours and 2359 hours If TimeIsBetween(59,10,60,min) Then SW12State=True 'Turn OFF SW12 only if time runs out and ComRS232 is not active ElseIf (ComPortIsActive(ComRS232)=False) Then SW12State=False EndIf 'Always turn OFF SW12 if battery drops below 12.2 volts If Battery<12.2 Then SW12State=False 'Set SW12 to the state of 'SW12State' variable SW12(SW12State) 'SW12 Timed Control for CCFC Camera 'Turn ON SW12 between CAM_ON_MIN and CAM_OFF_MIN If TimeIsBetween(CAM_ON_MIN,CAM_OFF_MIN,CAM_PERIOD,Min) Then SW12_2State=True Else SW12_2State=False EndIf 'Always turn OFF SW12 if battery drops below MODM_V_LIM volts If Battery