Item Scaling
Overview
All protocol modules support the scaling of item values. This allows client applications to view or change data based on calculated formula instead of raw device data. Any item can be scaled, with the exception of Boolean (bit) and String items. After scaling the original item data type will be changed to Double.
Scaling Parameter Syntax
To scale an item, attach a string designating the Scaling Parameters to the OPC item name. Each scaling method has a unique scaling identifier (the first parameter in the string), and the remaining parameters are used in the calculation. Each method is explained further below:
The Gain/Offset Scaling ‘SG’ is used if no scaling identifier is given inside of the appended string. If the format of the scaling string is incorrect, e.g., too few or too many parameters, no scaling will be applied.
Linear Scaling (SL)
ItemName{SL:LR:HR:LE:HE}
ItemName is any valid item.
SL is the linear scale identifier and must appear after the open bracket
LR is the low raw value (LoRaw)
HR is the high raw value (HiRaw)
LE is the low engineering value (LoEGU)
HE is the high engineering value (HiEGU)
Validate that HR is greater than LR, and HE is greater than LE.
Below is SL formula used to calculate scaled data after reading from device:
Scaled = (Raw-LoRaw)/(HiRaw-LoRaw)*(HiEGU-LoEGU)+LoEGU
Example: Device1.40001{SL:0:4095:0:100}
If device returns raw value 1000 the scaled value should be:
Scaled = (1000 - 0)/(4095 - 0)*(100 - 0) + 0 = 24.42
This sample shows how the raw data of 1000 was calculated with SL formula to generate the result of 24.42.
Below is SL formula used to calculate raw data before sending to device:
Raw = (Scaled-LoEGU)/(HiEGU-LoEGU)*(HiRaw-LoRaw)+LoRaw
Example: Device1.40001{SL:0:4095:0:100}
If a scaled value of 60 was written to the device then the actual data written to the device will be:
Raw = (60 - 0)/(100 - 0)*(4095 - 0) + 0 = 2457
The above sample shows how the scaled value of 60 is written to the device as actual raw value of 2457.
Note
It is possible to lose data precision due to data type conversion.
Square Root Scaling (SQ)
ItemName{SQ:LR:HR:LE:HE}
ItemName is any valid item.
SQ is the square root scale identifier and must appear after the open bracket
LR is the low raw value (LoRaw)
HR is the high raw value (HiRaw)
LE is the low engineering value (LoEGU)
HE is the high engineering value (HiEGU)
Validate that HR is greater than LR, and HE is greater than LE.
Below is the SQ formula used to calculate scaled data after reading from device:
Scaled = SQRT((Raw-LoRaw)/(HiRaw-LoRaw))*(HiEGU-LoEGU)+LoEGU
Example: Device1.40002{SQ:0:4095:0:100}
If device returns raw value 1000 the scaled value should be:
Scaled = SQRT((1000 - 0)/(4095 - 0))*(100 - 0) + 0 = 49.42
This sample shows how the raw data of 1000 was calculated with the SQ formula to generate the result of 49.42.
Below is the SQ formula used to calculate raw data before sending to device:
Raw = ((Scaled-LoEGU)/(HiEGU–LoEGU))^2*(HiRaw-LoRaw)+LoRaw
Example: Device1.40002{SQ:0:4095:0:100}
If a scaled value of 60 was written to the device then the actual data written to the device will be:
Raw = ((60 - 0)/(100 - 0))^2*(4095 - 0) + 0 = 1474.2
Above sample shows how the scaled data of 60 being written to device as actual raw value of 1474.2.
Note
It is possible to lose data precision due to data type conversion.
Gain/Offset Scaling (SG)
ItemName{SG:Gain:Offset}
ItemName is any valid item
SG is the gain/offset scale identifier and must appear after the open bracket
Gain is a multiplier
Offset is an addition
Validate that Gain is not zero.
Below is the SG formula used to calculate scaled data after reading from device:
Scaled = Raw * gain + offset
Example: Device1.40003{SG:2.5:1}
If the device returns raw value of 1000 the scaled value should be:
Scaled = 1000 * 2.5 + 1 = 2501
This sample shows how the raw data of 1000 was calculated with the SG formula to generate the result of 2501.
Below is the SG formula used to calculate raw data before sending to device:
Raw = (Scaled - offset) / gain
Example: Device1.40003{SG:2.5:1}
If a scaled value of 60 was written to the device then the actual data written to the device will be:
Raw = (60 - 1)/2.5 = 24.4
The above sample shows how the scaled data of 60 was written to the device as actual raw value of 24.4.
Note
It is possible to lose data precision due to data type conversion.
Gain/Offset Scaling without Identifier
This works the same way as Gain/Offset Scaling (SG), it just doesn’t include an identifier in the brackets.
For example, Device1.40003{2.5:1} is scaled the same way as Device1.40003{SG:2.5:1}.
Inverse Scaling (SI)
ItemName{SI:Inverse} or {SI}
Validate that Item raw value is not zero!
ItemName is any valid item
SI is the inverse scale identifier and must appear after the open bracket
Inverse is a divider. The default inverse is 1, making {SI} the same as {SI:1}.
Below is the SI formula used to calculate scaled data after reading from device:
Scaled = Inverse/Raw
Example: Device1.40003{SI:2}
If the device returns a raw value of 1000 the scaled value should be:
Scaled = 2/1000 = 0.002
This sample shows how the raw data of 1000 was calculated with the SI formula to generate the result of 0.002.
Below is the SI formula used to calculate raw data before sending to device:
Raw = (1/Scaled) * Inverse
Example: Device1.40003{SI:2}
If a scaled value of 0.5 was written to the device then the actual data written to the device will be:
Raw = (1/0.5) * 2 = 4
The above sample shows how the scaled data of 0.5 was written to the device as an actual raw value of 4.
Bitwise ‘AND’ Scale (BA)
ItemName{BA:Mask}
ItemName is any valid item
BA is the bitwise AND identifier and must appear after an open bracket
Mask is the mask to use for scaling, and should be between 1 and 2,147,483,647 (0x7FFFFFFF)
Below is the BA formula used to calculate scaled data after reading from device:
Scaled = BA AND Mask
Example: Device1.40003{BA15}
If the device returns a raw value of 1000 the scaled value should be:
Scaled = 1000 AND 15 = 8
For assistance, please submit a ticket via our Support Portal, email autosol.support@autosoln.com or call 281.286.6017 to speak to a support team member.