<< Quick start VISA Integration Toolbox findAllInstruments >>

VISA Integration Toolbox >> VISA Integration Toolbox > Module overview

Module overview

This help gives an overwiew of the functions, types, and other entities of the Scilab VISA module.

Introduction

The Scilab VISA interface is based on the VISA C interface (described in the NI-VISA Programmer Manual).

It means that for example, all Scilab functions have the same names as in the C API, and their signatures are the same, as much as possible. Differences are described here.

Functions

Scilab functions have mostly the same name as functions in the C API. Only the prototypes of functions differ.

Some functions with a pointer as parameter can be returned in the Scilab equivalent function. These are some examples:

VISA C function Equivalent in Scilab
ViStatus viOpenDefaultRM(ViPSession sesn) [status, sesn] = viOpenDefaultRM()
ViStatus viOpen(ViSession sesn, ViRsrc rsrcName, ViAccessMode accessMode, ViUInt32 openTimeout, ViPSession vi) [status, vi] = viOpen(sesn, rsrcName, accessMode, openTimeout)
ViStatus viRead(ViSession vi, ViPBuf buf, ViUInt32 count, ViPUInt32 retCount) [status, buf, retCount] = viParseRsrc(vi, count)
ViStatus viReadAsync(ViSession vi, ViPBuf buf, ViUInt32 count, ViPJobId jobId) [status, buf, jobId] = viReadSTB(vi, count)
ViStatus viParseRsrc(ViSession sesn, ViRsrc rsrcName, ViPUInt16 intfType, ViPUInt16 intfNum) [status, intfType, intfNum] = viParseRsrc(sesn, rsrcName)
ViStatus viReadSTB(ViSession vi, ViPUInt16 status) [status, ViPUInt16_status] = viReadSTB(vi)
ViStatus viVxiCommandQuery(ViSession vi, ViUInt16 mode, ViUInt32 cmd, ViPUInt32 response) [status, response] = viReadSTB(vi, mode, cmd)

Example:

[status, sesn] = viOpenDefaultRM()

Some other functions accept buffer pointers in inputs, and Scilab simplifies their use. As we can see below, a simple string can be passed instead of buffer pointers, and count is automatically calculated.

VISA C function Equivalent in Scilab
ViStatus viWrite(ViSession vi, ViBuf buf, ViUInt32 count, ViPUInt32 retCount) [status, retCount] = viWrite(vi, buf)
ViStatus viWriteAsync(ViSession vi, ViBuf buf, ViUInt32 count, ViPJobId jobId) [status, jobId] = viWriteAsync(vi, buf)
ViStatus viBufWrite(ViSession vi, ViBuf buf, ViUInt32 count, ViPUInt32 retCount) [status, retCount] = viBufWrite(vi, buf)
ViStatus viGpibCommand(ViSession vi, ViBuf buf, ViUInt32 count, ViPUInt32 retCount) [status, retCount] = viGpibCommand(vi, buf)

Example:

[status, count] = viWrite(vi, "*IDN?");

Some functions use pointers to void, as the output type is not defined and therefore it is the user's responsibility to define this type.

VISA C function Equivalent in Scilab
ViStatus viGetAttribute(ViObject vi, ViAttr attribute, void * attrState) status = viGetAttribute(vi, attribute, attrState)

Example:

attrState = new_ViPUInt16();
attribute = viGetDefinition("VI_ATTR_MAX_QUEUE_LENGTH");
status = viGetAttribute(vi, attribute, attrState);
State = ViPUInt16_value(attrState)

Types

The VISA C API redefines the primitive types. For example the VISA C type for an integer 16 bits is ViUint16.

These primitive types are automatically mapped to Scilab types. The functions using that types can be used transparently, without any conversion.

Some functions require pointers (to a VISA primitive type) as arguments (that is the case of the function viWrite() for example).

VISA also defines also types for these pointers, following is the list:
ViPInt32, ViPInt16, ViPInt8, ViAInt32, ViAInt16, ViAInt8
ViPUInt32, ViPUInt16, ViPUInt8, ViAUInt32, ViAUInt16, ViAUInt8
ViPChar, ViAChar
ViPByte, ViAByte
ViPBoolean, ViABoolean
ViPAddr, ViAAddr
ViPReal32, ViAReal32
ViPReal64, ViAReal64
ViPStatus, ViAStatus
ViPObject, ViAObject
ViPVersion, ViAVersion
ViPSession, ViASession

A set of dedicated functions are provided to create and manipulate pointers on each of these types.

Create a pointer on a given type <Type> is done with new_<Type>(). For example to create a pointer on a ViUint16:

pData = new_ViPUInt16();

To dereference a pointer, use <Type>_value() to read, and <Type>_assign() to write, with the pointer as argument:

ViPUInt16_assign(pData, valueIn);
valueOut = ViPUInt16_value(pData);

Copying a pointer is done with copy_<Type>().

Finally, you have to delete the pointer (to free the allocated memory) with delete_<Type>()

delete_ViPUInt16(pData);

Constants

The VISA C API defines a lot a constants, like attribute IDs (ex: VI_ATTR_JOB_ID), event IDs (ex: VI_EVENT_IO_COMPLETION), and so on.

These constants are accessed in Scilab via the viGetDefinition() function.

Note on instructions

When you send a command with viWrite(), a carriage return ("\n") is automatically added by the function:

[status, count] = viWrite(instr, ":WAVeform:DATA?");

See also


Report an issue
<< Quick start VISA Integration Toolbox findAllInstruments >>