How to Build an XControl
To demonstrate how you create an XControl, we will build the Dual Mode Thermometer (DMT) example program that ships with LabVIEW 8. This example program can be found at the following location or via the Example Finder utility.
<LabVIEW 8.0>\examples\general\xcontrols\Dual Mode Thermometer
Upon opening the LabVIEW Simple Dual Mode Thermometer project, the following files appear in the Project Explorer Window.
The Data ability – Simple Dual Mode Thermometer Data.ctl
The Data ability is a type definition control that specifies which type of data LabVIEW will pass into and receive from the XControl. This can only be one data type; however, more complex types such as Clusters, Waveforms, etc. may be used as the type definition.
For the purpose of this example, the data type is a double.
The State ability – Simple Dual Mode Thermometer State.ctlThe State ability is a type definition cluster that contains variables used to control the appearance and/or behavior of the X Control. It is here that a user can define all algorithms that must be applied to the data.
For the Dual Mode Thermometer example, the state has a Boolean that identifies whether or not the temperature will be displayed in Fahrenheit mode. The user can change the mode by selecting a checkbox which is part of the XControl’s facade. By default, the Fahrenheit mode is disabled.
The Init ability – Simple Dual Mode Thermometer Init.vi
This ability is used to initialize the control. It has three inputs and one output. The inputs are:
· Previous version
· Previous display
· Container state
The one output is:
· Current State
Using information gained from the three inputs a, current state is output. LabVIEW calls the Init ability when the XControl is first placed on a front panel or when a VI containing that XControl is loaded into memory. The Init ability also updates previous versions of the XControl to the latest version. When a VI containing an XControl is loaded into memory, LabVIEW calls Init and checks if the version has changed since the last time the VI was saved.
Init includes Previous Version and Previous State controls and a Current State indicator. When the version changes, Init converts the value of Previous State, which is passed in as a variant, to the new state format. The new state is passed to the Current State indicator. |