Constructing the JSON Configuration
About this task
It is easier to edit your JSON in the Historian Excel Add-In, which you will use later to add the tag to Historian, see Adding a Python Expression Tag to Historian.
The JSON needs to be minified
and it needs to conform to a particular structure. Example of JSON containing a Python Expression in "Minified" format
{"imports":["math"],"script":"temp.value +
math.pow(10,temp.value/70)","parameters":[{"name":"temp","source":{"add
Beautifiedformat. The highlighted entries are placeholders.
{
"imports":["<imported_module0>", "<imported_module1>",
"<imported_module2>",...], "script":"<python_expression>",
"parameters":[
{
"name":"<variable_name>", "source":{"address":"<source_address>",
"dataType":"<datatype_of_parameter_value_field>"}
},...
]
}
After "imports"
, list the Python modules you need to import for your Python expression. See Supported Python Modules.
After "script"
, enter the python expression that you created in Constructing a Python Expression.
Parameter | Description |
---|---|
name | The variable name you gave to the object representing the raw data which will be pre-processed by the expression you created. This variable is exposed in the Python script as an object with the following properties: value , is_quality_good , is_quality_bad , timestamp . |
address | The source address used by the collector to access the raw data. This parameter is stipulated in the context of the chosen collector, which must be on the list of collectors supporting Python Expression Tags. |
dataType | The datatype of the \value field for the variable representing the raw data. This allows the Python expression to know the data type on which it is operating.The datatype options are: |
Example of JSON containing a Python Expression in Beautified
format
{
"imports":["math"],
"script":"temp.value+math.pow(10,temp.value/70)",
"parameters":[{"name":"temp","source":
{"address":"Simulation00001","dataType":"SingleFloat" } } ]
}
It is important to check that your JSON is valid, since no validation will be performed on the JSON at tag creation.
Minified JSON
Once you have constructed this JSON, you need to format it as a minified
string, so that it can be processed in later steps. Minified JSON has no newline characters or comments. There are tools which can help you minify JSON.
{"imports":["math"],"script":"temp.value + math.pow(10,temp.value/70)","parameters":
[{"name":"temp","source":{"address":"Simulation00001","dataType":"SingleFloat"}}]}
Pay attention to escape characters in your JSON. If your JSON contains a \ character, you need to escape it. So, \ becomes \\ (since \ is used to escape another \).