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.

how to test multiple copies of same type of sensor


tjwilli_58 Aug 27, 2024 12:21 AM

I'm trying to compare 3 WXT520 sensors and a WXT536 all-in-one weather sensor. I have a program running on a CR1000 that collects data from either sensor using a serial rs-232 connection. The CR1000 has 4 COM ports available, so I can use Com1, Com2, Com3, Com4 to talk to these. I was thinking about creating 4 tables, one for each sensor, but how to handle the variables?


For example, I guess I need 4 copies of variables like this? (one for each sensor) 

(snippets of program for one WXT520 - I may have copy/pasted things in the wrong order)

 

DataTable(WxData,True,-1)
  DataInterval(0,5,Min,10)
  ' copied from CSI Forum post
  ' UTC and Local Data tables simultaneously
  ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
  Sample (1,TmStamp_UTC,Nsec)

  Average(1,AirTemp,FP2,False)
  Maximum(1,AirTemp,FP2,False,False)
  Minimum(1,AirTemp,FP2,False,False)
  Average(1,RH,FP2,False)
  Maximum(1,RH,FP2,False,False)
  Minimum(1,RH,FP2,False,False)
  Average(1,Pressure,FP2,False)
  Maximum(1,Pressure,FP2,False,False)
  Minimum(1,Pressure,FP2,False,False)
  Average(1,DewPt,FP2,False)
  Maximum(1,DewPt,FP2,False,False)
  Minimum(1,DewPt,FP2,False,False)
  Average(1,Windchill,FP2,False)
  Average(1,HeatIndex,FP2,False)
  Average(1,FeelTemp,FP2,False)    'GET THE AVERAGE REAL FEEL TEMPERATURE

  Average (1,WindSpdAvg,FP2,False)
  Average (1,WindDirAvg,FP2,False)
  Maximum(1,WindSpdMax,FP2,False,False)     'GET THE MAXIMUM WINDSPEED
  FieldNames("WindGst")                'RENAME THE VARIABLES

 
EndTable



'These are set so COM ports only have to be changed in one place in the code.
Const wxtCOM = Com4
Const wxtAddr = 1 'Set device address for WMT52, WXT520 here so it can be changed easily

Public Message_Pressure As String *30
Public PressureStr As String *30
Public PressureResult(3)
Alias PressureResult(1) = AirTemp
Alias PressureResult(2) = RH
Alias PressureResult(3) = Pressure
Public DewPt              'THIS IS THE DEWPOINT TEMPERATURE
'UNITS P=H,T=C
Units AirTemp = Deg C
Units RH = %
Units Pressure = hPa
Units DewPt = Deg C        'DEWPOINT UNITS ARE DEGREES CELSIUS

BeginProg

  'THIS OPENS UP THE SERIAL PORT FOR THE WXT520 TO COMMUNICATE THROUGH.  THEN WE SET UP THE VisMessage.
  SerialOpen (wxtCOM,19200,0,100,1000)

  Message_Pressure = "R2"+CHR(13)+CHR(10)

  'WE GO AHEAD AND SCAN THROUGH THE SENSORS.
  Scan(5,Sec,1,0)

    'GET THE PRESSURE DATA
    SerialFlush(wxtCOM)
    SerialOut(wxtCOM,wxtAddr + Message_Pressure,0,0,10)
    SerialIn(PressureStr,wxtCOM,50,-1,100)
    SplitStr(PressureResult(1),PressureStr,"=",3,6)
 
CallTable WxData
NextScan EndProg

 


Thanks for any help.


tjwilli_58 Aug 27, 2024 02:44 PM

Looking through CRBasic help. I think the example program for the Dim and Public instructions may help.


mercedesdear Aug 28, 2024 07:45 AM

Create a unique table for each sensor (e.g., WxData1, WxData2, WxData3, and WxData4). This way, the data from each sensor is stored separately, which is crucial for comparison.


JDavis Aug 28, 2024 02:47 PM

Most people choose to store the data for the sensors they want to compare in the same table. It makes it easier post processing, because you only have to open one data file. You do have the option of creating separate tables for each sensor. The data logger allows creating a large number of tables, however you wish.

That example program you show is grabbing the pressure data by itself. I recommend setting the all-in-one to output a format with all the values you want in a single message. It will make getting values out faster. I know the manual for the WXT series is a challenge to read, but you can customize the output a lot.


tjwilli_58 Aug 30, 2024 05:38 PM

I basically did use 4 tables. I was going back and forth on using 4 basically identical tables, or making one big table. I also had to have 4 copies of the varialbles, but what I was hoping for was to have something like a subroutine with the comPortt being an argument.

Here's what I ended up with:

 

'Modified from test520.cr1 and POL_Yard.cr3
' 3x WXT520, 1x WXT536

'VAISALA WXT520 WEATHER TRANSMITTER

'WIRING INFORMATION
'WHITE = C1
'BLUE = C2
'CLEAR/GREEN/PINK = G
'BROWN/YELLOW = 12V

'These are set so COM ports only have to be changed in one place in the code.
'Const wxtCOM = Com4
Const wxtAddr = 0 'Set device address for WMT52, WXT520 here so it can be changed easily
Const MPH = 0.44703999999999994 'MPH in m/s

' copied from CSI Forum post
' UTC and Local Data tables simultaneously
' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
Public UTCOffset As Long
Public TmStamp_UTC As Long
Units TmStamp_UTC = TS

'Public WXTMessage As String *30   'MESSAGE WE SEND TO WXT520 TO REQUEST DATA
'Public WXTString As String *250   'MESSAGE SENT BACK BY WXT520 WITH WX DATA

Public Message_Wind As String *30  'THIS IS THE TEXT STRING WE SEND WMT50 TO REQUEST DATA
Public WindStr As String *120    'THIS IS THE TEXT STRING FROM THE WMT50 WITH ALL THE DATA
Public WindResult(4,6)  'THIS ARRAY HOLDS EACH PIECE OF WIND DATA ONCE WINDSTR IS PARSED OUT
Alias WindResult(1,1) = WindDirMin1: Units WindDirMin1 = Deg      'MINIMUM WIND DIRECTION
Alias WindResult(1,2) = WindDirAvg1: Units WindDirAvg1 = Deg       'AVERAGE WIND DIRECTION
Alias WindResult(1,3) = WindDirMax1: Units WindDirMax1 = Deg       'MAXIMUM WIND DIRECTION
Alias WindResult(1,4) = WindSpdMin1: Units WindSpdMin1 = m/s      'MINIMUM WIND SPEED
Alias WindResult(1,5) = WindSpdAvg1: Units WindSpdAvg1 = m/s      'AVERAGE WIND SPEED
Alias WindResult(1,6) = WindSpdMax1: Units WindSpdMax1 = m/s       'MAXIMUM WIND SPEED
Alias WindResult(2,1) = WindDirMin2: Units WindDirMin2 = Deg      'MINIMUM WIND DIRECTION
Alias WindResult(2,2) = WindDirAvg2: Units WindDirAvg2 = Deg       'AVERAGE WIND DIRECTION
Alias WindResult(2,3) = WindDirMax2: Units WindDirMax2 = Deg       'MAXIMUM WIND DIRECTION
Alias WindResult(2,4) = WindSpdMin2: Units WindSpdMin2 = m/s      'MINIMUM WIND SPEED
Alias WindResult(2,5) = WindSpdAvg2: Units WindSpdAvg2 = m/s      'AVERAGE WIND SPEED
Alias WindResult(2,6) = WindSpdMax2: Units WindSpdMax2 = m/s       'MAXIMUM WIND SPEED
Alias WindResult(3,1) = WindDirMin3: Units WindDirMin3 = Deg      'MINIMUM WIND DIRECTION
Alias WindResult(3,2) = WindDirAvg3: Units WindDirAvg3 = Deg       'AVERAGE WIND DIRECTION
Alias WindResult(3,3) = WindDirMax3: Units WindDirMax3 = Deg       'MAXIMUM WIND DIRECTION
Alias WindResult(3,4) = WindSpdMin3: Units WindSpdMin3 = m/s      'MINIMUM WIND SPEED
Alias WindResult(3,5) = WindSpdAvg3: Units WindSpdAvg3 = m/s      'AVERAGE WIND SPEED
Alias WindResult(3,6) = WindSpdMax3: Units WindSpdMax3 = m/s       'MAXIMUM WIND SPEED
Alias WindResult(4,1) = WindDirMin4: Units WindDirMin4 = Deg      'MINIMUM WIND DIRECTION
Alias WindResult(4,2) = WindDirAvg4: Units WindDirAvg4 = Deg       'AVERAGE WIND DIRECTION
Alias WindResult(4,3) = WindDirMax4: Units WindDirMax4 = Deg       'MAXIMUM WIND DIRECTION
Alias WindResult(4,4) = WindSpdMin4: Units WindSpdMin4 = m/s      'MINIMUM WIND SPEED
Alias WindResult(4,5) = WindSpdAvg4: Units WindSpdAvg4 = m/s      'AVERAGE WIND SPEED
Alias WindResult(4,6) = WindSpdMax4: Units WindSpdMax4 = m/s       'MAXIMUM WIND SPEED

Public Message_Pressure As String *30
Public PressureStr As String *30
Public PressureResult(4,3)
Alias PressureResult(1,1) = AirTemp1: Units AirTemp1 = Deg C
Alias PressureResult(1,2) = RH1: Units RH1 = %
Alias PressureResult(1,3) = Pressure1: Units Pressure1 = hPa
Alias PressureResult(2,1) = AirTemp2: Units AirTemp2 = Deg C
Alias PressureResult(2,2) = RH2: Units RH2 = %
Alias PressureResult(2,3) = Pressure2: Units Pressure2 = hPa
Alias PressureResult(3,1) = AirTemp3: Units AirTemp3 = Deg C
Alias PressureResult(3,2) = RH3: Units RH3 = %
Alias PressureResult(3,3) = Pressure3: Units Pressure3 = hPa
Alias PressureResult(4,1) = AirTemp4: Units AirTemp4 = Deg C
Alias PressureResult(4,2) = RH4: Units RH4 = %
Alias PressureResult(4,3) = Pressure4: Units Pressure4 = hPa

Public DewPt(4)              'THIS IS THE DEWPOINT TEMPERATURE
Alias DewPt(1) = Dewpt1: Units Dewpt1 = Deg C
Alias DewPt(2) = Dewpt2: Units Dewpt2 = Deg C
Alias DewPt(3) = Dewpt3: Units Dewpt3 = Deg C
Alias DewPt(4) = Dewpt4: Units Dewpt4 = Deg C
'
'THESE ARE VARIABLE USED TO DETERMINE HEAT INDEX, WINDCHILL, AND REAL-FEEL TEMPERATURES
'DECLARE VARIABLES
Dim WindSpdMaxMPH
Public HeatIndex(4)
Alias HeatIndex(1) = HeatIndex1: Units HeatIndex1 = Deg F          'THIS IS THE HEAT INDEX
Alias HeatIndex(2) = HeatIndex2: Units HeatIndex2 = Deg F
Alias HeatIndex(3) = HeatIndex3: Units HeatIndex3 = Deg F
Alias HeatIndex(4) = HeatIndex4: Units HeatIndex4 = Deg F

Public Windchill(4)
Alias Windchill(1) = Windchill1: Units Windchill1 = Deg F          'THIS IS THE WINDCHILL
Alias Windchill(2) = Windchill2: Units Windchill2 = Deg F
Alias Windchill(3) = Windchill3: Units Windchill3 = Deg F
Alias Windchill(4) = Windchill4: Units Windchill4 = Deg F

Public FeelTemp(4)
Alias FeelTemp(1) = FeelTemp1: Units FeelTemp1 = Deg F           'THIS IS THE REAL FEEL TEMP.
Alias FeelTemp(2) = FeelTemp2: Units FeelTemp2 = Deg F
Alias FeelTemp(3) = FeelTemp3: Units FeelTemp3 = Deg F
Alias FeelTemp(4) = FeelTemp4: Units FeelTemp4 = Deg F

Public AirTempF: Units AirTempF = Deg F


'UNITS P=H,T=C


Public Message_Rain As String *30
Public RainStr As String *120
Public RainResult(4,8)
Alias RainResult(1,1) = RainAmount1: Units RainAmount1 = mm
Alias RainResult(1,2) = RainDuration1: Units RainDuration1 = s
Alias RainResult(1,3) = RainIntensity1: Units RainIntensity1 = mm/h
Alias RainResult(1,4) = HailAmount1: Units HailAmount1 = hits/cm²
Alias RainResult(1,5) = HailDuration1: Units HailDuration1 = s
Alias RainResult(1,6) = HailIntensity1: Units HailIntensity1 = hits/cm²h
Alias RainResult(1,7) = RainPeak1: Units RainPeak1 = mm/h
Alias RainResult(1,8) = HailPeak1: Units HailPeak1 = hits/cm²h
Alias RainResult(2,1) = RainAmount2: Units RainAmount2 = mm
Alias RainResult(2,2) = RainDuration2: Units RainDuration2 = s
Alias RainResult(2,3) = RainIntensity2: Units RainIntensity2 = mm/h
Alias RainResult(2,4) = HailAmount2: Units HailAmount2 = hits/cm²
Alias RainResult(2,5) = HailDuration2: Units HailDuration2 = s
Alias RainResult(2,6) = HailIntensity2: Units HailIntensity2 = hits/cm²h
Alias RainResult(2,7) = RainPeak2: Units RainPeak2 = mm/h
Alias RainResult(2,8) = HailPeak2: Units HailPeak2 = hits/cm²h
Alias RainResult(3,1) = RainAmount3: Units RainAmount3 = mm
Alias RainResult(3,2) = RainDuration3: Units RainDuration3 = s
Alias RainResult(3,3) = RainIntensity3: Units RainIntensity3 = mm/h
Alias RainResult(3,4) = HailAmount3: Units HailAmount3 = hits/cm²
Alias RainResult(3,5) = HailDuration3: Units HailDuration3 = s
Alias RainResult(3,6) = HailIntensity3: Units HailIntensity3 = hits/cm²h
Alias RainResult(3,7) = RainPeak3: Units RainPeak3 = mm/h
Alias RainResult(3,8) = HailPeak3: Units HailPeak3 = hits/cm²h
Alias RainResult(4,1) = RainAmount4: Units RainAmount4 = mm
Alias RainResult(4,2) = RainDuration4: Units RainDuration4 = s
Alias RainResult(4,3) = RainIntensity4: Units RainIntensity4 = mm/h
Alias RainResult(4,4) = HailAmount4: Units HailAmount4 = hits/cm²
Alias RainResult(4,5) = HailDuration4: Units HailDuration4 = s
Alias RainResult(4,6) = HailIntensity4: Units HailIntensity4 = hits/cm²h
Alias RainResult(4,7) = RainPeak4: Units RainPeak4 = mm/h
Alias RainResult(4,8) = HailPeak4: Units HailPeak4 = hits/cm²h

DataTable(WxData1,True,-1)
  DataInterval(0,1,Min,10)
  ' copied from CSI Forum post
  ' UTC and Local Data tables simultaneously
  ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
  Sample (1,TmStamp_UTC,Nsec)

  Sample (1,Status.PanelTemp,FP2)
  Average(1,AirTemp1,FP2,False)
  Maximum(1,AirTemp1,FP2,False,False)
  Minimum(1,AirTemp1,FP2,False,False)
  Average(1,RH1,FP2,False)
  Maximum(1,RH1,FP2,False,False)
  Minimum(1,RH1,FP2,False,False)
  Average(1,Pressure1,FP2,False)
  Maximum(1,Pressure1,FP2,False,False)
  Minimum(1,Pressure1,FP2,False,False)
  Average(1,Dewpt1,FP2,False)
  Maximum(1,Dewpt1,FP2,False,False)
  Minimum(1,Dewpt1,FP2,False,False)
  Average(1,Windchill1,FP2,False)
  Average(1,HeatIndex1,FP2,False)
  Average(1,FeelTemp1,FP2,False)    'GET THE AVERAGE REAL FEEL TEMPERATURE

  Average (1,WindSpdAvg1,FP2,False)
  Average (1,WindDirAvg1,FP2,False)
  Maximum(1,WindSpdMax1,FP2,False,False)     'GET THE MAXIMUM WINDSPEED
'  FieldNames("WindGst1")                'RENAME THE VARIABLES

  Average(1,RainAmount1,FP2,False)  'get average rain over Interval
  Sample(1,RainDuration1,UINT2)
  Sample(1,RainIntensity1,FP2)
  Average(1,HailAmount1,FP2,False)
  Sample(1,HailDuration1,UINT2)
  Sample(1,HailIntensity1,FP2)
  Sample (1,RainPeak1,FP2)
  Sample (1,HailPeak1,FP2)

EndTable


DataTable(WxData2,True,-1)
  DataInterval(0,1,Min,10)
  ' copied from CSI Forum post
  ' UTC and Local Data tables simultaneously
  ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
  Sample (1,TmStamp_UTC,Nsec)

  Sample (1,Status.PanelTemp,FP2)
  Average(1,AirTemp2,FP2,False)
  Maximum(1,AirTemp2,FP2,False,False)
  Minimum(1,AirTemp2,FP2,False,False)
  Average(1,RH2,FP2,False)
  Maximum(1,RH2,FP2,False,False)
  Minimum(1,RH2,FP2,False,False)
  Average(1,Pressure2,FP2,False)
  Maximum(1,Pressure2,FP2,False,False)
  Minimum(1,Pressure2,FP2,False,False)
  Average(1,Dewpt2,FP2,False)
  Maximum(1,Dewpt2,FP2,False,False)
  Minimum(1,Dewpt2,FP2,False,False)
  Average(1,Windchill2,FP2,False)
  Average(1,HeatIndex2,FP2,False)
  Average(1,FeelTemp2,FP2,False)    'GET THE AVERAGE REAL FEEL TEMPERATURE

  Average (1,WindSpdAvg2,FP2,False)
  Average (1,WindDirAvg2,FP2,False)
  Maximum(1,WindSpdMax2,FP2,False,False)     'GET THE MAXIMUM WINDSPEED
'  FieldNames("WindGst")                'RENAME THE VARIABLES

  Average(1,RainAmount2,FP2,False)  'get average rain over Interval
  Sample(1,RainDuration2,UINT2)
  Sample(1,RainIntensity2,FP2)
  Average(1,HailAmount2,FP2,False)
  Sample(1,HailDuration2,UINT2)
  Sample(1,HailIntensity2,FP2)
  Sample (1,RainPeak2,FP2)
  Sample (1,HailPeak2,FP2)

EndTable


DataTable(WxData3,True,-1)
  DataInterval(0,1,Min,10)
  ' copied from CSI Forum post
  ' UTC and Local Data tables simultaneously
  ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
  Sample (1,TmStamp_UTC,Nsec)

  Sample (1,Status.PanelTemp,FP2)
  Average(1,AirTemp3,FP2,False)
  Maximum(1,AirTemp3,FP2,False,False)
  Minimum(1,AirTemp3,FP2,False,False)
  Average(1,RH3,FP2,False)
  Maximum(1,RH3,FP2,False,False)
  Minimum(1,RH3,FP2,False,False)
  Average(1,Pressure3,FP2,False)
  Maximum(1,Pressure3,FP2,False,False)
  Minimum(1,Pressure3,FP2,False,False)
  Average(1,Dewpt3,FP2,False)
  Maximum(1,Dewpt3,FP2,False,False)
  Minimum(1,Dewpt3,FP2,False,False)
  Average(1,Windchill3,FP2,False)
  Average(1,HeatIndex3,FP2,False)
  Average(1,FeelTemp3,FP2,False)    'GET THE AVERAGE REAL FEEL TEMPERATURE

  Average (1,WindSpdAvg3,FP2,False)
  Average (1,WindDirAvg3,FP2,False)
  Maximum(1,WindSpdMax3,FP2,False,False)     'GET THE MAXIMUM WINDSPEED
'  FieldNames("WindGst")                'RENAME THE VARIABLES

  Average(1,RainAmount3,FP2,False)  'get average rain over Interval
  Sample(1,RainDuration3,UINT2)
  Sample(1,RainIntensity3,FP2)
  Average(1,HailAmount3,FP2,False)
  Sample(1,HailDuration3,UINT2)
  Sample(1,HailIntensity3,FP2)
  Sample (1,RainPeak3,FP2)
  Sample (1,HailPeak3,FP2)

EndTable


DataTable(WxData4,True,-1)
  DataInterval(0,1,Min,10)
  ' copied from CSI Forum post
  ' UTC and Local Data tables simultaneously
  ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
  Sample (1,TmStamp_UTC,Nsec)

  Sample (1,Status.PanelTemp,FP2)
  Average(1,AirTemp4,FP2,False)
  Maximum(1,AirTemp4,FP2,False,False)
  Minimum(1,AirTemp4,FP2,False,False)
  Average(1,RH4,FP2,False)
  Maximum(1,RH4,FP2,False,False)
  Minimum(1,RH4,FP2,False,False)
  Average(1,Pressure4,FP2,False)
  Maximum(1,Pressure4,FP2,False,False)
  Minimum(1,Pressure4,FP2,False,False)
  Average(1,Dewpt4,FP2,False)
  Maximum(1,Dewpt4,FP2,False,False)
  Minimum(1,Dewpt4,FP2,False,False)
  Average(1,Windchill4,FP2,False)
  Average(1,HeatIndex4,FP2,False)
  Average(1,FeelTemp4,FP2,False)    'GET THE AVERAGE REAL FEEL TEMPERATURE

  Average (1,WindSpdAvg4,FP2,False)
  Average (1,WindDirAvg4,FP2,False)
  Maximum(1,WindSpdMax4,FP2,False,False)     'GET THE MAXIMUM WINDSPEED
'  FieldNames("WindGst")                'RENAME THE VARIABLES

  Average(1,RainAmount4,FP2,False)  'get average rain over Interval
  Sample(1,RainDuration4,UINT2)
  Sample(1,RainIntensity4,FP2)
  Average(1,HailAmount4,FP2,False)
  Sample(1,HailDuration4,UINT2)
  Sample(1,HailIntensity4,FP2)
  Sample (1,RainPeak4,FP2)
  Sample (1,HailPeak4,FP2)

EndTable

Sub wxtSetup()
  SerialOpen(Com1,19200,0,100,1000)
  SerialFlush(Com1)
  SerialOpen(Com2,19200,0,100,1000)
  SerialFlush(Com2)
  SerialOpen(Com3,19200,0,100,1000)
  SerialFlush(Com3)
  SerialOpen(Com4,19200,0,100,1000)
  SerialFlush(Com4)

  'WIND
  SerialOut(Com1,wxtAddr + "WU,R=1111110011111100"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com2,wxtAddr + "WU,R=1111110011111100"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com3,wxtAddr + "WU,R=1111110011111100"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com4,wxtAddr + "WU,R=1111110011111100"+CHR(13)+CHR(10),0,0,50)
  'I = 5 MEANS UPDATE EVERY 5 SECONDS
  'A = 5 MEANS DO 5 SECOND AVERAGES
  'G = 1 MEANS TRADITIONAL WIND SPEED MAX/MIN
  'U = M MEANS WIND SPEED GIVEN IN m/s
  'D = 0 MEANS DIRECTION OFFSET IS 0
  'N = W MEANS MESSAGE INCLUDES WIND SPEED AND ANGLE
  'F = 1 MEANS SAMPLE AT 1HZ
  SerialOut(Com1,wxtAddr + "WU,I=5,A=5,G=1,U=M,D=0,N=W,F=1"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com2,wxtAddr + "WU,I=5,A=5,G=1,U=M,D=0,N=W,F=1"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com3,wxtAddr + "WU,I=5,A=5,G=1,U=M,D=0,N=W,F=1"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com4,wxtAddr + "WU,I=5,A=5,G=1,U=M,D=0,N=W,F=1"+CHR(13)+CHR(10),0,0,50)

  'PRESSURE, TEMPERATURE, HUMIDITY
  SerialFlush(Com1)
  SerialOut(Com1,wxtAddr + "TU,R=1101000011010000"+CHR(13)+CHR(10),0,0,50) 'BIT 3 IS INTERNAL TEMP USED IN PRESSURE CALCULATIONS
  SerialFlush(Com1)
  SerialFlush(Com2)
  SerialOut(Com2,wxtAddr + "TU,R=1101000011010000"+CHR(13)+CHR(10),0,0,50) 'BIT 3 IS INTERNAL TEMP USED IN PRESSURE CALCULATIONS
  SerialFlush(Com2)
  SerialFlush(Com3)
  SerialOut(Com3,wxtAddr + "TU,R=1101000011010000"+CHR(13)+CHR(10),0,0,50) 'BIT 3 IS INTERNAL TEMP USED IN PRESSURE CALCULATIONS
  SerialFlush(Com3)
  SerialFlush(Com4)
  SerialOut(Com4,wxtAddr + "TU,R=1101000011010000"+CHR(13)+CHR(10),0,0,50) 'BIT 3 IS INTERNAL TEMP USED IN PRESSURE CALCULATIONS
  SerialFlush(Com4)
  'I = 5 MEANS UPDATE EVERY 5 SECONDS
  'P = H MEANS hPa (mbars)
  'T = C MEANS DEGREES CELSIUS
  SerialOut(Com1,wxtAddr + "TU,I=5,P=H,T=C"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com2,wxtAddr + "TU,I=5,P=H,T=C"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com3,wxtAddr + "TU,I=5,P=H,T=C"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com4,wxtAddr + "TU,I=5,P=H,T=C"+CHR(13)+CHR(10),0,0,50)

  'RAIN
  SerialFlush(Com1)
  SerialOut(Com1,wxtAddr + "RU,R=1111111111111111"+CHR(13)+CHR(10),0,0,50)
  SerialFlush(Com1)
  SerialFlush(Com2)
  SerialOut(Com2,wxtAddr + "RU,R=1111111111111111"+CHR(13)+CHR(10),0,0,50)
  SerialFlush(Com2)
  SerialFlush(Com3)
  SerialOut(Com3,wxtAddr + "RU,R=1111111111111111"+CHR(13)+CHR(10),0,0,50)
  SerialFlush(Com3)
  SerialFlush(Com4)
  SerialOut(Com4,wxtAddr + "RU,R=1111111111111111"+CHR(13)+CHR(10),0,0,50)
  SerialFlush(Com4)
  'I = 5 MEANS UPDATE EVERY 5 SECONDS
  'U = M MEANS METRIC PRECIPITATION UNITS (accumulation mm, duration s, intensity mm/hr)
  'S = M MEANS METRIC HAIL UNITS (accumulation mm, duration s, intensity mm/hr)
  'M = T MEANS TIME BASED - INTERVALS DEFINED IN I FIELD
  SerialOut(Com1,wxtAddr + "RU,I=5,U=M,S=M,M=T"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com2,wxtAddr + "RU,I=5,U=M,S=M,M=T"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com3,wxtAddr + "RU,I=5,U=M,S=M,M=T"+CHR(13)+CHR(10),0,0,50)
  SerialOut(Com4,wxtAddr + "RU,I=5,U=M,S=M,M=T"+CHR(13)+CHR(10),0,0,50)

EndSub

Sub DewPt_QC(DewPt, AirTemp)
  If DewPt > AirTemp OR DewPt = NAN Then DewPt = AirTemp
  DewPt = 1.8 * DewPt + 32 'convert to deg F
EndSub

Sub AirTemp_QC(AirTemp)
  If AirTemp < -53 OR AirTemp > 141 Then
    AirTemp = NAN
  EndIf
EndSub

Sub Pressure_QC(Pressure)
  If Pressure < 600 OR Pressure > 1100 Then
    Pressure = NAN
  EndIf
EndSub

Sub RH_QC(RH)
  If RH < 0 OR RH > 105 Then 'outside 5% accuracy
    RH = NAN
  ElseIf RH > 100 Then 'RH also < 105 here
    RH = 100
  EndIf
EndSub


Function CalcHeatIndex(AirTemp, RH)
  AirTempF = 1.8 * AirTemp + 32
  HeatIndex = -42.379 + 2.049*AirTempF+10.143*RH - 0.22476*AirTempF*RH
  HeatIndex = HeatIndex  - 6.8378*10^-3*AirTempF^2 - 5.4817*10^-2*RH^2
  HeatIndex = HeatIndex + 1.2287*10^-3*AirTempF^2*RH + 8.5282*10^-4*AirTempF*RH^2
  HeatIndex = HeatIndex - 1.99*10^-6*AirTempF^2*RH^2

  'HEAT INDEX = AIR TEMP IF AIR TEMP < 80F OR RH < 40% OR HEAT INDEX < AIR TEMP
  If AirTempF < 80 OR RH < 40 OR HeatIndex < AirTempF Then HeatIndex = AirTempF

  Return(HeatIndex)
EndFunction

Function CalcWindChill(AirTemp, WindSpdMax)
  AirTempF = 1.8 * AirTemp + 32
  WindSpdMaxMPH = WindSpdMax/MPH ' convert from m/s to mph
  Windchill = 35.74 + 0.6215*AirTempF - 35.75*WindSpdMaxMPH^0.16
  Windchill = Windchill + 0.4275*AirTempF*WindSpdMaxMPH^0.16

  'WINDCHILL = AIR TEMP IF WINDCHILL > AIR TEMP
  If Windchill > AirTempF Then Windchill = AirTempF

  'IF AIR TEMP > 50F OR WINDSPEED < 3 MPH THEN WINDCHILL = AIR TEMP
  If AirTempF > 50 OR WindSpdMaxMPH < 3 Then Windchill = AirTempF

  Return(Windchill)
EndFunction

Function CalcFeelTemp(AirTemp, HeatIndex, Windchill)
  AirTempF = 1.8 * AirTemp + 32
  If HeatIndex = AirTempF Then
    FeelTemp = Windchill
  Else
    FeelTemp = HeatIndex
  EndIf
  Return(FeelTemp)
EndFunction


BeginProg

  PortSet(9,1)

  'THIS OPENS UP THE SERIAL PORT FOR THE WXT520 TO COMMUNICATE THROUGH.
  Call(wxtSetup)

  'WIND
  Message_Wind = "R1"+CHR(13)+CHR(10)
  Message_Pressure = "R2"+CHR(13)+CHR(10)
  Message_Rain  = "R3"+CHR(13)+CHR(10)

  'WE GO AHEAD AND SCAN THROUGH THE SENSORS.
  Scan(5,Sec,1,0)

    ' copied from CSI Forum post
    ' UTC and Local Data tables simultaneously
    ' https://www.campbellsci.com/forum?l=thread&forum=1&tid=15941
    ' Calculate UTC offset so I get also use local time. EST is UTC-5
    UTCOffset = 5*3600-DaylightSavingUS(-1)
    TmStamp_UTC = Public.TimeStamp(1,1) + UTCOffset

    '************************************************************************
    '  WXT520 SECTION

    'GET THE WIND DATA
    SerialFlush (Com1)  'FLUSH OUT ANY OLD DATA IN THE COM PORT
    SerialOut (Com1,wxtAddr + Message_Wind,0,0,10)	'REQUEST THE DATA FROM THE METER
    SerialIn (WindStr,Com1,50,-1,100)		'RECEIVE THE DATA FROM THE METER
    SplitStr (WindResult(1,1),WindStr,"=",6,6)

    SerialFlush (Com2)  'FLUSH OUT ANY OLD DATA IN THE COM PORT
    SerialOut (Com2,wxtAddr + Message_Wind,0,0,10)	'REQUEST THE DATA FROM THE METER
    SerialIn (WindStr,Com2,50,-1,100)		'RECEIVE THE DATA FROM THE METER
    SplitStr (WindResult(2,1),WindStr,"=",6,6)

    SerialFlush (Com3)  'FLUSH OUT ANY OLD DATA IN THE COM PORT
    SerialOut (Com3,wxtAddr + Message_Wind,0,0,10)	'REQUEST THE DATA FROM THE METER
    SerialIn (WindStr,Com3,50,-1,100)		'RECEIVE THE DATA FROM THE METER
    SplitStr (WindResult(3,1),WindStr,"=",6,6)

    SerialFlush (Com4)  'FLUSH OUT ANY OLD DATA IN THE COM PORT
    SerialOut (Com4,wxtAddr + Message_Wind,0,0,10)	'REQUEST THE DATA FROM THE METER
    SerialIn (WindStr,Com4,50,-1,100)		'RECEIVE THE DATA FROM THE METER
    SplitStr (WindResult(4,1),WindStr,"=",6,6)

    'GET THE PRESSURE DATA
    SerialFlush(Com1)
    SerialOut(Com1,wxtAddr + Message_Pressure,0,0,10)
    SerialIn(PressureStr,Com1,50,-1,100)
    SplitStr(PressureResult(1,1),PressureStr,"=",3,6)

    SerialFlush(Com2)
    SerialOut(Com2,wxtAddr + Message_Pressure,0,0,10)
    SerialIn(PressureStr,Com2,50,-1,100)
    SplitStr(PressureResult(2,1),PressureStr,"=",3,6)

    SerialFlush(Com3)
    SerialOut(Com3,wxtAddr + Message_Pressure,0,0,10)
    SerialIn(PressureStr,Com3,50,-1,100)
    SplitStr(PressureResult(3,1),PressureStr,"=",3,6)

    SerialFlush(Com4)
    SerialOut(Com4,wxtAddr + Message_Pressure,0,0,10)
    SerialIn(PressureStr,Com4,50,-1,100)
    SplitStr(PressureResult(4,1),PressureStr,"=",3,6)

    'GET THE RAIN DATA
    SerialFlush(Com1)
    SerialOut(Com1,wxtAddr + Message_Rain,0,0,10)
    SerialIn(RainStr,Com1,50,-1,120)
    SplitStr(RainResult(1,1),RainStr,"=",8,6)

    SerialFlush(Com2)
    SerialOut(Com2,wxtAddr + Message_Rain,0,0,10)
    SerialIn(RainStr,Com2,50,-1,120)
    SplitStr(RainResult(2,1),RainStr,"=",8,6)

    SerialFlush(Com3)
    SerialOut(Com3,wxtAddr + Message_Rain,0,0,10)
    SerialIn(RainStr,Com3,50,-1,120)
    SplitStr(RainResult(3,1),RainStr,"=",8,6)

    SerialFlush(Com4)
    SerialOut(Com4,wxtAddr + Message_Rain,0,0,10)
    SerialIn(RainStr,Com4,50,-1,120)
    SplitStr(RainResult(4,1),RainStr,"=",8,6)

    '************************************************************************
    'CALCULATED VALUES SECTION

    'QUALITY CONTROL AIRTEMP,PRESSURE,RH
    Call AirTemp_QC(AirTemp1)
    Call AirTemp_QC(AirTemp2)
    Call AirTemp_QC(AirTemp3)
    Call AirTemp_QC(AirTemp4)

    Call Pressure_QC(Pressure1)

    Call RH_QC(RH1)

    '    'CALCULATES THE DEWPOINT
    DewPoint(Dewpt1,AirTemp1,RH1)
    DewPoint(Dewpt2,AirTemp2,RH2)
    DewPoint(Dewpt3,AirTemp3,RH3)
    DewPoint(Dewpt4,AirTemp4,RH4)
    '
    '    'QUALITY CONTROL THE DEWPOINT
    Call DewPt_QC(Dewpt1, AirTemp1)
    Call DewPt_QC(Dewpt2, AirTemp2)
    Call DewPt_QC(Dewpt3, AirTemp3)
    Call DewPt_QC(Dewpt4, AirTemp4)

    'CALCULATES THE HEAT INDEX
    HeatIndex1 = CalcHeatIndex(AirTemp1, RH1)
    HeatIndex2 = CalcHeatIndex(AirTemp2, RH2)
    HeatIndex3 = CalcHeatIndex(AirTemp3, RH3)
    HeatIndex4 = CalcHeatIndex(AirTemp4, RH4)

    'CALCULATES THE WINDCHILL
    Windchill1 = CalcWindChill(AirTemp1, WindSpdMax1)
    Windchill2 = CalcWindChill(AirTemp2, WindSpdMax2)
    Windchill3 = CalcWindChill(AirTemp3, WindSpdMax3)
    Windchill4 = CalcWindChill(AirTemp4, WindSpdMax4)

    'CHOOSE WHAT THE FEEL TEMP SHOULD BE
    FeelTemp1 = CalcFeelTemp(AirTemp1, HeatIndex1, Windchill1)
    FeelTemp2 = CalcFeelTemp(AirTemp2, HeatIndex2, Windchill2)
    FeelTemp3 = CalcFeelTemp(AirTemp3, HeatIndex3, Windchill3)
    FeelTemp4 = CalcFeelTemp(AirTemp4, HeatIndex4, Windchill4)

    'Call Data Tables and Store Data
    CallTable WxData1
    CallTable WxData2
    CallTable WxData3
    CallTable WxData4

  NextScan
EndProg

 


tjwilli_58 Aug 30, 2024 05:43 PM

I should put this in a new question, but I just tried to update my LoggerNet and the install seems to have worked, but now I get "Access denied" everytime I try to run something. 

(This was on a different computer.)


tjwilli_58 Aug 30, 2024 05:47 PM

Nevermind. I disabled my AV, and it worked. I recently changed anti-virus.

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