Page
219
of
248
To use the script, enable
Use Script
and set
Script Function
to the name of the Python routine that should
be invoked (in the example below, that would be
twelve_more
).
20.1.1
Twelve More Measurement Script Example
Here is an example of a measurement script:
@MEASUREMENT
def twelve_more(inval):
"""returns 12+input"""
return 12 + inval
The example script above adds twelve to the result of the sensor reading in order to provide a final
measurement result.
Let us suppose that a measurement were setup as a battery voltage reading. Let us suppose that the
current battery voltage is 13.5. If the script
twelve_more
were associated with that measurement, the
station would do the following:
Make a battery voltage reading (13.5V)
Pass the value 13.5 to script function
twelve_more
twelve_more
would run, adding 12 to 13.5 and returning a value of 25.5
The final measurement result would be 25.5.
20.1.2
Rules for Measurement Scripts
These rules must be followed when writing a script that will be referenced by the measurement:
The @MEASUREMENT decorator must be on the line preceding the Python function. The
decorator is case sensitive.
The measurement function must take in one floating point type parameter, and it must return a
float parameter.
The parameter passed to the function is the result of the sensor reading.
The parameter returned by the function is the final result of the measurement.
The function may call into any other functions in the script. Those other functions do not need to
have the @MEASUREMENT decorator.
20.1.3
Minutes of Daylight Measurement Script Example
A typical usage scenario for a measurement script is illustrated by the daylight counter. The goal of the
measurement is to count the number of minutes of daylight. A single measurement is setup with the
following details:
Measurement M1 daylight
Active = On
Label = daylight
Meas Type = Analog
Meas Interval = 00:01:00
Use Script = On
Script Function = minutes_of_daylight
And here is the script used
Summary of Contents for SUTRON XLINK 100
Page 230: ...Page 230 of 248...
Page 247: ...Page 247 of 248...