viOpen

Please note, this function is available for both Windows and Linux users, however, VXI and PXI functionality are Windows only.

Syntax

viOpen(ViSession sesn, ViRsrc rsrcName, ViAccessMode accessMode, ViUInt32 timeout, ViPSession vi);

Description

This function opens a session to the specified device. It returns a session identifier that can be used to call any other functions to that device.

Some Connection Expert settings and Keysight Instrument Discovery Service policies affect the operation of viFindRsrc, viFindNext, and viOpen. Click here for more information on these interactions.

Parameters

Name

Dir

Type

Description

sesn

IN

ViSession

Resource Manager session (should always be the Default Resource Manager for VISA returned from viOpenDefaultRM).

rsrcName

IN

ViRsrc

Unique symbolic name (VISA address) of a resource. (See the following tables.) Can also be a VISA alias (defined in the Keysight Connection Expert utility).

accessMode

IN

ViAccessMode

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

ViUInt32

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.) Note: The timeout parameter affects ONLY the LOCK; it does not impact the overall viOpen command timing.

vi

OUT

ViPSession

Unique logical identifier reference to a session.

Address String Grammar for rsrcName Parameter

Interface

Syntax

ASRL

ASRL[board][::INSTR]

GPIB

GPIB[board]::INTFC

GPIB-VXI

GPIB-VXI[board]::MEMACC

GPIB

GPIB[board]::primary address[::secondary address][::INSTR]

GPIB-VXI

GPIB-VXI[board]::VXI logical address[::INSTR]

GPIB-VXI

GPIB-VXI[board][::VXI logical address]::BACKPLANE

PXI

PXI[bus]::device[::function][::INSTR]

PXI

PXI[interface]::bus-device[.function][::INSTR]

PXI

PXI[interface]::CHASSISchassis::SLOTslot[::FUNCfunction][::INSTR]

PXI

PXI[interface]::MEMACC

PXI

PXI[interface]::chassis number::BACKPLANE

TCPIP

TCPIP[board]::[[$[$]][credential information]@]host address::port::SOCKET

TCPIP

TCPIP[board]::[[$[$]][credential information]@]host address[::HiSLIP device name[,HiSLIP port]][::INSTR]

TCPIP

TCPIP[board]::host address[::LAN device name]::INSTR

USB

USB[board]::manufacturer ID::model code::serial number[::USB interface number][::INSTR]

VXI

VXI[board]::MEMACC

VXI

VXI[board]::VXI logical address[::INSTR]

VXI

VXI[board][::VXI logical address]::BACKPLANE

Examples of Address Strings for rsrcName Parameter

Address String

Description (Please note VXI and PXI examples are Windows only)

ASRL1::INSTR

A serial device located on port 1.

GPIB::1::0::INSTR

A GPIB device at primary address 1 and secondary address 0 in GPIB interface 0.

GPIB2::INTFC

Interface or raw resource for GPIB interface 2.

GPIB-VXI::9::INSTR

A VXI device at logical address 9 in a GPIB-VXI controlled VXI system.

GPIB-VXI1::MEMACC

Board-level register access to GPIB-VXI interface number 1.

"MyDMM"

A device for which the VISA Alias myDMM has been created in the Keysight Connection Expert utility

PXI0::21::INSTR

PXI device 21 on bus 0

PXI0::3-18.2::INSTR

Function 2 on PXI device 18 on bus 3

PXI0::3-18::INSTR

PXI device 18 on bus 3.

PXI0::CHASSIS1::SLOT4::INSTR

PXI device in slot 4 of chassis 1.

PXI0::MEMACC

Access to system controller memory available to devices in the PXI system.

PXI0::1::BACKPLANE

Mainframe resource for PXI chassis 1.

TCPIP0::[fe80::1]::hislip0::INSTR

A TCP/IP device using HiSLIP located at IPv6 IP address fe80::1.

TCPIP::devicename.company.com::INSTR

TCPIP device using VXI-11 located at the specified address. This uses the default LAN Device Name of inst0.

TCPIP0::1.2.3.4::999::SOCKET

Raw TCPIP access to port 999 at the specified address.

TCPIP0::[fe80::218:e77f]::999::SOCKET

Raw TCPIP access to port 999 at the specified IPv6 address.

TCPIP::@[fe80::1]::hislip0::INSTR

A TCP/IP device using HiSLIP rev 2 located at IPv6 IP address fe80::1. The connection is a secure connection with an anonymous VISA client.

USB::0x1234::0x5678::A22-5::INSTR

A USB device with manufacturer ID 0x1234, model code 0x5678, and serial number A22-5. This uses the device’s first available USBTMC interface. This is usually number 0.

VXI::1::BACKPLANE

Mainframe resource for chassis 1 on the default VXI system, which is interface 0.

VXI::MEMACC

Board-level register access to the VXI interface.

VXI0::1::INSTR

A VXI device at logical address 1 in VXI interface VXI0.

Return Values

Type ViStatus

This is the function return status. It returns either a completion code or an error code as follows.

Completion Code

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.

VI_WARN_SERVER_CERT_UNTRUSTED

A HiSLIP VISA client does not trust the server certificate.

Error Code

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
VI_ERROR_INV_OBJECT

The given session or object reference is invalid (both are the same value).

VI_ERROR_INV_PROT

The resource descriptor specifies a secure connection, but the device or VISA implementation does not support secure connections, or security has been disabled on the device.

-or-

The address string indicates a secure connection should be made, but the designated port is not for a TLS server.

VI_ERROR_LIBRARY_NFOUND

A code library required by VISA could not be located or loaded.

VI_ERROR_NPERMISSION

A secure connection could not be created because the instrument refused the credentials proffered by VISA or the credential information could not be mapped to valid credentials.

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_SERVER_CERT

A secure connection could not be created due to the instrument certificate being invalid or untrusted.

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

See Also

viClose

viFindRsrc and the Instrument Discovery Service