Opening a Session

From Agilent VISA.NET

Opening a Session

A session is a channel of communication. Sessions must first be opened on the default resource manager, and then for each resource you will be using.

  • A resource manager session is used to initialize the VISA system. It is a parent session that knows about all the opened sessions. A resource manager session must be opened before any other session can be opened.
  • A resource session is used to communicate with a resource on an interface. A session must be opened for each resource you will be using. When you use a session you can communicate without worrying about the type of interface to which it is connected. This insulation makes applications more robust and portable across interfaces.

Resource Manager Sessions

There are two parts to opening a communications session with a specific resource. First, you must open a session to the default resource manager with the viOpenDefaultRM function. The first call to this function initializes the default resource manager and returns a session to that resource manager session. You only need to open the default manager session once. However, subsequent calls to viOpenDefaultRM return a unique session to the same default resource manager resource.

Resource Sessions

Next, open a session with a specific resource using the viOpen function. This function uses the session returned from viOpenDefaultRM and returns its own session to identify the resource session. The following shows the function syntax.

viOpenDefaultRM(sesn);
viOpen(sesn, rsrcName, accessMode, timeout,   vi);

The session returned from viOpenDefaultRM must be used in the sesn parameter of the viOpen function. The viOpen function then uses that session and the resource address specified in the rsrcName parameter to open a resource session. The vi parameter in viOpen returns a session identifier that can be used with other VISA functions.

Your program may have several sessions open at the same time after creating multiple session identifiers by calling the viOpen function multiple times. The following table summarizes the parameters in the previous function calls.

Parameter

Descriptions

sesn

A session returned from the viOpenDefaultRM function that identifies the resource manager session.

rsrcName

A unique symbolic name of the resource (resource address).

accessMode

 

 

 

 

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.

timeout

 

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.

vi

 

This is a pointer to the session identifier for this particular resource session. This pointer will be used to identify this resource session when using other VISA functions.

Example: Opening a Resource Session

This code sample shows one way of opening resource sessions with a GPIB multimeter and a GPIB-VXI scanner. The sample first opens a session with the default resource manager. The example then uses the session returned from the resource manager, and a VISA address, to open a session with the GPIB device at address 22. You can now identify that session as dmm when you call other VISA functions.

The example uses the session returned from the resource manager, with another VISA address, to open a session with the GPIB-VXI device at primary address 9 and VXI logical address (secondary address) 24. You can then identify this session as scanner when calling other VISA functions. See Addressing a Session , for information on addressing particular devices.

ViSession defaultRM, dmm, scanner;
.

viOpenDefaultRM(&defaultRM);
viOpen(defaultRM, "GPIB0::22::INSTR",VI_NULL,   VI_NULL,&dmm);
viOpen(defaultRM, "GPIB-VXI0::24::INSTR",   VI_NULL, VI_NULL,&scanner);
.

viClose(scanner);
viClose(dmm);
viClose(defaultRM);