Beginning Terminology

NI-VISA

Beginning Terminology

Typical device capabilities include sending and receiving messages, responding to register accesses, requesting service, being reset, and so on. One of the underlying premises of VISA, as defined in the previous section, is to export the capabilities of the devices—independent of the interface bus—to the user. VISA encapsulates each of these abilities into a resource.

A resource is simply a complete description of a particular set of capabilities of a device. For example, to be able to write to a device, you need a function you can use to send messages—viWrite(). In addition, there are certain details you need to consider, such as how long the function should try to communicate before timing out. Those of you familiar with this methodology might recognize this approach as object-oriented (OO) design. Indeed, VISA is based on OO design. In keeping with the terminology of OO, we call the functions of these resources operations and the details, such as the timeout, attributes.

An important VISA resource is the INSTR Resource. This resource encapsulates all of the basic device functions together so that you can communicate with the device through a single resource. The INSTR Resource exports the most commonly used features of these resources and is sufficient for most instrument drivers.

Other resource classes currently supported include MEMACC, INTFC, BACKPLANE, SERVANT, and SOCKET. Most of these are specific to a given hardware interface type, and are intended for advanced programmers. You can read more about these classes in VISA Resource Types.

Returning to the message-based communication example, look at the point where the program has opened a communication channel with a message-based device. Because of interface independence, it does not matter whether the device is GPIB or VXI or of any other interface type. You want to send the identification query, *IDN?\n, to the device. Because of the possibility that the device or interface could fail, you want to ensure that the computer will not hang in the event that the device does not receive the string. Therefore, the first step is to tell the resource to time out after 5 s (5000 ms):

status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 5000);

This sets an attribute (VI_ATTR_TMO_VALUE) of the resource. From this point on, all communication to this resource through this communication channel (instr) will have a timeout of 5 s. As you become more experienced with VISA, you will see more of the benefits of this OO approach. But for now, you can see that you can set the timeout with an operation (function) in a manner similar to that used with other drivers. In addition, the operation you need to remember, viSetAttribute(), is the same operation you use to set any feature of any resource. Now you send the string to the device and read the result:

status = viWrite(instr, "*IDN?\n", 6, &retCount);

status = viRead(instr, buffer, MAX_CNT, &retCount);

This is a familiar approach to programming. You use a write operation to send a string to a device, and read the response with a read operation.

See Message-Based Communication for more information.