I have modified some data logger code I found online to log data with a CR1000X from an RM Young 81000 3D sonic anemometer. I have the instrument setup to output data at 20 Hz.
If I log data at 10 Hz, the code I pasted below works perfectly. If I change the instrument output rate to 20 Hz, change the scan interval to 50 ms, and then double the serial buffer size, I end up with NaNs for approximately 1 out of every 3 scans.
Does anyone have any thoughts on what I need to do to this code in order to be able to log output at 20 Hz (and eventually 32 Hz)? Thanks in advance for any insight!
-Amato
' Begin Code
PipeLineMode
Const SCAN_INTERVAL = 100 'Scan interval is 10 Hz = 100 ms.
Const SERIAL_BUFF_SIZE = 37*(Ceiling (20*SCAN_INTERVAL/1000))+37+1
Const NMBR_BYTES_EXPCTD = 36 'Length of the data record (37), less the EndWord (&h0D).
Public sonic(6)
Alias sonic(1) = diagnostic
Alias sonic(2) = wspd
Alias sonic(3) = az
Alias sonic(4) = elev
Alias sonic(5) = sspd
Alias sonic(6) = temp
Units diagnostic = arb
Units wspd = m/s
Units sspd = m/s
Units az = deg
Units elev = deg
Units temp = C
Public WSStr As String * NMBR_BYTES_EXPCTD
Dim nmbr_bytes_rtrnd As Long
DataTable(RMY81000v1,1,-1)
DataInterval(0,0,Sec,0) 'save time stamp for every measurement
Sample(1,wspd,FP2)
Sample(1,az,FP2)
Sample(1,elev,FP2)
Sample(1,temp,FP2)
Sample(1,sspd,FP2)
EndTable
BeginProg
SerialOpen (ComC5,38400,3,0,SERIAL_BUFF_SIZE)
Scan (SCAN_INTERVAL,mSec,3,0)
SerialInRecord(ComC5,WSStr,0,NMBR_BYTES_EXPCTD,&h0D,nmbr_bytes_rtrnd,01)
SplitStr(sonic(),WSStr,"",6,0)
CallTable(RMY81000v1)
NextScan
EndProg
Using the watch mode in the terminal of the data logger is a useful tool. The video below shows how to watch an SDI-12 sensor, but you can use the same terminal mode to watch data coming from the wind sensor.
https://www.campbellsci.com/videos/sdi12-sensors-watch-or-sniffer-mode
It is common to have an occassional NaN when a serial sensor is set to output at the same rate as the data logger scan. If the sensor's internal clock is a bit slow, you would get fewer data lines output than expected. Missing 1 out of 3 would be an extreme clock issue, and unlikely. Normal expectation from clock differences can be a few seconds worth of data per day.
OK, thanks. I'll check this out. It just seems like there should be a simple solution since I get no NaNs when logging at 10 Hz.
With the sensor set to output at 20Hz and the logger scanning at 10Hz, expect two data lines in the serial buffer of the data logger each scan. So, any timing mismatch is not an issue. A slow internal clock in the sensor would mean occassionally the data logger would only have 1 data line in the buffer instead of 2.