()()
Syntax
viOpen(int sesn, string viDesc, int mode, int timeout, out int vi);
Description
Opens a VISA resource session given a VISA Resource Manager session, a resource address, and resource locking information. If successful, it returns a session identifier (integer) that can be used to execute any other legal operations on that resource.
Parameters
Name |
Dir |
Type |
Description |
sesn |
IN |
int |
Resource Manager session (should always be the Default Resource Manager for VISA returned from viOpenDefaultRM). |
viDesc |
IN |
string |
Unique symbolic name of a resource. (See the viOpen topic in the VISA Help for details..) |
mode |
IN |
int |
Specifies the modes by which the resource is to be accessed. The value VI_EXCLUSIVE_LOCK is used to acquire an exclusive lock immediately upon opening a session. If a lock cannot be acquired, the session is closed and an error is returned. The VI_LOAD_CONFIG value is used to configure attributes specified by some external configuration utility. If this value is not used, the session uses the default values provided by this specification. Multiple access modes can be used simultaneously by specifying a "bit-wise OR" of the values. (Must use VI_NULL in VISA 1.0.) |
timeout |
IN |
int |
If the accessMode parameter requires a lock, this parameter specifies the absolute time period (in milliseconds) that the resource waits to get unlocked before this operation returns an error. Otherwise, this parameter is ignored. (Must use VI_NULL in VISA 1.0.) |
vi |
OUT |
out int |
Unique logical identifier reference to a session. |
Return Values
Completion Codes |
Description |
VI_SUCCESS |
Operation completed successfully. |
VI_SUCCESS_DEV_NPRESENT |
Session opened successfully, but the device at the specified address is not responding. |
VI_WARN_CONFIG_NLOADED |
The specified configuration either does not exist or could not be loaded using VISA-specified defaults. |
Error Codes |
Description |
VI_ERROR_ALLOC |
Insufficient system resources to open a session. |
VI_ERROR_INTF_NUM_NCONFIG |
The interface type is valid but the specified interface number is not configured. |
VI_ERROR_INV_ACC_MODE |
Invalid access mode. |
VI_ERROR_INV_RSRC_NAME |
Invalid resource reference specified. Parsing error. |
VI_ERROR_INV_SESSION |
The given session or object reference is invalid (both are the same value). |
VI_ERROR_LIBRARY_NFOUND |
A code library required by VISA could not be located or loaded. |
VI_ERROR_NSUP_OPER |
The given sesn does not support this function. For VISA, this function is supported only by the Default Resource Manager session. |
VI_ERROR_RSRC_BUSY |
The resource is valid but VISA cannot currently access it. |
VI_ERROR_RSRC_LOCKED |
Specified type of lock cannot be obtained because the resource is already locked with a lock type incompatible with the lock requested. |
VI_ERROR_RSRC_NFOUND |
Insufficient location information or resource not present in the system. |
VI_ERROR_TMO |
A session to the resource could not be obtained within the specified timeout period. |
C# Example
public int OpenSession(string resourceAddress, int resourceManager) { int session, viError; viError = visa32.viOpen(resourceManager, resourceAddress, visa32.VI_NO_LOCK, visa32.VI_TMO_IMMEDIATE, out session); if (viError < visa32.VI_SUCCESS) { System.Text.StringBuilder error = new System.Text.StringBuilder(256); visa32.viStatusDesc(resourceManager, viError, error); throw new ApplicationException(error.ToString()); } return session; }
VB .NET Example
Public Function OpenSession(ByVal resourceAddress As String, _ ByVal resourceManager As Integer) As Integer Dim session As Integer = 0, viError As Integer viError = visa32.viOpen(resourceManager, resourceAddress, _ visa32.VI_NO_LOCK, _ visa32.VI_TMO_IMMEDIATE, session) If viError < visa32.VI_SUCCESS Then Dim err As System.Text.StringBuilder = New System.Text.StringBuilder(256) visa32.viStatusDesc(resourceManager, viError, err) Throw New ApplicationException(err.ToString()) End If Return session End Function