Example Using No Python Modules or Functions
Problem Definition
In this example, we want to perform gross error detection on a signal "Signal"
and clip the values to a range between 0 and 600.
Expression
0 if Signal.value<0 else (600 if Signal.value>600 else Signal.value)
Python Datatype | Name | Description | |
---|---|---|---|
Expression Inputs | SingleFloat | Signal | Represents the signal value. |
Expression Result | SingleFloat | Not Applicable | Represents the resulting expression value, with extreme outliers clipped. |
Python Modules to Import for this Expression
None
(Only modules contained on the list of supported modules are available for this expression.)
Constructing the JSON
"script":"0 if Signal.value<0 else (600 if Signal.value>600 else Signal.value)", "parameters":[
{
"name":" Signal",
"source":{"address":"Simulation00001", "dataType":"SingleFloat"}
}
]
}
Note that the address
parameter is stipulated in the context of the chosen collector, which must be on the list of collectors supporting Python Expression Tags.
In this example, we have used the Simulation Collector. Your collector might use a different source address.
{"script":"0 if Signal.value < 0 else (600 if Signal.value > 600 else Signal.value)","parameters":
[{"name":"Signal","source":{"address":"Simulation00001",dataType":"SingleFloat"}}]}
Adding the Expression Tag to Historian
For this example, we choose to add a Python Expression tag to the Historian using the File Collector to import a CSV file. (We could also have added the tag via the Historian Excel Add-In.)
[Tag]
Tagname,CollectorName,CalcType,SourceAddress,DataType,DescriptionGEDSignalTag,SimulationCollector,PythonExpr,
"{""script"":""0 if Signal.value < 0 else (600 if Signal.value > 600 else Signal.value)"",""parameters"":
[{""name"":""Signal"",""source"":{""address"":""Simulation00001"",""dataType"":""SingleFloat""}}]}",
SingleFloat,Python Expression Tag example
- The
CalcType
header is included and set toPythonExpr
. - The
Source Address
is set to the minified JSON created in the previous step. - The
CollectorName
is set toSimulationCollector
, which is a Simulation Collector. Your collector might be called by a different name. - The quotation marks within the JSON string are escaped with other quotation marks.
We then import the file, following the instructions specified in File Collector.