User`s guide
76 Agilent VISA User’s Guide
3 Programming with VISA
See the VISA Online Help for function descriptions to determine which
are applicable for locking and which are not restricted by locking.
Example: Exclusive Lock This example 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};
/* Open session to GPIB device at address 22 */
viOpenDefaultRM (&defaultRM);
viOpen (defaultRM, "GPIB0::22::INSTR",
VI_NULL,VI_NULL, &vi);
/* Initialize device */
viPrintf (vi, "*RST\n");
/* Make sure no other process or thread does
anything to this resource between viPrintf and
viScanf calls */
viLock (vi, VI_EXCLUSIVE_LOCK, 2000, VI_NULL,
VI_NULL);
/* Send an *IDN? string to the device */
viPrintf (vi, "*IDN?\n");
/* Read results */
viScanf (vi, "%t", &buf);
/* Unlock this session so other processes and
threads can use it */
viUnlock (vi);