<< VISA Integration Toolbox VISA Integration Toolbox Module overview >>

VISA Integration Toolbox >> VISA Integration Toolbox > Quick start

Quick start

This help contains information on using the VISA Library Application Programmer’s Interface (API) under Scilab.

Introduction

VISA

The Virtual Instrument Software Architecture (VISA) is a standard for configuring, programming, and troubleshooting instrumentation systems comprising GPIB, VXI, PXI, Serial, Ethernet, and/or USB interfaces.

VISA provides the programming interface between the hardware and development environments.

GPIB

GPIB (General Purpose Interface Bus) comes from IEEE-488 standard. It is a short-range digital communications bus specification. It was created for use with automated test equipment.

Pre-requisites

You can use both National Instruments (GPIB) and Agilent/HP (HPIB) Controllers in the same System :

To activate the interface between NI_VISA and Agilent, you must enable the NiTulip mode of NI_VISA. Under Windows :

You can find this information here.

Tutorial

Get the list of connected devices

To connect between your computer and your device you need the address of the instrument.

For this, run the findAllInstruments() which gives you the list of all connected instruments:

[status, deviceAddrs] = findAllInstruments()
- status contains the return code of the operation.
- deviceAddrs contains the list of descriptors (or adresses) of all connected devices.
If findAllInstruments() hasn't found any device, it returns [].

Open a session

viOpenDefaultRM() creates a session and returns its identifier.

[status, defaultRM] = viOpenDefaultRM();
- status contains the return code of the operation.
- defaultRM is a unique logical identifier of the Default Resource Manager session.

Connect to a device

To open a communication with the first connected device:

[status, idDevice] = viOpen(defaultRM, deviceAddrs(1), viGetDefinition("VI_NULL"), viGetDefinition("VI_NULL"));
- defaultRM defaultRM is Resource Manager session—should always be a session returned from viOpenDefaultRM().
- deviceAddrs(1) is the address of the first connected device.
- the first viGetDefinition("VI_NULL") specifies the mode by which the resource is accessed, here the session uses VISA-supplied default values (please Refer to the Description section for valid values)..
- the second viGetDefinition("VI_NULL") specifies the maximum time period (in milliseconds) the operation waits before returning an error (this does not set the I/O timeout—to do that you must call viSetAttribute() with the attribute VI_ATTR_TMO_VALUE).
- status contains the return code of the operation.
- idDevice is the device identifier.

Send commands

Once connected, you can send commands to your instrument using the function viWrite().

[status, count] = viWrite(idDevice, "*IDN?");
- idDevice is the device identifier.
- "*IDN?" is a command to get a device identification string (a command ending with "?" will return a value). Please refer to your instrument manual to get the list of its supported instructions.
- status contains the return code of the operation.
- count is the number of bytes actually transferred.

Read data

The viRead() is used for this purpose:

[status, bufferOut, count] = viRead(idDevice, 255);
- idDevice is the device identifier.
- 255 is number of bytes to be read.
- status contains the return code of the operation.
- bufferOut contains the read data.
- count is the number of bytes actually read.

Read attributes

You can also read one of the instruments attributes with the viGetAttribute() function.

This function needs a pointer on the attribute, so you need to create a pointer of the attribute type, then pass it to the function.

Then, you will need to read the pointer value, use the dedicated function for this:

pQueueLength = new_ViPUInt16();
status = viGetAttribute(idDevice, viGetDefinition("VI_ATTR_MAX_QUEUE_LENGTH"), pQueueLength);
queueLength = ViPUInt16_value(pQueueLength);
- idDevice is the device identifier.
- viGetDefinition("VI_ATTR_MAX_QUEUE_LENGTH") returns the identifier of the Max Queue Length attribute.
- pQueueLength is the pointer to the value of the attribute.
- status contains the return code of the operation.

Disconnect from the device

The communication with the device is over, you can close it using the function viClose().

viClose(idDevice);
- idDevice is the device identifier.

Close the session

The same command is used to close the session.

viClose(defaultRM);
- defaultRM is a unique logical identifier of the Default Resource Manager session.

Tutorial full script

[status, deviceAddrs] = findAllInstruments();

[status, defaultRM] = viOpenDefaultRM();

// if no device is connected, use NI FTP as device
if deviceAddrs == [] then
    deviceAddrs = "TCPIP0::ftp.ni.com::21::SOCKET";
end

[status, idDevice] = viOpen(defaultRM, deviceAddrs(1), viGetDefinition("VI_NULL"),viGetDefinition("VI_NULL"));

[status, count] = viWrite(idDevice, "*IDN?");
[status, bufferOut, count] = viRead(idDevice, 255)

pMaxQueueLength = new_ViPUInt16();
status = viGetAttribute(idDevice, viGetDefinition("VI_ATTR_MAX_QUEUE_LENGTH"), pMaxQueueLength);
maxQueueLength = ViPUInt16_value(pMaxQueueLength)
delete_ViPUInt16(pMaxQueueLength);

viClose(idDevice);
viClose(defaultRM);

See also


Report an issue
<< VISA Integration Toolbox VISA Integration Toolbox Module overview >>