niSwitch_UnlockSession

NI Switches Help

Edition Date: April 2015

Part Number: 375472H-01

»View Product Info
Download Help (Windows Only)

Specific Function

C Function Prototype

ViStatus niSwitch_UnlockSession (ViSession vi, ViBoolean* callerHasLock);

Purpose

This function releases a lock that you acquired on an instrument session using niSwitch_LockSession.
Refer to niSwitch_LockSession for additional information on session locks.

Parameters

Name Type Description
vi ViSession A particular NI-SWITCH session established with niSwitch_InitWithTopology, niSwitch_InitWithOptions, or niSwitch_init and used for all subsequent NI-SWITCH calls.

callerHasLock ViBoolean This parameter serves as a convenience. If you do not want to use this parameter, pass VI_NULL. Use this parameter in complex functions to keep track of whether you obtain a lock and therefore need to unlock the session. Pass the address of a local ViBoolean variable. In the declaration of the local variable, initialize it to VI_FALSE. Pass the address of the same local variable to any other calls you make to niSwitch_LockSession or niSwitch_UnlockSession in the same function. The parameter is an input/output parameter. niSwitch_LockSession and niSwitch_UnlockSession each inspect the current value and take the following actions:
- If the value is VI_TRUE, niSwitch_LockSession does not lock the session again. If the value is VI_FALSE, niSwitch_LockSession obtains the lock and sets the value of the parameter to VI_TRUE.
- If the value is VI_FALSE, niSwitch_UnlockSession does not attempt to unlock the session. If the value is VI_TRUE, niSwitch_UnlockSession releases the lock and sets the value of the parameter to VI_FALSE.

Thus, you can, call niSwitch_UnlockSession at the end of your function without worrying about whether you actually have the lock.

Example:
ViStatus TestFunc (ViSession vi, ViInt32 flags)
{
ViStatus error = VI_SUCCESS;
ViBoolean haveLock = VI_FALSE;
if (flags & BIT_1)
{
viCheckErr( niSwitch_LockSession(vi, &haveLock));
viCheckErr( TakeAction1(vi)); if (flags & BIT_2)
{
viCheckErr( niSwitch_UnlockSession(vi, &haveLock));
viCheckErr( TakeAction2(vi));
viCheckErr( niSwitch_LockSession(vi, &haveLock);
}
if (flags & BIT_3)
viCheckErr( TakeAction3(vi));
}
Error:
/* At this point, you cannot really be sure that you have
the lock. Fortunately, the haveLock variable takes care
of that for you. */
niSwitch_UnlockSession(vi, &haveLock);
return error;
}

Related Information

WAS THIS ARTICLE HELPFUL?

Not Helpful