Example 3 - Editing High-Level Instrument Driver Functions
- Updated2023-02-21
- 3 minute(s) read
This example shows how to edit the high-level instrument driver functions that the Instrument Driver Development Wizard creates.
Editing the Fetch Function
Complete the following steps to modify the Fetch function for the Fluke 45 and delete the functions that the Fluke 45 does not support:
- Select File»Open»Function Tree (*.fp) to open the fl45.fp function panel file.
- Scroll down to the Fetch function. Right-click Fetch to display the context menu and select Go To Definition from the context menu to go to the FL45_Fetch function definition in the fl45.c file.
Notice that the Instrument Driver Development Wizard has already created the FL45_Fetch function. The function contains the code for a typical implementation. The function also contains instructions on how to modify the instrument specific segments of code. In general, the modification instructions appear within comments that start with CHANGE and end with END CHANGE, in the FL45_Fetch function. The modification instructions include explanations and sample source code.
Complete the following steps to modify the code for the FL45_Fetch function.
- Change the command string in the viPrintf statement to VAL1?.
- Change the if statement that tests for over-range to the following:
if ((reading == 1000000000) || (reading == -1000000000))
- Change the comments that start with a double-slash (//) to the traditional C comment style (/*...*/).
- Delete the CHANGE and END CHANGE comment lines and the explanation text from the modification instructions.
The code appears as follows:
/*******************************************************************
* Function: FL45_Fetch
* Purpose: This function returns the measured value from a
* previously initiated measurement. This function does not
* trigger the instrument.
*
* After this function executes, the value in *readingRef
* is an actual reading or a value indicating that an
* over-range condition occurred. If an over-range
* condition occurs, the function sets *readingRef to
* FL45_VAL_OVER_RANGE_READING and returns
* FL45_WARN_OVER_RANGE.
*******************************************************************/
ViStatus _VI_FUNC FL45_Fetch (ViSession vi, ViInt32 maxTime, ViReal64 *readingRef)
{
ViStatus error = VI_SUCCESS;
ViReal64 reading;
ViBoolean overRange = VI_FALSE;
ViSession io = VI_NULL;
ViUInt32 oldTimeout;
ViBoolean needToRestoreTimeout = VI_FALSE;
checkErr (Ivi_LockSession (vi, VI_NULL));
if (readingRef == VI_NULL)
viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "Null address for Reading");
if (!Ivi_Simulating (vi))
{
io = Ivi_IOSession (vi);
checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));
/* Store the old timeout so that it can be restored later */
viCheckErr (viGetAttribute (io, VI_ATTR_TMO_VALUE, &oldTimeout)26);
viCheckErr (viSetAttribute (io, VI_ATTR_TMO_VALUE, maxTime));
needToRestoreTimeout = VI_TRUE;
viCheckErr (viPrintf (io, "VAL1?;"));
error = ( viscanf (io, "%lf", &reading));
if (error == VI_ERROR_TMO)
error = FL45_ERROR_MAX_TIME_EXCEEDED;
viCheckErr (error);
/* Test for over-range */
if ((reading == 1000000000) || (reading == -1000000000))
{
*readingRef = IVIDMM_VAL_OVER_RANGE_READING;
overRange = VI_TRUE;
}
else
{
*readingRef = reading;
}
}
else
{
ViReal64 range;
checkErr (Ivi_GetAttributeViReal64 (vi, VI_NULL, FL45_ATTR_RANGE, 0, &range));
if (range <= 0.0) /* If auto-ranging, use the max value. */
checkErr (Ivi_GetAttrMinMaxViReal64 (vi, VI_NULL, FL45_ATTR_RANGE, VI_NULL, &range, VI_NULL, VI_NULL));
*readingRef = range * ((ViReal64)rand() / (ViReal64)RAND_MAX);
}
/* Do not invoke FL45_CheckStatus here. FL45_Read invokes FL45_CheckStatus after it calls this function. After the user calls this function, the user can check for errors by calling FL45_error_query. */
Error:
if (needToRestoreTimeout)
{
/* Restore the original timeout */
viSetAttribute (io, VI_ATTR_TMO_VALUE, oldTimeout);
}
Ivi_UnlockSession (vi, VI_NULL);
if (overRange && (error >= VI_SUCCESS))
return FL45_WARN_OVER_RANGE;
else
return error;
}
Deleting Functions the Instrument Does Not Use
The Fluke 45 does not support multipoint operations. Refer to the following table for the functions you should delete from the Fluke 45.
Multipoint Operations
| Function | Function Panel Name |
|---|---|
| FL45_ReadMultiPoint | Read Multi-Point |
| FL45_FetchMultiPoint | Fetch Multi-Point |
| FL45_ConfigureMultiPoint | Configure Multi-Point |
For each of these operations, you must delete the corresponding function definition in the source file, delete the corresponding function declaration in the header file, and delete the corresponding function panel in the function panel file.
Complete the following steps to delete the functions.
- Open the function tree for the fl45.fp function panel file.
- Right-click the Configure Multipoint function to display the context menu. Select Go To Declaration to go to the function declaration in the fl45.h file.
- Delete the declaration.
- In the Source window, select Edit Function Tree from the context menu to return to the Function Tree Editor.
- Right-click the Configure Multipoint function and select Go To Definition from the context menu to go to the function definition in the fl45.c file.
- Delete the entire function body.
- In the Source window, select Edit Function Tree from the context menu to return to the Function Tree Editor.
- Select the Configure Multipoint function. Select Edit»Cut to delete the function panel.
- For each of the remaining functions, you either can repeat the steps above or make all the edits in each file at once.