This command sets the scaling values used in the MARPOSS_ACQUIRE command. The raw value read in the MARPOSS_ACQUIRE command is converted into a new scaled value based on the four values from this command. The scaling values are used to map the analog output (the actual values) of the gage to a scaled value. You must use this command before using the device. If you modify the device setup, you must rescale the device.
Syntax
MARPOS_SCALING low_raw_value, low_scale_value, high_raw_value, high_scale_value
Example
This command does not return a value.
These are the default scaling values:
MARPOSS_SCALING -505, -505, 505, 505
Remarks
If the raw values are -505 and 505, and the scaling values ares are 0 to 100 (MARPOSS_SCALING -505, 0, 505, 100), then a raw value of 0 (the midpoint of the raw values) results in a return value of 50 when using the MARPOSS_ACQUIRE command:
return_value = 100 - ((505 – raw_value) / (505 – -505) * (100 – 0))
thus, return_value = 100 – (505 / 1010 * 100) = 100 – 50 = 50
Note: The values shown in cell B1 in the following table may be hardcoded into a template (as in this example of a template) or read from each standard's StdVars. If using the StdVar command to access the values, you must used the VAL command to convert the StdVar into a number.
Cell |
Formula |
Explanation |
A1 |
DE_OPT 14, 12 : Marposs_Connect "EasyBox", 1, 1 |
The DE_OPT command turns on screen components used later. Then connect to the "EasyBox" driver using Channel 1 and input bit 1 |
B1 |
MyNvar "low_scale_value" = 0 : MyNvar "high_scale_value" = 100 | Set the low and high scale values |
C1 |
Marposs_Scaling -505, MyNvar "low_val", 505, MyNvar "high_val" |
Scale the device using low and high raw and scale values |
D1 |
MyNvar "MinScale" = 9999 : MyNvar "MaxScale" = -9999 : MyNvar "MinRaw" = 9999 : MyNvar "MaxRaw" = -9999 | Initialize some variables to store minimum and maximum values read and calculated from device |
E1 |
Nvar 1 = Marposs_Acquire | Acquire a reading from the device. |
F1 |
Svar 1 = Concat Format Nvar 1, "0.00000", " raw value = ", CStr MyNvar "MarpossRaw" | Build a string of the scale and raw values read from the device |
G1 |
MyNvar "MinScale" = Min MyNvar "MinScale", Nvar 1: MyNvar "MaxScale" = Max MyNvar "MaxScale", Nvar 1 | Set the minimum and maximum scale values |
H1 |
MyNvar "MinRaw" = Min MyNvar "MinRaw", MyNvar "MarpossRaw" : MyNvar "MaxRaw" = Max MyNvar "MaxRaw", MyNvar "MarpossRaw" | Set the minimum and maximum raw values |
I1 |
Display_Part Concat "Min value = ", Format MyNvar "MinScale", "0.00000", " Max value = ", Format MyNvar "MaxScale", "0.00000" | Display the minimum and maximum scale values |
J1 |
Display_Desc Concat "Min raw = ", CStr MyNvar "MinRaw", " Max raw = ", CStr MyNvar "MaxRaw" | Display the minimum and maximum raw values |
K1 |
Timer_Delay 0, 0, 1, 0, 4, -1, -1 : Goto [E1] : Svar 1 | Display the reading values and then delay for a second before taking another reading |
Note: This template is in a loop that will not exit. To exit the template, press the F8 key while the template is waiting to acquire a reading in cell E1. Pressing F8 stops the template from processing commands. Once the template is stopped, click the File, Close menu. |