User`s guide

88 Agilent VISA User’s Guide
3 Programming with VISA
viLock(vi, lockType, timeout, requestedKey,
accessKey);
The VI_ATTR_RSRC_LOCK_STATE attribute specifies the
current locking state of the resource on the given session,
which can be either VI_NO_LOCK, VI_EXCLUSIVE_LOCK, or
VI_SHARED_LOCK.
The VISA viUnlock function is then used to release the lock
on a resource. If a resource is locked and the current
session does not have the lock, the error
VI_ERROR_RSRC_LOCKED is returned.
VISA Lock Types
VISA defines two different types of locks: Exclusive Lock
and Shared Lock.
Exclusive Lock - A session can lock a VISA resource
using the lock type VI_EXCLUSIVE_LOCK to get exclusive
access privileges to the resource. This exclusive lock type
excludes access to the resource from all other sessions.
If a session has an exclusive lock, other sessions cannot
modify global attributes or invoke operations on the
resource. However, the other sessions can still get
attributes.
Shared Lock - A session can share a lock on a VISA
resource with other sessions by using the lock type
VI_SHARED_LOCK. Shared locks in VISA are similar to
exclusive locks in terms of access privileges, but can still
be shared between multiple sessions.
If a session has a shared lock, other sessions that share
the lock can also modify global attributes and invoke
operations on the resource (of course, unless some other
session has a previous exclusive lock on that resource). A
session that does not share the lock will lack these
capabilities.
Locking a resource restricts access from other sessions, and
in the case where an exclusive lock is acquired, ensures that
operations do not fail because other sessions have acquired