SetAttrCompareCallbackViReal64

IVI Library

Ivi_SetAttrCompareCallbackViReal64

Usage

ViStatus Ivi_SetAttrCompareCallbackViReal64(ViSession vi, ViAttr attributeID, CompareAttrViReal64_CallbackPtr compareCallback);

Purpose

This function sets the compare callback function for a ViReal64 attribute. The IVI engine invokes the compare callback when comparing cache values it obtains from the instrument against new values you set the attribute to. If the compare callback determines that the two values are equal, the IVI engine does not call the write callback for the attribute.

A compare callback is useful when the instrument can return several values which you consider to have the same meaning, and you do not want to coerce the instrument value in your read callback.

When you create an attribute with Ivi_AddAttributeViReal64, the IVI engine automatically installs a default compare callback. The default callback uses the degree of precision you specify in the Compare Precision parameter to Ivi_AddAttributeViReal64. The IVI engine installs the default compare callback rather than comparing based on strict equality because of differences between computer and instrument floating point representations.

If you want to compare based on strict equality, pass VI_NULL for the Compare Callback parameter. If you set the callback to VI_NULL and subsequently call Ivi_SetAttrComparePrecision on the attribute, the IVI engine reinstalls its default compare callback.

If you want to specify your own callback function but you want to use the default compare callback within your function, you can call Ivi_DefaultCompareCallbackViReal64.

Parameters

Name Type Description
vi ViSession

The ViSession handle that you obtain from Ivi_SpecificDriverNew. The handle identifies a particular IVI session.

attributeID ViAttr

Pass the ID of an attribute for this parameter.

The include file for a specific instrument driver defines constant names for all of the user-accessible attributes that apply to the driver. This includes attributes that the IVI engine defines, attributes that the instrument class defines, and attributes that are specific to the particular instrument. Each defined constant name begins with PREFIX_ATTR_, where PREFIX is the specific instrument prefix.

For each IVI engine attribute, the specific driver include file uses the same constant name that appears in ivi.h, except that the specific instrument prefix replaces the IVI prefix. For example, ivi.h defines IVI_ATTR_CACHE, and the Fluke 45 include file, fl45.h, defines the following constant name:

#define FL45_ATTR_CACHE  IVI_ATTR_CACHE

For each instrument class attribute, the specific driver include file uses the same constant name that appears in the instrument class include file, except that the specific instrument prefix replaces the class prefix. For example, the DMM class include file, ividmm.h, defines IVIDMM_ATTR_RANGE, and fl45.h defines the following constant name:

#define FL45_ATTR_RANGE  IVIDMM_ATTR_RANGE

For each specific instrument attribute, the specific driver include file defines a constant name and assigns a value that is an offset from IVI_SPECIFIC_PUBLIC_ATTR_BASE. For example, fl45.h defines the following constant name:

#define FL45_ATTR_HOLD_THRESHOLD \ (IVI_SPECIFIC_PUBLIC_ATTR_BASE + 3L)

For each attribute that is private to an instrument driver, the instrument driver source file defines a constant name and assigns a value that is an offset from IVI_SPECIFIC_PRIVATE_ATTR_BASE. For example, hp34401a.c defines the following constant name:

#define HP34401A_ATTR_TRIGGER_TYPE \ (IVI_SPECIFIC_PRIVATE_ATTR_BASE + 1L)

compareCallback CompareAttrViReal64_CallbackPtr

Specify the compare callback function you want the IVI engine to invoke to compare a cache value you obtained from the instrument against a new value you want to set the attribute to.

The function must have the following prototype:

ViStatus _VI_FUNC Callback(ViSession vi,ViConstString repCapName,
ViAttr attributeId,
ViReal64 coercedNewValue,
ViReal64 cacheValue,
ViInt32 *result);

Set *result to a zero if coercedNewValue and cacheValue are equal. Otherwise, set *result to a non-zero value.

Note  If you want to use the Edit IVI Specific Driver Attributes dialog box to develop your instrument driver source code, retain the parameter names as shown in the prototype for the callback.

If you do not want to use a compare callback function, pass VI_NULL.

Return Value

Contains the status code that the function call returns. IVI engine functions can return error and warning values from several sets of status codes. Some status codes are unique to the IVI engine. Other status codes are the same codes that VISA Library functions return. Still others are error or warning values that functions in specific instrument drivers return. Each set of status codes has its own numeric range.

Regardless of the source of the status code, 0 always indicates success, a positive value indicates a warning, and a negative value indicates an error.

Related Topic

IVI Status Codes