Example - Adding New Attributes and Functions
- Updated2023-02-21
- 8 minute(s) read
This example shows how to add new attributes and functions to the instrument driver as follows:
- A Hold Enable attribute that selects whether to enable the hold capability
- A Hold Threshold attribute that specifies how stable the signal must be for the Fluke 45 to take a new measurement
- A high-level Configure Hold function
The hold feature enables the Fluke 45 to take a new measurement only when it detects a stable input signal
Adding the Hold Enable Attribute
Complete the following steps to add the Hold Enable attribute.
- Select Tools»IVI Development»Edit IVI Specific Driver Attributes to launch the Attribute Editor.
- Select Configuration Information.
- Click Add Group to create a group for the new attributes.
- Enter the following information in the Edit Group dialog box.
- Enter Hold Modifier in the Name control.
- Enter the following text in the Description control.
This group contains attributes that control the DMM Hold Modifier. The Hold Modifier configures the DMM to take a new measurement only when the input signal is stable and 'hold' that measurement on the display. This feature can be particularly advantageous in difficult or hazardous circumstances when you might want to keep your eyes fixed on the probes, and then read the display when it is safe or convenient to do so.
- Click OK to return to the Edit Driver Attributes dialog box. Click Add Attribute to create a new attribute. Enter the following information in the Edit Attribute dialog box.
- Enter HOLD_ENABLE in the Constant Name control.
- Enter Hold Enable in the Descriptive Name control.
- Select ViBoolean from the Data Type ring control.
- Enter VI_FALSE in the Default Value control.
- Enter the following text in the Description control.
Specifies whether to enable the hold function modifier. This modifier configures the DMM to take a new measurement only when the input signal is stable and 'hold' that measurement on the display. - Click in the left margin of the Callbacks list box control next to the Read Callback and Write Callback entries to create read and write callbacks for the attribute.
- Click OK to return to the Edit Driver Attributes dialog box.
- Click Apply to apply the changes.
- Right-click the HOLD_ENABLE attribute and select Go To Write Callback.
- Enter the following code for the FL45AttrHoldEnable_WriteCallback function.
static ViStatus _VI_FUNC FL45AttrHoldEnable_WriteCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViBoolean value) {
ViStatus error = VI_SUCCESS;
if (value)viCheckErr (viPrintf (io, "HOLD;"));
else
viCheckErr (viPrintf (io, "HOLDCLR;"));
Error:
return error;
}
- Save the source file.
- Select Tools»IVI Development»Edit IVI Specific Driver Attributes to return to the Edit Driver Attributes dialog box.
- Right-click the HOLD_ENABLE attribute and select Go To Read Callback.
- Enter the following code for the FL45AttrHoldEnable_ReadCallback function.
static ViStatus _VI_FUNC FL45AttrHoldEnable_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViBoolean *value)
{ViStatus error = VI_SUCCESS;
ViInt32 modebyte;
viCheckErr (viPrintf (io, "MOD?;"));
viCheckErr (viScanf (io, "%ld", &modebyte));
if (modebyte & 0x04)*value = VI_TRUE;
else
*value = VI_FALSE;
Error:
return error;
}
- Save the source file.
Adding the Hold Threshold Attribute
Complete the following steps to add the Hold Threshold attribute.
- Select Tools»IVI Development»Edit IVI Specific Driver Attributes to launch the Attribute Editor.
- Select the HOLD_ENABLE attribute.
- Click Add Attribute to create a new attribute.
- Enter the following information in the Edit Attribute dialog box:
- Enter HOLD_THRESHOLD in the Constant Name control.
- Enter Hold Threshold in the Descriptive Name control.
- Select ViInt32 from the Data Type ring control.
- Click New to create a range table for the attribute.
- Enter the following information for the range table:
- Enter attrholdThresholdRangeTable in the Range Table Name control.
- Select ViInt32 from the Data Type ring control.
- Select Discrete from the Table Type ring control.
- Enter the information in the following table for the range table entries.
Range Table Entry Information
Discrete Actual CmdStr Help Text FL45_VAL_HOLD_VERY_STABLE 0 "1" Very Stable Input (5% of range) FL45_VAL_HOLD_STABLE 1 "2" Stable Input (7% of range) FL45_VAL_HOLD_NOISY 2 "3" Noisy Input (8% of range)

Note You can insert FL45_VAL_ into the Discrete Value control automatically by placing the cursor in the control and pressing <F4>. - Click OK to return to the Edit Attribute dialog box.
- Complete the dialog box with the following information:
- Enter FL45_VAL_HOLD_STABLE in the Default Value control.
- Enter the following text in the Description control.
This attribute specifies the Hold Measurement Threshold. The DMM takes a new measurement only when the input signal is as stable as you specify with this attribute.
This attribute affects instrument behavior only when you set the FL45_ATTR_HOLD_ENABLE attribute to VI_TRUE. - Click in the left margin of the Callbacks list box control next to the Read Callback and Write Callback entries to create read and write callbacks for the attribute.
- Click OK to return to the Edit Driver Attributes dialog box.
- Click Apply to apply the changes.
- Right-click the HOLD_THRESHOLD attribute and select Go To Write Callback.
- Enter the following code for the FL45AttrHoldThreshold_WriteCallback function.
static ViStatus _VI_FUNC FL45AttrHoldThreshold_WriteCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViInt32 value)
{ViStatus error = VI_SUCCESS;
ViString cmd;
checkErr (Ivi_GetViInt32EntryFromValue (value, &holdThresholdRangeTable, VI_NULL, VI_NULL, VI_NULL, VI_NULL, &cmd, VI_NULL));
viCheckErr (viPrintf ( io, "HOLDTHRESH %s;",cmd));Error:
return error;
}
- Select Tools»IVI Development»Edit IVI Specific Driver Attributes to return to the Edit Driver Attributes dialog box.
- Right-click the HOLD_THRESHOLD attribute and select Go To Read Callback.
- Enter the following code for the FL45AttrHoldThreshold_ReadCallback function.
static ViStatus _VI_FUNC FL45AttrHoldThreshold_ReadCallback (ViSession vi, ViSession io, ViConstString channelName, ViAttr attributeId, ViInt32 *value)
{ViStatus error = VI_SUCCESS;
ViChar rdbuffer[5];
viCheckErr (viPrintf ( io, "HOLDTHRESH?;"));
viCheckErr (viScanf ( io, "%s", rdbuffer));
checkErr (Ivi_GetViInt32EntryFromString (rdbuffer, &holdThresholdRangeTable, value, VI_NULL, VI_NULL, VI_NULL, VI_NULL));Error:
return error;
}
Adding the Configure Hold Function Panel
Complete the following steps to add the Configure Hold function panel.
- Select File»Open to open the fl45.fp function panel file.
- Select the Configure Freq Voltage Range function. Select Create»Function Panel Window and enter the following information:
- Enter Configure Hold Modifier in the Name control.
- Enter ConfigureHold in the Function Name control.
- Click OK to return to the Function Tree Editor.
- Complete the following steps to edit the function panel.
- Select the Configure Hold Modifier function and select Edit»Edit Function Panel Window.
- Select Edit»Function Help.
- Enter the following help text:
This function configures the DMM's Hold Modifier capability. The Hold Modifier configures the DMM to take a new measurement only when the input signal is stable and 'hold' that measurement on the display. This feature can be particularly advantageous in difficult or hazardous circumstances when you might want to keep your eyes fixed on the probes, and then read the display when it is safe or convenient to do so. - Select File»Close in the Help Editor.
- Complete the following steps to add an Instrument Handle control to the function panel.
- Press <Ctrl-Page Up> to display the Configure Freq Voltage Range function panel.
- Select the Instrument Handle control.
- Select Edit»Copy Controls.
- Press <Ctrl-Page Down> to display the Configure Hold Modifier function panel.
- Select Edit»Paste to place a copy of the Instrument Handle control on the Configure Hold Modifier panel.
- Position the Instrument Handle control in the lower left corner of the panel.
- Complete the following steps to add a control to specify whether to enable the Hold Modifier.
- Select Create»Binary.
- Complete the Create Binary Control and Edit On/Off Settings dialog boxes as shown in the following images.
- Click OK twice to return to the function panel window. Position the Hold Enable control in the upper left portion of the panel.
- Complete the following steps to add help to the Hold Enable control.
- Select the Hold Enable control and select Edit»Control Help.
- Enter the following text in the Edit Help dialog box.
Specify whether you want to enable the Hold Modifier. Setting this parameter to VI_TRUE configures the DMM to take a new measurement only when the input signal is stable and 'hold' that measurement on the display. The value you specify in the Hold Threshold parameter determines how stable the signal must be for the DMM to take a measurement.
Valid Values: VI_TRUE - Enables the Hold Modifier
VI_FALSE - Disables the Hold Modifier
Default Value: VI_FALSE - Select File»Close to return to the function panel window.
- Complete the following steps to add a control to specify the Hold Threshold parameter.
- Select Create»Slide.
- Complete the Edit Slide Control dialog box as shown in the following figure.
- Click Label/Value Pairs and complete the Edit Label/Value Pairs dialog box as shown in the following figure.
- Return to the Function Panel Editor. Position the Hold Threshold control in the upper right portion of the panel.
- Complete the following steps to add help to the Hold Threshold control.
- Select the Hold Threshold control and select Edit»Control Help.
- Enter the following text in the Help Editor dialog box.
Pass the Hold Threshold you want the DMM to use. The DMM takes a new measurement when the input signal is as stable as you specify with this parameter.
This parameter affects instrument behavior only when you set the Hold Enable parameter to VI_TRUE.
Valid Values:
FL45_VAL_HOLD_VERY_STABLE (0) - 5% of range
FL45_VAL_HOLD_STABLE (1) - 7% of range
FL45_VAL_HOLD_NOISY (2) - 8% of range
Default Value: FL45_VAL_HOLD_NOISY - Select File»Close in the Help editor.
- Complete the following steps to add a return control to indicate the status of the function.
- Press <Ctrl-Page Up> to display the Configure Freq Voltage Range function panel.
- Select the Status control.
- Select Edit»Copy Controls.
- Press <Ctrl-Page Down> to display the Configure Hold Modifier function panel.
- Select Edit»Paste to place a copy of the Status control on the Configure Hold Modifier panel.
- Position the Status control in the lower right corner of the panel.
- Select the Status return value and select Edit»Control Help and modify the text to add help to the Status control.
The Configure Hold Modifier function panel window now appears, as shown in the following figure.
Creating the Configure Hold Function Body
Complete the following steps to create the Configure Hold Function Body.
- Select File»Open»Function Tree (*.fp) to open the fl45.fp function panel file.
- Right-click the Configure Hold function to display the context menu.
- Choose the Generate Source For Function Node command in the context menu to create the function prototype in the fl45.h file and the function definition in the fl45.c file.
- Right-click the Configure Hold function and select Go To Definition from the context menu to go to the function definition in the fl45.c file.
- Enter the following code for the Configure Hold function.
/*******************************************************************
* Function: FL45_ConfigureHold
* Purpose: Configures the DMM's hold capability.
*******************************************************************/
ViStatus _VI_FUNC FL45_ConfigureHold (ViSession vi, ViBoolean holdEnable, ViInt32 holdThreshold)
{ViStatus error = VI_SUCCESS;
checkErr (Ivi_LockSession (vi, VI_NULL));
viCheckParm (Ivi_SetAttributeViBoolean (vi, VI_NULL, FL45_ATTR_HOLD_ENABLE, 0, holdEnable), 2, "Hold Enable");
if (holdEnable)viCheckParm (Ivi_SetAttributeViInt32 (vi, VI_NULL, FL45_ATTR_HOLD_THRESHOLD, 0, holdThreshold), 3, "Hold Threshold");
checkErr (FL45_CheckStatus (vi));
Error:
Ivi_UnlockSession (vi, VI_NULL);
return error;