-
Notifications
You must be signed in to change notification settings - Fork 1
/
LufftWS5022Sec.cr300
204 lines (167 loc) · 6.35 KB
/
LufftWS5022Sec.cr300
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
'CR300 Series Datalogger
'Lufft WS502 connect SDI12 comms wire to C1 on datalogger
'Lufft WS502 SDI12 address is 0
'Outputs to be in the following units
'Air Temp (C)
'RH (%)
'WS (m/s)
'WD (deg)
'Solar (W/m2)
'BP (hPa)
'
SequentialMode
'User Entered Inputs
Public SaveSite 'Used to store updated values of site variables
Public Latitude 'station latitude in decimal degress
Public Longitude 'station longitude in decimal degrees
Public Altitude_m 'station altitude in meters
Public BPoffset_KPa 'Pressure offset
Public SensorH_m 'Sensor height in meters
'Measured inputs
Public BatVolt_V
Public AirTemp_C
Public RH
Public Solar_W_m2
Public Barometer_hPa
Public WindSpeed_ms
Public WindDirect_deg
Public Wind_Quality
Dim BPsealvl_KPa
Dim time(8)
'Arrays for data from Lufft sensor via SDI12 communications
Dim Meas0(5) 'Lufft array for buffer 0
Dim Meas1(4) 'Lufft array for buffer 1
Dim Meas2(4) 'Lufft array for buffer 2
Dim Meas3(3) 'Lufft array for buffer 3
Dim Meas4(3) 'Lufft array for buffer 4
Dim cnt
'DataTables
'//////////////////////User input values////////////////////////////////
DataTable (SiteVal,1,20)
Sample (1,Altitude_m,FP2)
Sample (1,Latitude,FP2)
Sample (1,Longitude,FP2)
Sample (1,BPoffset_KPa,FP2)
Sample (1,SensorH_m,FP2)
EndTable
'///////////////////////////////////////////////////////////////////////
'////////////////////// 2 Second Data Table//////////////////////////////
DataTable (two_sec,1,-1)
DataInterval (0,2,Sec,10)
Minimum (1,BatVolt_V,FP2,0,False)
Average (1,AirTemp_C,FP2,False)
Average (1,RH,FP2,False)
Sample (1,Barometer_hPa,IEEE4)
Average (1,Solar_W_m2,FP2,False)
Minimum (1,AirTemp_C,FP2,0,False)
Maximum (1,AirTemp_C,FP2,0,False)
WindVector (1,WindSpeed_ms,WindDirect_deg,FP2,0,0,0,1)
Average (1,Wind_Quality,FP2,False)
EndTable
'////////////////////////////////////////////////////////////////////////
'////////////////////// 10 Second Data Table//////////////////////////////
DataTable (ten_sec,1,-1)
DataInterval (0,10,Sec,10)
Minimum (1,BatVolt_V,FP2,0,False)
Average (1,AirTemp_C,FP2,False)
Average (1,RH,FP2,False)
Sample (1,Barometer_hPa,IEEE4)
Average (1,Solar_W_m2,FP2,False)
Minimum (1,AirTemp_C,FP2,0,False)
Maximum (1,AirTemp_C,FP2,0,False)
WindVector (1,WindSpeed_ms,WindDirect_deg,FP2,0,0,0,1)
Average (1,Wind_Quality,FP2,False)
EndTable
'////////////////////////////////////////////////////////////////////////
'//////////////////////60 Minute Data Table//////////////////////////////
DataTable (sixty_min,True,-1)
DataInterval (0,60,Min,10)
Average (1,AirTemp_C,FP2,False)
Average (1,RH,FP2,False)
Sample (1,Barometer_hPa,IEEE4)
Average (1,Solar_W_m2,FP2,False)
WindVector (1,WindSpeed_ms,WindDirect_deg,FP2,0,0,0,1)
Average (1,Wind_Quality,FP2,False)
EndTable
'///////////////////////////////////////////////////////////////////////
'/////////////////24 Hour Data Table (7 a.m.)///////////////////////////
DataTable (Daily_7am,True,500)
DataInterval (7,24,Hr,10)
Maximum (1,AirTemp_C,FP2,False,True)
Minimum (1,AirTemp_C,FP2,0,True)
Maximum (1,WindSpeed_ms,FP2,0,True)
Average (1,Wind_Quality,FP2,False)
EndTable
'///////////////////////End Data Tables///////////////////////////////
'//////////////////////Begin Program//////////////////////////////////
BeginProg
'Initialize Values (unitialized values are zero)
'unitialized variables are SaveSite, Raindaily_mm,RainReset,SnowReset
Latitude=0.00001
Longitude=Latitude
Altitude_m=Latitude
BPoffset_KPa=Latitude
SW12 (1)
'//////////////////////////Begin Scan//////////////////////////////////////
cnt=0
Scan (2,sec,0,0) '5 second scan rate
Battery (BatVolt_V)
'Save Site Values
If SaveSite = 1 Then
CallTable SiteVal
SaveSite=0
EndIf
'Query Site Values from data table and use if needed'
If Latitude = 0.00001 AND SiteVal.Latitude(1,1)<> NAN Then
Latitude=SiteVal.Latitude(1,1)
Longitude=SiteVal.Longitude(1,1)
Altitude_m=SiteVal.Altitude_m(1,1)
BPoffset_KPa=SiteVal.BPoffset_KPa(1,1)
SensorH_m=SiteVal.SensorH_m(1,1)
EndIf
'using altitude, calculate Barometric Pressure offset to adjust BP to sealevel
'Sea Level Correction dP(KPa)=101.325*(1-(1-elev(m)/44307.69231)5.25328)
'for Logan UT, elev=1355 m, dP(KPa)=15.254
BPsealvl_KPa = 101.32*(1-(1-(Altitude_m/44307.69231))^5.25328) 'calculate sealevel adjustment
'Get SDI12 data from Lufft WS600
SDI12Recorder (Meas0(),1,0,"R0!",1,0)
SDI12Recorder (Meas1(),1,0,"R1!",1,0)
SDI12Recorder (Meas2(),1,0,"R2!",1,0)
SDI12Recorder (Meas3(),1,0,"R3!",1,0)
SDI12Recorder (Meas4(),1,0,"R4!",1,0)
'Wind Speed/Direction Measurements
If Meas3(1)<>NAN Then
WindDirect_deg = Meas3(1)
EndIf
If Meas2(1)<>NAN Then
WindSpeed_ms = Meas2(1)
EndIf
Wind_Quality = Meas2(4)
'Air temperature Measurement
If Meas0(1)<>NAN Then
AirTemp_C = Meas0(1)
EndIf
'Relative Humidity Measurement
If Meas0(2)<>NAN Then
RH = Meas0(2)
EndIf
'Barometer Measurement
If Meas0(3)<>NAN Then
Barometer_hPa = Meas0(3)
EndIf
'Add offsets and sea level adjust
Barometer_hPa= Barometer_hPa + BPsealvl_KPa + BPoffset_KPa
'Solar Radiation Measurement
If Meas1(2)<>NAN Then
Solar_W_m2 = Meas1(2)
EndIf
'Never let the RH reading be above 100%
RH=IIF(RH>100,100,RH) 'saves 6bytes over if then endif
'Call output tables
'Get Rainyearly_mm from final storage
CallTable ten_sec
CallTable two_sec
CallTable sixty_min
CallTable Daily_7am
NextScan
EndProg