Attribute-Based Resource Matching
VISA can also search for a resource based on the values of the resource's attributes. The viFindRsrc() search expression is handled in two parts: the regular expression for the resource string and the (optional) logical expression for the attributes. Assuming that a given resource matches the given regular expression, VISA checks the attribute expression for a match. The resource matches the overall string if it matches both parts.
Attribute matching works by using familiar constructs of logical operations such as AND (&&), OR (||), and NOT (!). Equal (==) and unequal (!=) apply to all types of attributes, and you can additionally compare numerical attributes using other common comparators (>, <, >=, and <=).
You are free to make attribute matching expressions as complex as you like, using multiple ANDs, ORs, and NOTs. Precedence applies as follows:
- The grouping operator () in an attribute matching expression has the highest precedence.
- The NOT ! operator has the next highest precedence.
- The AND && operator has the next highest precedence.
- The OR operator || has the lowest precedence.
The following table shows three examples of matching based on attributes.
Expression | Meaning |
---|---|
GPIB[0-9]*::?*::?*::INSTR {VI_ATTR_GPIB_SECONDARY_ADDR > 0 && VI_ATTR_GPIB_SECONDARY_ADDR < 10} | Find all GPIB devices that have secondary addresses from 1 to 9. |
ASRL?*INSTR{VI_ATTR_ASRL_BAUD == 9600} | Find all serial ports configured at 9600 baud. |
?*VXI?INSTR{VI_ATTR_MANF_ID == 0xFF6 && !(VI_ATTR_VXI_LA ==0 || VI_ATTR_SLOT <= 0)} | Find all VXI instrument resources with manufacturer ID of FF6 and which are not logical address 0, slot 0, or external controllers. |
Notice that only global VISA attributes are permitted in the attribute matching expression.
The following example is similar to the finding resources example, except that it uses a regular expression with attribute matching. Notice that because only the first match is needed, VI_NULL is passed for both the retCount and findList parameters. This tells VISA to automatically close the find list rather than return it to the application.
Example
Note This example shows C source code. There is also an example in Visual Basic syntax. |
#include <stdio.h>
/* Find the first matching device and return a session to it */
status = viOpenDefaultRM(&defaultRM); /* Error initializing VISA ... exiting */ } /* Error finding resources ... exiting */ } viClose(defaultRM); } } |