User-Defined Data Types
You also can define data types and use them in function panels. You must declare user-defined data types in the function panel file of an instrument driver, and you must define the data type in the include file for the driver. Declare user-defined data types with the Data Types option in the Function Panel Editor.
For example, you can define a waveform_var data type for an instrument driver to represent waveform data. This waveform_var data type could be a structure that contains an array of doubles to represent the individual points in the waveform, a float for the time of the first point, and a float for the time between points.
Creating a User-Defined Data Type
Complete the following steps to create a user-defined data type for use in a function panel.
- Define the data type with a typedef statement in the instrument driver header file.
Using the previous example of the waveform_var data type, include the following code in the include file for the instrument driver.
typedef struct {
double waveform_arr [500];
float t_zero;
float t_delta;
} waveform_var; - Add the data type to the instrument driver function panel file using the Options»Data Types command in the Function Panel Editor.
Make the waveform_var data type available in the function panel file. Select Options»Data Types in the Function Panel Editor and enter waveform_var in the Type box of the Edit Data Type List dialog box. Click Add.
Now you can select the waveform_var data type when you create function panel controls for this instrument driver. Also, users can interactively declare a variable of waveform_var data type from any function panel control that you define as waveform_var.
User-Defined Array Data Types
Use care when you declare user-defined data types that are arrays. If you want to define a user-defined array data type, square brackets [] must appear at the end of the type name in the Edit Data Type List dialog box. The brackets enable the interactive variable declaration and other capabilities of LabWindows/CVI function panels. For example, to declare an array of waveform_var type from the preceding example, add waveform_var [] in the Type box of the Edit Data Type List dialog box and include the typedef declaration for waveform_var in the driver include file. This example is correct because it includes brackets.
The following examples show incorrect ways to define user-defined array data types.
Assume the following data type definitions are in an instrument driver header file.
typedef waveform_var * waveform_arr1;
typedef waveform_var waveform_arr2[100];
The following data type declarations in the Edit Data Type List dialog box are incorrect.
waveform_var * (This example is incorrect because it lacks brackets.)
waveform_arr1 (This example is incorrect because it lacks brackets.)
waveform_arr2 (This example is incorrect because it lacks brackets.)