Avoid writing bad quality data to IO reference
- Last UpdatedAug 06, 2024
- 2 minute read
When variables are needed to calculate an external IO value in any script, use the Graphic Custom Properties to calculate the value. Do not use scripted DIM variables.
Industrial Graphics help prevent writes of BAD values to external IO references. DIM variables in Industrial Graphic scripts do not contain quality information. They are always considered to have Good quality. If the value of a DIM variable is calculated from an IO reference that has Bad Quality, System Platform will not prevent writing the Bad value because the DIM variable has no quality and is always Good.
When a connection is being made to an external reference, such as a Compound. Block.Parameter, System Platform does not know if it is a String, Boolean, or Analog value. The reference has no value until the connection is made. The quality of this value is Bad-Initializing. It has no value and is considered as Not a Number (NaN).
Bad practice
In the case below, the script is ramping a setpoint. It is using a DIM variable to calculate the new setpoint value. There are several custom properties that are connected to IO tags. When the operator presses the ramp button, the Hi Scale connection is still initializing.
Custom Properties
|
SPT |
OPCClient_001.port.plc.i01 |
Connection is Good |
|
LSC |
OPCClient_001.port.plc.LSC |
Connection is Good |
|
HSC |
OPCClient_001.port.plc.HSC |
Connection is initializing and has no value |
Ramp Script
|
dim Temp as float; |
|
|
Temp = SPT + ((HSC-LSC) *0.05); |
HSC is still initializing and has no value yet. However, even though HSC is Bad-Initializing, since Temp is a DIM variable and not a Custom Property, Temp will have a quality of GOOD, even though it's value will be uninitialized. |
|
IF Temp < 100 Then |
|
|
SPT = Temp |
The uninitialized value will always be written to SPT |
|
ENDIF; |
Preferred Practice
Use custom properties when using IO references to calculate a temporary value and write the results to another value. Using the previous example, the DIM Temp variable is replaced with Custom Property Temp.
Custom Properties
|
SPT |
IADAS.CMP.BLK.SPT |
Connection is Good |
|
LSC |
IADAS.CMP.BLK.LSCI1 |
Connection is Good |
|
HSC |
IADAS.CMP.BLK.HCSI1 |
Connection is initializing and has no value |
|
Temp |
float |
0.0 |
Replace DIM Temp Variable with Custom Property Temp
|
Temp = SPT + ((HSC-LSC) *0.05); |
HSC has Bad Quality. The calculation passes the Bad Data Quality of HSC to custom property Temp. |
|
IF Temp < 100 Then |
|
|
SPT = Temp |
The value of Temp is not written to SPT if Temp has BAD quality. |
|
ENDIF; |