Sutron Corporation 8310 & 7310 Users Manual 8800-1125Rev. 2.7 (BETA) 4/16/2014 pg. 199
SetPort Port, 115200, 0, 8, 0, 1 ' 115200,N,8,1,h/w
SetTimeout Port, 1.0
FlushInput Port
NumBytes = WriteB(Port, POLL_CMD, Len(POLL_CMD))
NumBytes = ReadB(Port, Response, 100)
If Err = 0 Then
sr.Data = Response
sr.Quality = "G"
End If
Close Port
Else
ErrorMsg "RS232: Port open failed"
End If
INPUT_RS232 = sr
End Function
Example 5. Custom Processing Step
Basic allows custom processing steps to be created that can be applied to any input or output.
The step can only be a function of a single input and may only produce a single output, however
other values may be incorporated in to the step by accessing tags or making direct readings. For
instance, this step can be used to adjust a Wind Direction sensor by applying a compass
correction:
REM Compass.bas – accepts a wind speed as the input
REM and returns the speed corrected for compass bearing
REM
REM Sensor reading fields we can change include:
REM .Time, .Name, .Data, .Quality,
REM .Units, .Alarm, and .Digits
REM
Public Function PROC_Compass(i1)
o1 = i1
REM Assume the compass is connected up to input AIO1
REM and produces 0V = 0 deg, and 5V = 360 deg
CompassReading = Ad(1,1) / 5.0 * 360.0
o1.Data = i1.Data + CompassReading
REM Correct for a direction above 360 deg
If (o1.Data > 360) Then
o1.Data = o1.Data - 360
End If
PROC_Compass = o1
End Function
Example 5. Custom Measurement
Basic allows custom measurements to be created that can be added and scheduled by the user
to run on a periodic interval. They are implemented as public subroutines that begin with
“MEAS_”. They are added and scheduled just like standard measurements using the Station
Setup/Measurements menu. Custom measurements do not currently accept inputs or provide
outputs, but this does not mean they can’t perform I/O. For example, this measurement can be
used to take an A/D reading and log it:
REM Sample1.bas – take an A/D reading and log it.
Public Sub MEAS_Sample1
A=Ad(1,1)
Result = 1.2*A^2 - 0.5*A + 2
Open "Data.log" For Log As #1
Log #1, Now, "Analog1", Result, "G", "Volts"