Opening a Session

NI-VISA

Opening a Session

When trying to access any of the VISA resources, the first step is to get a reference to the default Resource Manager by calling viOpenDefaultRM(). Your application can then use the session returned from this call to open sessions to resources controlled by that Resource Manager, as shown in the following example.

Example

Note  This example shows C source code. There is also an example in Visual Basic syntax.

#include "visa.h"

int main(void)
{

ViStatus
ViSession
status;
defaultRM, instr;
/* Open Default RM */
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS) {


/* Error Initializing VISA...exiting */
return -1;

}

/* Access other resources */
status = viOpen(defaultRM, "GPIB::1::INSTR", VI_NULL, VI_NULL, &instr);

/* Use device and eventually close it. */
viClose(instr);
viClose(defaultRM);
return 0;

}

As shown in this example, you use the viOpen() call to open new sessions. In this call, you specify which resource to access by using a string that describes the resource. Refer to VISA Resource Syntax and Examples for the syntax of resource strings and examples.

Refer to NI-VISA Platform-Specific and Portability Issues for help in determining exactly which resource you may be accessing. In some cases, such as serial (ASRL) resources, the naming conventions with other serial naming conventions may be confusing. In the Windows platform, COM1 corresponds to ASRL1, unlike in LabVIEW, where COM1 is accessible using port number 0.

The tables in VISA Resource Syntax and Examples show the canonical resource name formats. NI-VISA also supports the use of aliases to make opening devices easier. On Windows, run Measurement & Automation Explorer (MAX) and choose the menu option Tools»NI-VISA»Alias Editor to manage all your aliases. On UNIX, run visaconf and double-click any resource to bring up a dialog box for managing the alias for that resource. NI-VISA supports alias names that include letters, numbers, and underscores. To use an alias in your program, just call viOpen() with the alias name instead of the canonical resource name.