Communication Channels: Sessions

NI-VISA 15.0 Help

Edition Date: June 2015

Part Number: 370131S-01

»View Product Info

The examples from Introductory Programming Examples used an operation called viOpen() to open communication channels with the instruments. In VISA terminology, this channel is known as a session. A session connects you to the resource you addressed in the viOpen() operation and keeps your communication and attribute settings unique from other sessions to the same resource. In VISA, a resource can have multiple sessions to it from the same program and for interfaces other than Serial, even from other programs simultaneously. Therefore, you must consider some things about the resource to be local, that is, unique to the session, and other things to be global, that is, common for all sessions to the resource.

If you look at the descriptions of the various attributes supported by the VISA resources, you will see that some are marked global (such as VI_ATTR_INTF_TYPE) and others are marked local (such as VI_ATTR_TMO_VALUE). For example, the interface bus that the resource is using to communicate with the device (VI_ATTR_INTF_TYPE) is the same for everyone using that resource and is therefore a global attribute. However, different programs may have different timeout requirements, so the communication timeout value (VI_ATTR_TMO_VALUE) is a local attribute.

Again, look at the message-based communication example. To open communication with the instrument, that is, to create a session to the INSTR Resource, you use the viOpen() operation as shown below:

status = viOpen(defaultRM, "GPIB0::1::INSTR", VI_NULL, VI_NULL, &instr);

In this case, the interface to which the instrument is connected is important, but only as a means to uniquely identify the instrument. The code above references a GPIB device on bus number 0 with primary address 1. The access mode and timeout values for viOpen() are both VI_NULL. Other values are defined, but VI_NULL is recommended for new users and all instrument drivers.

However, notice the statement has two sessions in the parameter list for viOpen(), defaultRM and instr. Why do you need two sessions? As you will see in a moment, viOpen() is an operation on the Resource Manager, so you must have a communication channel to this resource. However, what you want is a session to the instrument; this is what is returned in instr.

For the entire duration that you communicate with this GPIB instrument, you use the session returned in instr as the communication channel. When you are finished with the communication, you need to close the channel. This is accomplished through the viClose() operation as shown below:

status = viClose(instr);

At this point, the communication channel is closed, but you are still free to open it again or open a session to another device. Notice that you do not need to close a session to open another session. You can have as many sessions to different devices as you want.

WAS THIS ARTICLE HELPFUL?

Not Helpful