Definition level
-
Carry out the following steps in the project file:
-
Create two internal variables of the data type "VT_I2" by selecting the project explorer node VariablesWChannelsWInternal. Open the table editor for the "Internal" channel by double-clicking on the node. Select the table editor with a mouse click and insert the two variable definitions by pressing the F8 key. Change the names of the two variables to "DistanceSensorAdaptionSwitch" and "DistanceSensorExtendedSwitch".
-
Create a variable-dependent unit class. To do this, go to the VariablesWEunitclassesWvariable-dependent node in the project explorer. Press the F8 key directly in the project explorer to create a new definition. Enter "DistanceSensorAdaption" as the name and "DistanceSensorAdaptionSwitch" as the switching variable on the properties pages.
-
Create a second variable-dependent unit class. Enter "LengthConversionExtended" as the name and "DistanceSensorExtendedSwitch" as the switching variable.
-
Select the node of the "DistanceSensorAdaption" unit class and insert a new unit definition with the following parameters in the table editor:
Parameters
Value
X1
0
X2
1
Y1
0
Y2
1
-
Insert a second unit definition with the following parameters into the "DistanceSensorAdaption" unit class:
Parameters
Value
X1
0
X2
12599
Y1
0
Y2
16000
-
In the project explorer, switch to the "LengthConversionExtended" unit class and insert a new unit definition with the following parameters in the table editor:
Parameters
Value
X1
0
X2
16000
Y1
0
Y2
100
-
Add a second unit definition with the following parameters to the "LengthConversionExtended" unit class:
Parameters
Value
Switching identifier
1
X1
0
X2
16000
Y1
0
Y2
39,37
Unit text
in
-
Add a third unit definition with the following parameters to the "LengthConversionExtended" unit class:
Parameters
Value
Switching identifier
2
X1
0
X2
16000
Y1
0
Y2
16000
Unit text
mm
-
Add the fourth required unit definition with the following parameters to the "LengthConversionExtended" unit class:
Parameters
Value
Switching identifier
3
X1
0
X2
16000
Y1
0
Y2
39370
Unit text
mil
-
Create a language-dependent unit class. To do this, go to the VariableWEinitialisation classesLanguage-dependent node in the project explorer. Press the F8 key directly in the project explorer to create a new definition. Change the name of the unit class to "LengthConversion".
-
Select the node of the "LengthConversion" unit class and insert a new unit definition with the following parameters in the table editor:
Parameters
Value
Switching identifier
German (1031)
X1
0
X2
16000
Y1
0
Y2
1000
Unit text
cm
-
Add the second required unit definition with the following parameters to the "LengthConversion" unit class:
Parameters
Value
Switching identifier
English (1033)
X1
0
X2
16000
Y1
0
Y2
39,37
Unit text
in
-
Browse the variable to be converted into your project. To do this, add a new communication channel of the type "VisiWin(.NET) driver" via the VariablesWChannels project explorer node. Specify the "Sample driver" in the Driver name parameter. Open the browser dialogue via the context menu entry Browse variables... of the newly added driver channel node. Select the DataTypesWReal variable here and confirm your selection by clicking OK.
-
Rename the variable to "RawValue" using the Alias parameter.
-
Duplicate the variable. To do this, select the Duplicate entry in the context menu of the definition in the table editor.
-
Change the alias of the variable copied in this way to "SensorIndependent" and select the definition "DistanceSensorAdaption" via the property pages in the parameter Unit class (process).
-
Duplicate the variable definition "SensorIndependent" and enter the name "SensorIndependent_Lng" as the alias. Specify "LengthConversion" as the "Unit class (display)".
-
Duplicate the variable definition "SensorIndependent" once again and enter the name "SensorIndependent_Ext" as the alias. Specify "LengthConversionExt" as the "Unit class (display)".
The ItemID is identical for the four variable definitions. This means that the visualisation accesses the same value in the communication component across all variable definitions.
Why this complex approach?
If a variable value is converted via a unit class (process) between the communication component and the variable server, the raw value from the communication component is no longer available anywhere. The only way to bypass the conversion of the unit class (process) in the view is to define a second variable that does not use a unit class (process) but accesses the same variable in the communication component. To show the conversion in the application, the following steps (see Design) also implement the non-converted value as a display value in the application.