User`s guide
Programming with VISA 3
Agilent VISA User’s Guide 89
a lock on that resource. Thus, locking a resource prevents
other, subsequent sessions from acquiring an exclusive lock
on that resource. Yet, when multiple sessions have acquired
a shared lock, VISA allows one of the sessions to acquire an
exclusive lock along with the shared lock it is holding.
Also, VISA supports nested locking. That is, a session can
lock the same VISA resource multiple times (for the same
lock type) via multiple invocations of the viLock function. In
such a case, unlocking the resource requires an equal
number of invocations of the viUnlock function. Nested
locking is explained in detail later in this section.
Some VISA operations may be permitted even when there is
an exclusive lock on a resource, or some global attributes
may not be read when there is any kind of lock on the
resource. These exceptions, when applicable, are mentioned
in the descriptions of the individual VISA functions and
attributes.
See the VISA Online Help for descriptions of individual
functions to determine which are applicable for locking and
which are not restricted by locking.
Sample: Exclusive Lock
This sample shows a session gaining an exclusive lock to
perform the viPrintf and viScanf VISA operations on a GPIB
device. It then releases the lock via the viUnlock function.
/* lockexcl.c
This example program queries a GPIB device for
an identification string and prints the results.
Note that you may need to change the address. */
#include <visa.h>
#include <stdio.h>
void main () {
ViSession defaultRM, vi;
char buf [256] = {0};