Adding Attribute Getter and Setter Functions
Using the IVI standard attribute accessor functions to manipulate driver attributes can be cumbersome for users. For example, consider the following code required to get the value of a RESOLUTION_BANDWIDTH attribute:
auto status = acme4301_SetAttributeViReal64(session, VI_NULL, ACME4301_ATTR_RESOLUTION_BANDWIDTH, 1.5E6);
Not only is the above code tedious, it is error prone. For instance, there is no compile-time verification of the parameters supplied to any of the accessor functions. The user must know from the driver documentation that the RESOLUTION_BANDWIDTH attribute is of type ViReal and that the SetAttributeViReal64 must then be used. Additionally, the user must know that the RESOLUTION_BANDWITH attribute is not associated with any particular repeated capability, and, as such, the value VI_NULL must be supplied for the second parameter to the SetAttributeViReal64 call. If the user makes a mistake, there is no indication at compile time. Only at runtime will the error be revealed.
To provide a much more convenient and less error-prone mechanism for manipulating IVI-C attributes, Nimbus can automatically generate and implement type-safe attribute getter and setter functions that wrap the calls to the attribute accessors, such as the SetAttributeViReal64 call above.
For example, the setter function for the RESOLUTION_BANDWIDTH attribute above would look like the following:
auto status = acme4301_SetResolutionBandwidth(session, 1.5E6);
The above function is simpler, type safe, clearer to read, and much easier for the user to type. In editors such as the Visual Studio code editor, which offers IntelliSense support when typing, the attribute setter above is far easier to type, as the user can simply begin typing resolu and the SetResolutionBandwith function (as well as the corresponding GetResolutionBandwith function) will appear in the completion list. In contrast, the attribute accessors, such as SetAttributeViReal64 require the user to type enough text to bring up the SetAttributeViReal64 suggestion, and then they must continue typing until the third parameter and attempt to get IntelliSense to suggestion a value for the attribute ID (ACME4301_ATTR_RESOLUTION_BANDWIDTH).
Attribute getter and setter functions are automatically generated when the applicable options are enabled on the Features Page of the Driver Settings Editor. There, getter function generation and setter function generation can be enabled and configured separately. Function generation can be enabled or disabled at any point in driver development, and the desired prefix for the getter and setter functions can also be changed at any time.
Nimbus automatically implements the attribute getter and setter functions by delegating to the appropriate attribute accessor (e.g. SetAttributeViReal64. The getter and setter function signatures are also completely managed by Nimbus. For instance, when a parameter is added or removed or a parameter data type or direction is changed, the associated IVI-C getter and setter functions are updated appropriately. The same holds true for attributes that are associated with a repeated capability -- Nimbus will add or remove a repeated capability selector parameter to the attribute getter and setter functions as appropriate for the attribute in question.
In addition to controlling getter and setter function generation at the project level, Nimbus allows control on a per-attribute basis. Individual getter and setter functions can simply be deleted in the normal fashion. To restore a deleted getter or setter function, simply right-click on the attribute in question, and execute the Create Getter Funtion command or the Create Setter Function command, as appropriate.
Individual getter and setter functions can also be renamed if it is desirable in certain cases to deviate from the name created automatically based on the project-level selections on the Features Page of the Driver Settings Editor.
To make bulk changes to the getter and setter functions across the driver, use the Synchronize Code button on the Features Page of the Driver Settings Editor. Based on the selections made in the resulting dialog, getter and setter functions will be added, removed, and renamed as desired.
Download a complete CHM version of this documentation here.