Programming via GPIB and VXI. Agilent Technologies E2094S


Add to my manuals
146 Pages

advertisement

Programming via GPIB and VXI. Agilent Technologies E2094S | Manualzz

Agilent IO Libraries Suite

Agilent VISA User’s Guide

4

Programming via GPIB and VXI

VISA supports three interfaces you can use to access GPIB (General

Purpose Interface Bus) and VXI (VME eXtension for Instrumentation) instruments: GPIB, VXI, and GPIB-VXI.

This chapter provides information to program GPIB and VXI devices via the GPIB, VXI or GPIB-VXI interfaces, including:

GPIB and VXI Interfaces Overview

Using High-Level Memory Functions

Using Low-Level Memory Functions

Using High/Low-Level Memory I/O Methods

Using the Memory Access Resource

Using VXI-Specific Attributes

See Chapter 3, “Programming with VISA”, for general information on

VISA programming for the GPIB, VXI, and GPIB-VXI interfaces. See the VISA Online Help for information on the specific VISA functions.

Agilent Technologies

79

4

Programming via GPIB and VXI

GPIB and VXI Interfaces Overview

This section provides an overview of the GPIB, GPIB-VXI, and VXI interfaces, including:

General Interface Information

GPIB Interfaces Overview

VXI Interfaces Overview

General Interface Information

VISA supports three interfaces you can use to access instruments or devices: GPIB, VXI, and GPIB-VXI. The GPIB interface can be used to access VXI instruments via a Command Module. In addition, the VXI backplane can be directly accessed with the VXI or GPIB-VXI interfaces.

What is an I/O Interface?

An I/O interface can be defined as both a hardware interface and as a software interface. Connection Expert is used to associate a unique interface name with a hardware interface. Agilent IO Libraries Suite uses a VISA interface name to identify an interface. This information is passed in the parameter string of the viOpen function call in a VISA program.

Connection Expert assigns a VISA interface name to the interface hardware, and other necessary configuration values for an interface when the interface is configured. See the Agilent IO Libraries Suite

Online Help for details.

VXI Device Types

When using GPIB-VXI or VXI interfaces to directly access the VXI backplane (in the VXI mainframe), you must know whether you are programming a message-based or a register-based VXI device

(instrument).

A message-based VXI device has its own processor that allows it to interpret high-level commands such as Standard Commands for

Programmable Instruments (SCPI). When using VISA, you can place the SCPI command within your VISA output function call. Then, the

80 Agilent VISA User’s Guide

Programming via GPIB and VXI

4 message-based device interprets the SCPI command. In this case you can use the VISA formatted I/O or non-formatted I/O functions and program the message-based device as you would a GPIB device.

However, if the message-based device has shared memory, you can access the device's shared memory by doing register peeks and pokes.

VISA provides two different methods you can use to program directly to the registers: high-level memory functions or low-level memory functions.

A register-based VXI device typically does not have a processor to interpret high-level commands. Therefore, the device must be programmed with register peeks and pokes directly to the device's registers. VISA provides two different methods you can use to program register-based devices: high-level memory functions or low-level memory functions.

GPIB Interfaces Overview

As shown in the following figure, a typical GPIB interface consists of a

Windows PC with one or more GPIB cards (PCI and/or ISA) cards installed in the PC, and one or more GPIB instruments connected to the

GPIB cards via GPIB cable. I/O communication between the PC and the instruments is via the GPIB cards and the GPIB cable. The following figure shows GPIB instruments at addresses 3 and 5.

Agilent VISA User’s Guide 81

4

Programming via GPIB and VXI

GPIB Interface (82350 PCI GPIB Cards)

Windows PC GPIB Cable GPIB Instruments

82350 GPIB Card #1

82350 GPIB Card #2

5

3

3

Example: GPIB (82350) Interface

The GPIB interface system in the following figure consists of a

Windows PC with two 82350 GPIB cards connected to three GPIB instruments via GPIB cables. For this system, Agilent Connection

Expert has been used to assign GPIB card #1 a VISA name of GPIB0 and to assign GPIB card #2 a VISA name of GPIB1. VISA addressing is as shown in the figure.

82 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Interface VISA Names

GPIB Interface (82350 PCI GPIB Cards)

Windows PC GPIB Cable

VISA Name

"GPIB0"

"GPIB1"

82350 GPIB Card #1

82350 GPIB Card #2

GPIB Instruments

5

3

3

VISA Addressing viOpen (... "GPIB0::5::INSTR"...) viOpen (... "GPIB0::3::INSTR"...) viOpen (... "GPIB1::3::INSTR"...)

Open IO path to GPIB instrument at address 5 using 82350 Card #1

Open IO path to GPIB instrument at address 3 using 82350 Card #1

Open IO path to GPIB instrument at address 3 using 82350 Card #2

Agilent VISA User’s Guide 83

4

Programming via GPIB and VXI

VXI Interfaces Overview

As shown in the following figure, a typical VXI (E8491) interface consists of an E8491 PC Card in a Windows PC that is connected to an

E8491B IEEE-1394 Module in a VXI mainframe via an IEEE-1394 to

VXI cable. The VXI mainframe also includes one or more VXI instruments.

Windows PC

VXI (E8491) Interfaces

IEEE-1394 to VXI

VXI Mainframe

E8491 PC Card

9

1

B

E

8

4

I n s r t

V

X

I

V

X

I n s t r

. .

I n s r t

V

X

I

Example: VXI (E8491B) Interfaces

The VXI interface system in the following figure consists of a Windows

PC with an E8491 PC card that connects to an E8491B IEEE-1394 to

VXI Module in a VXI Mainframe. For this system, the three VXI instruments shown have logical addresses 8, 16, and 24. The

Connection Expert utility has been used to assign the E8491 PC card a

VISA name of VXI0. VISA addressing is as shown in the figure.

For information on the E8491B module, see the Agilent E8491B User’s

Guide. For information on VXI instruments, see the applicable VXI instrument User’s Guide.

84 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

VXI Interface (E8491B IEEE-1394 to VXI Module)

Interface VISA Name

VISA Name

"VXI0"

Windows PC IEEE-1394 to VXI

E8491 PC Card

VXI Mainframe

1

B

4

9

E

8

V

X

I

V

X

I

V

X

I r t s

I n

I t s r

LA 8 LA 24

. .

LA 16 s t r

I n

VISA Addressing viOpen (... "VXI0::24::INSTR"...) Open IO path to VXI instrument at logical address 24 using

E8491 PC Card and E8491 IEEE-1394 to VXI Module

GPIB-VXI Interfaces Overview

As shown in the following figure, a typical GPIB-VXI interface consists of a GPIB card (82350 or equivalent) in a Windows PC that is connected via a GPIB cable to an E1406A Command Module. The

E1406A sends commands to the VXI instruments in a VXI mainframe.

There is no direct access to the VXI backplane from the PC.

Agilent VISA User’s Guide 85

4

Programming via GPIB and VXI

N O T E

For a GPIB-VXI interface, VISA uses a DLL supplied by the Command

Module vendor to translate the VISA VXI calls to Command Module commands that are vendor-specific. The DLL required for Agilent

Command Modules is installed by the Agilent IO Libraries Suite installer. This DLL is installed by default when Agilent VISA is installed.

Windows PC

GPIB-VXI (E1406A) Interfaces

GPIB VXI Mainframe

GPIB Card

0

6

A

E

1

4 s t r

I n

V

X

I

V

X

I r t n s

. .

I r t n s

V

X

I

Example: GPIB-VXI (E1406A) Interface

The GPIB-VXI interface system in the following figure consists of a

Windows PC with an Agilent 82350 GPIB card that connects to an

E1406A command module in a VXI mainframe. The VXI mainframe includes one or more VXI instruments.

When Agilent IO Libraries Suite was installed, a GPIB-VXI driver with

GPIB address 9 was also installed, and the E1406A was configured for primary address 9 and logical address (LA) 0. The three VXI instruments shown have logical addresses 8, 16, and 24.

86 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

The Connection Expert utility has been used to assign the GPIB-VXI driver a VISA name of GPIB-VXI0 and to assign the 82350 GPIB card a VISA name of GPIB0. VISA addressing is as shown in the figure.

For information on the E1406A Command Module, see the Agilent

E1406A Command Module User’s Guide. For information on VXI instruments, see the applicable instrument’s User’s Guide.

Interface VISA Name

VISA Name

"GPIB-VXI0"

"GPIB0"

GPIB-VXI Interface (E1406A Command Module)

Windows PC VXI Mainframe

GPIB-VXI Driver

GPIB Address 9

82350 GPIB Card

Primary

Address 9

GPIB

V

X

I

V

X

I

0

6

A

E

1

4

I n s t r

I s t r

LA 0 LA 8 LA 24

V

X

I

. .

s t

I n r

LA 16

VISA Addressing viOpen (... "GPIB-VXI0::24::INSTR"...) Open IO path to VXI instrument at logical address 24 using

82350 GPIB Card and E1406A VXI Command Module at

GPIB primary address 9

Agilent VISA User’s Guide 87

4

Programming via GPIB and VXI

Using High-Level Memory Functions

High-level memory functions allow you to access memory on the interface through simple function calls. There is no need to map memory to a window. Instead, when high-level memory functions are used, memory mapping and direct register access are automatically done.

The trade-off, however, is speed. High-level memory functions are easier to use. However, since these functions encompass mapping of memory space and direct register access, the associated overhead slows program execution time. If speed is required, use the low-level memory

functions discussed in “Using Low-Level Memory Functions” on page 94.

Programming the Registers

High-level memory functions include the viIn and viOut functions for transferring 8-, 16-, or 32-bit values, as well as the viMoveIn and

viMoveOut functions for transferring 8-, 16-, or 32-bit blocks of data into or out of local memory. You can therefore program using 8-, 16-, or

32-bit transfers.

High-Level Memory Functions

This table summarizes the high-level memory functions.

Table 20 Summary of High-Level Memory Functions

Function viIn8 ( vi, space, offset, val8) ;

Description

Reads 8 bits of data from the specified offset.

viIn16 ( vi, space, offset, val16) ; Reads 16 bits of data from the specified offset.

viIn32 ( vi, space, offset, val32) ; Reads 32 bits of data from the specified offset.

viOut8 ( vi, space, offset, val8) ; Writes 8 bits of data to the specified offset.

88 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Table 20 Summary of High-Level Memory Functions viOut16

val16)

val32)

; viOut32

;

( vi, space, offset,

( vi, space, offset,

viMoveIn8(vi, space, offset,

length, buf8) ; viMoveIn16 ( vi, space, offset,

length, buf16) ;

viMoveIn32(vi, space, offset,

length, buf32) ;

viMoveOut8(vi, space, offset,

length, buf8) ; viMoveOut16 ( vi, space, offset,

length, buf16) ; viMoveOut32 ( vi, space, offset,

length, buf32) ;

Writes 16 bits of data to the specified offset.

Writes 32 bits of data to the specified offset.

Moves an 8-bit block of data from the specified offset to local memory.

Moves a 16-bit block of data from the specified offset to local memory.

Moves a 32-bit block of data from the specified offset to local memory.

Moves an 8-bit block of data from local memory to the specified offset.

Moves a 16-bit block of data from local memory to the specified offset.

Moves a 32-bit block of data from local memory to the specified offset.

Using viIn and viOut

When using the viIn and viOut high-level memory functions to program to the device registers, all you need to specify is the session identifier, address space, and the offset of the register. Memory mapping is done for you. For example, in this function: viIn32(vi, space, offset, val32);

vi is the session identifier and offset is used to indicate the offset of the memory to be mapped. offset is relative to the location of this device's memory in the given address space. The space parameter determines which memory location to map the space. Valid space values are:

• VI_A16_SPACE - Maps in VXI/MXI A16 address space

• VI_A24_SPACE - Maps in VXI/MXI A24 address space

• VI_A32_SPACE - Maps in VXI/MXI A32 address space

89

4

Programming via GPIB and VXI

90

The val32 parameter is a pointer to where the data read will be stored. If instead you write to the registers via the viOut32 function, the val32 parameter is a pointer to the data to write to the specified registers. If the device specified by vi does not have memory in the specified address space, an error is returned. The following code sample uses viIn16.

ViSession defaultRM, vi;

ViUInt16 value;

.

viOpenDefaultRM(&&defaultRM); viOpen(defaultRM, "VXI::24", VI_NULL, VI_NULL,

&vi); viIn16(vi, VI_A16_SPACE, 0x100, &value);

Using

viMoveIn

and

viMoveOut

You can also use the viMoveIn and viMoveOut high-level memory functions to move blocks of data to or from local memory. Specifically, the viMoveIn function moves an 8-, 16-, or 32-bit block of data from the specified offset to local memory, and the viMoveOut functions moves an 8-, 16-, or 32-bit block of data from local memory to the specified offset. Again, the memory mapping is done for you.

For example, in this function: viMoveIn32(vi, space, offset, length, buf32);

vi is the session identifier and offset is used to indicate the offset of the memory to be mapped. offset is relative to the location of this device's memory in the given address space. The space parameter determines which memory location to map the space and the length parameter specifies the number of elements to transfer (8-, 16-, or 32-bits).

The buf32 parameter is a pointer to where the data read will be stored. If instead you write to the registers via the viMoveOut32 function, the

buf32 parameter is a pointer to the data to write to the specified registers.

High-Level Memory Functions: Sample Programs

Two sample programs follow that use the high-level memory functions to read the ID and Device Type registers of a device at the VXI logical address 24. The contents of the registers are then printed out.

Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

The first program uses the VXI interface; the second program accesses the backplane with the GPIB-VXI interface. These two programs are identical except for the string passed to viOpen.

Sample: Using VXI Interface (High-Level) Memory

Functions

This program uses high-level memory functions and the VXI interface to read the ID and Device Type registers of a device at VXI0::24.

/* vxihl.c

This example program uses the high-level memory functions to read the id and device type registers of the device at VXI0::24. Change this address if necessary. The register contents are then displayed.*/

#include <visa.h>

#include <stdlib.h>

#include <stdio.h> void main () {

ViSession defaultRM, dmm;

unsigned short id_reg, devtype_reg;

/* Open session to VXI device at address 24 */

viOpenDefaultRM(&defaultRM);

viOpen(defaultRM, "VXI0::24::INSTR", VI_NULL,

VI_NULL, &dmm);

/* Read instrument id register contents */

viIn16(dmm, VI_A16_SPACE, 0x00, &id_reg);

/* Read device type register contents */

viIn16(dmm, VI_A16_SPACE, 0x02,

&devtype_reg);

/* Print results */

printf ("ID Register = 0x%4X\n", id_reg);

printf ("Device Type Register = 0x%4X\n",

devtype_reg);

91

4

Programming via GPIB and VXI

/* Close sessions */

viClose(dmm);

viClose(defaultRM);

}

Sample: Using GPIB-VXI Interface (High-Level) Memory

Functions

This program uses high-level memory functions and the GPIB-VXI interface to read the ID and Device Type registers of a device at

GPIB-VXI0::24.

/*gpibvxih.c

This example program uses the high-level memory functions to read the id and device type registers of the device at GPIB-VXI0::24. Change this address if necessary. The register contents are then displayed.*/

#include <visa.h>

#include <stdlib.h>

#include <stdio.h> void main ()

{

ViSession defaultRM, dmm;

unsigned short id_reg, devtype_reg;

/* Open session to VXI device at address 24 */

viOpenDefaultRM(&defaultRM);

viOpen(defaultRM, "GPIB-VXI0::24::INSTR",

VI_NULL,VI_NULL, &dmm);

/* Read instrument id register contents */

viIn16(dmm, VI_A16_SPACE, 0x00, &id_reg);

/* Read device type register contents */

viIn16(dmm, VI_A16_SPACE, 0x02,

&devtype_reg);

92 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

/* Print results */

printf ("ID Register = 0x%4X\n", id_reg);

printf ("Device Type Register = 0x%4X\n",

devtype_reg);

/* Close sessions */

viClose(dmm);

viClose(defaultRM);

}

Agilent VISA User’s Guide 93

4

Programming via GPIB and VXI

Using Low-Level Memory Functions

Low-level memory functions allow direct access to memory on the interface just as do high-level memory functions. However, with low-level memory function calls, you must map a range of addresses and directly access the registers with low-level memory functions, such as viPeek32 and viPoke32.

There is more programming effort required when using low-level memory functions. However, the program execution speed can increase.

Additionally, to increase program execution speed, the low-level memory functions do not return error codes.

Programming the Registers

When using the low-level memory functions for direct register access, you must first map a range of addresses using the viMapAddress function. Next, you can send a series of peeks and pokes using the

viPeek and viPoke low-level memory functions. Then, you must free the address window using the viUnmapAddress function. A process you could use is:

1 Map memory space using viMapAddress.

2 Read and write to the register's contents using viPeek32 and

viPoke32.

3 Unmap the memory space using viUnmapAddress.

Low-Level Memory Functions

You can program the registers using low-level functions for 8-, 16-, or

32-bit transfers. This table summarizes the low-level memory functions.

Table 21 Summary of Low-Level Memory Functions

Function

viMapAddress(vi, mapSpace, mapBase, mapSize, access, suggested,

address);

viPeek8(vi, addr, val8);

Description

Maps the specified memory space.

Reads 8 bits of data from address specified.

94 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Table 21 Summary of Low-Level Memory Functions (continued)

viPeek16(vi, addr, val16);

viPeek32(vi, addr, val32);

viPoke8(vi, addr, val8);

viPoke16(vi, addr, val16);

viPoke32(vi, addr, val32);

viUnmapAddress(vi);

Reads 16 bits of data from address specified.

Reads 32 bits of data from address specified.

Writes 8 bits of data to address specified.

Writes 16 bits of data to address specified.

Writes 32 bits of data to address specified.

Unmaps memory space previously mapped.

Mapping Memory Space

When using VISA to access the device's registers, you must map memory space into your process space. For a given session, you can have only one map at a time. To map space into your process, use the

VISA viMapAddress function: viMapAddress(vi, mapSpace, mapBase, mapSize,

access, suggested, address);

This function maps space for the device specified by the vi session. mapBase , mapSize , and suggested are used to indicate the offset of the memory to be mapped, amount of memory to map, and a suggested starting location, respectively. mapSpace determines which memory location to map the space. The following are valid mapSpace choices:

VI_A16_SPACE - Maps in VXI/MXI A16 address space

VI_A24_SPACE - Maps in VXI/MXI A24 address space

VI_A32_SPACE - Maps in VXI/MXI A32 address space

A pointer to the address space where the memory was mapped is returned in the address parameter. If the device specified by vi does not have memory in the specified address space, an error is returned. Some sample viMapAddress function calls follow.

/* Maps to A32 address space */ viMapAddress(vi, VI_A32_SPACE, 0x000, 0x100,

VI_FALSE,

VI_NULL,&address);

95

4

Programming via GPIB and VXI

/* Maps to A24 address space */ viMapAddress(vi, VI_A24_SPACE, 0x00, 0x80,

VI_FALSE,

VI_NULL,&address);

Reading and Writing to Device Registers

When you have mapped the memory space, use the VISA low-level memory functions to access the device's registers. First, determine which device register you need to access. Then, you need to know the register's offset. See the applicable instrument’s user manual for a description of the registers and register locations. You can then use this information and the VISA low-level functions to access the device registers.

Sample: Using

viPeek16

A code sample using viPeek16 follows.

ViSession defaultRM, vi;

ViUInt16 value;

ViAddr address;

ViUInt16 value;

.

.

viOpenDefaultRM(&&defaultRM); viOpen(defaultRM, "VXI::24::INSTR", VI_NULL,

VI_NULL,

&vi); viMapAddress(vi, VI_A16_SPACE, 0x00, 0x04,

VI_FALSE,

VI_NULL, &address); viPeek16(vi, addr, &value)

Unmapping Memory Space

Make sure you use the viUnmapAddress function to unmap the memory space when it is no longer needed. Unmapping memory space makes the window available for the system to reallocate.

96 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Low-Level Memory Functions: Code Samples

Two sample programs follow that use the low-level memory functions to read the ID and Device Type registers of the device at VXI logical address 24. The contents of the registers are then printed out. The first program uses the VXI interface and the second program uses the

GPIB-VXI interface to access the VXI backplane. These two programs are identical except for the string passed to viOpen.

Sample: Using the VXI Interface (Low-Level) Memory

Functions

This program uses low-level memory functions and the VXI interface to read the ID and Device Type registers of a device at VXI0::24.

/*vxill.c

This example program uses the low-level memory functions to read the id and device type registers of the device at VXI0::24. Change this address if necessary. The register contents are then displayed.*/

#include <visa.h>

#include <stdlib.h>

#include <stdio.h> void main () {

ViSession defaultRM, dmm;

ViAddr address;

unsigned short id_reg, devtype_reg;

/* Open session to VXI device at address 24 */

viOpenDefaultRM(&defaultRM);

viOpen(defaultRM, "VXI0::24::INSTR", VI_NULL,

VI_NULL, &dmm);

/* Map into memory space */

viMapAddress(dmm, VI_A16_SPACE, 0x00, 0x10,

VI_FALSE,VI_NULL, &address);

/* Read instrument id register contents */

viPeek16(dmm, address, &id_reg);

Agilent VISA User’s Guide 97

4

Programming via GPIB and VXI

98

/* Read device type register contents */

/* ViAddr is defined as a void so we must cast

/* it to something else to do pointer

arithmetic */

viPeek16(dmm, (ViAddr)((ViUInt16 *)address +

0x01),

&devtype_reg);

/* Unmap memory space */

viUnmapAddress(dmm);

/* Print results */

printf ("ID Register = 0x%4X\n", id_reg);

printf ("Device Type Register = 0x%4X\n",

devtype_reg);

/* Close sessions */

viClose(dmm);

viClose(defaultRM);

}

Sample: Using the GPIB-VXI Interface (Low-Level) Memory

Functions

This program uses low-level memory functions and the GPIB-VXI interface to read the ID and Device Type registers of a device at

GPIB-VXI0::24.

/*gpibvxil.c

This example program uses the low-level memory functions to read the id and device type registers of the device at GPIB-VXI0::24. Change this address if necessary. Register contents are then displayed.*/

#include <visa.h>

#include <stdlib.h>

#include <stdio.h> void main () {

ViSession defaultRM, dmm;

ViAddr address;

unsigned short id_reg, devtype_reg;

Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

/* Open session to VXI device at address 24 */

viOpenDefaultRM(&defaultRM);

viOpen(defaultRM, "GPIB-VXI0::24::INSTR",

VI_NULL,

VI_NULL,&dmm);

/* Map into memory space */

viMapAddress(dmm, VI_A16_SPACE, 0x00, 0x10,

VI_FALSE,

VI_NULL, &address);

/* Read instrument id register contents */

viPeek16(dmm, address, &id_reg);

/* Read device type register contents */

/* ViAddr is defined as a void so we must

cast it to something else to do pointer

arithmetic */

viPeek16(dmm, (ViAddr)((ViUInt16 *)address +

0x01),

&devtype_reg);

/* Unmap memory space */

viUnmapAddress(dmm);

/* Print results */

printf ("ID Register = 0x%4X\n", id_reg);

printf ("Device Type Register = 0x%4X\n",

devtype_reg);

/* Close sessions */

viClose(dmm);

viClose(defaultRM);

}

99

4

Programming via GPIB and VXI

Using Low/High-Level Memory I/O Methods

VISA supports three different memory I/O methods for accessing memory on the VXI backplane, as shown. All three of these access methods can be used to read and write VXI memory in the A16, A24, and A32 address spaces. The best method to use depends on the VISA program characteristics.

Low-level viPeek/viPoke

• viMapAddress

• viUnmapAddress

viPeek8, viPeek16, viPeek32

viPoke8, viPoke16, viPoke32

High-level viIn/viOut

viIn8, viIn16, viIn32

viOut8, viOut16, viOut32

High-level viMoveIn/viMoveOut

• viMoveIn8, viMoveIn16, viMoveIn32

• viMoveOut8, viMoveOut16, viMoveOut32

Using Low-Level viPeek/viPoke

Low-level viPeek/viPoke is the most efficient in programs that require repeated access to different addresses in the same memory space.

The advantages of low-level viPeek/viPoke are:

Individual viPeek/viPoke calls are faster than viIn/viOut or

viMoveIn/viMoveOut calls.

Memory pointers may be directly de-referenced in some cases for the lowest possible overhead.

The disadvantages of low-level viPeek/viPoke are:

A viMapAddress call is required to set up mapping before

viPeek/viPoke can be used.

• viPeek/viPoke calls do not return status codes.

100 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Only one active viMapAddress is allowed per vi session.

There may be a limit to the number of simultaneous active

viMapAddress calls per process or system.

Using High-Level viIn/viOut

High-level viIn/viOut calls are best in situations where a few widely scattered memory accesses are required and speed is not a major consideration.

The advantages of high-level viIn/viOut are:

It is the simplest method to implement.

There is no limit on the number of active maps.

A16, A24, and A32 memory access can be mixed in a single vi session.

The disadvantage of high-level viIn/viOut calls is that they are slower than viPeek/viPoke.

Using High-Level viMoveIn/viMoveOut

High-level viMoveIn/viMoveOut calls provide the highest possible performance for transferring blocks of data to or from the VXI backplane. Although these calls have higher initial overhead than the

viPeek/viPoke calls, they are optimized on each platform to provide the fastest possible transfer rate for large blocks of data.

For small blocks, the overhead associated with viMoveIn/viMoveOut may actually make these calls longer than an equivalent loop of

viIn/viOut calls. The block size at which viMoveIn/viMoveOut becomes faster depends on the particular platform and processor speed.

The advantages of high-level viMoveIn/viMoveOut are:

They are simple to use.

There is no limit on number of active maps.

A16, A24, and A32 memory access can be mixed in a single vi session.

They provide the best performance when transferring large blocks of data.

They support both block and FIFO mode.

Agilent VISA User’s Guide 101

4

Programming via GPIB and VXI

The disadvantage of viMoveIn/viMoveOut calls is that they have higher initial overhead than viPeek/viPoke.

Sample: Using VXI Memory I/O

This program demonstrates using various types of VXI memory I/O.

/* memio.c

This example program demonstrates the use of various memory I/O methods in VISA. */

#include <visa.h>

#include <stdlib.h>

#include <stdio.h>

#define VXI_INST "VXI0::24::INSTR" void main () {

ViSession defaultRM, vi;

ViAddr address;

ViUInt16 accessMode;

unsigned short *memPtr16;

unsigned short id_reg;

unsigned short devtype_reg;

unsigned short memArray[2];

/*Open default resource manager and session

to instr*/

viOpenDefaultRM (&defaultRM);

viOpen defaultRM, VXI_INST, VI_NULL,VI_NULL,

&vi);

/*

================================================

==

Low level memory I/O = viPeek16 = direct

memory dereference (when allowed)

================================================

*/

/* Map into memory space */

viMapAddress (vi, VI_A16_SPACE, 0x00, 0x10,

VI_FALSE,VI_NULL, &address);

102 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Agilent VISA User’s Guide

/*

================================================

=

Using viPeek

================================================

*/

Read instrument id register contents */

viPeek16 (vi, address, &id_reg);

/* Read device type register contents

ViAddr is defined as a (void *) so we must

cast it to something else in order to do

pointer arithmetic. */

viPeek16 (vi, (ViAddr)((ViUInt16 *)address +

0x01),&devtype_reg);

/* Print results */

printf (" viPeek16: ID Register = 0x%4X\n",

id_reg);

printf (" viPeek16: Device Type Register =

0x%4X\n",devtype_reg);

/* Use direct memory dereferencing if

supported */

viGetAttribute( vi, VI_ATTR_WIN_ACCESS,

&accessMode );

if ( accessMode == VI_DEREF_ADDR ) {

/* assign pointer to variable of correct

type */

memPtr16 = (unsigned short *)address;

/* do the actual memory reads */

id_reg = *memPtr16;

devtype_reg = *(memPtr16+1);

/* Print results */

printf ("dereference: ID Register =

0x%4X\n",id_reg);

printf ("dereference: Device Type Register

=0x%4X\n", devtype_reg);

}

103

4

Programming via GPIB and VXI

/* Unmap memory space */

viUnmapAddress (vi);

/*==============================================

High Level memory I/O = viIn16

==============================================*/

/* Read instrument id register contents */

viIn16 (vi, VI_A16_SPACE, 0x00, &&id_reg);

/* Read device type register contents */

viIn16 (vi, VI_A16_SPACE, 0x02,&devtype_reg);

/* Print results */

printf (" viIn16: ID Register = 0x%4X\n",

id_reg);

printf (" viIn16: Device Type Register =

0x%4X\n", devtype_reg);

/*==============================================

======

High Level block memory I/O = viMoveIn16

The viMoveIn/viMoveOut commands do both block read/write and FIFO read write. These commands offer the best performance for reading and writing large data blocks on the VXI backplane.

For this example we are only moving 2 words at a time. Normally, these functions would be used to move much larger blocks of data.

If the value of VI_ATTR_SRC_INCREMENT is 1 (the default),viMoveIn does a block read. If the value of VI_ATTR_SRC_INCREMENT is 0, viMoveIn does a FIFO read.

If the value of VI_ATTR_DEST_INCREMENT is 1 (the default),viMoveOut does a block write. If the value of VI_ATTR_DEST_INCREMENT is 0, viMoveOut does a FIFO write.

*/

104 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

/* Demonstrate block read.

Read instrument id register and device type

register into an array.*/

viMoveIn16 (vi, VI_A16_SPACE, 0x00, 2,

memArray);

/* Print results */

printf (" viMoveIn16: ID Register = 0x%4X\n",

memArray[0]);

printf (" viMoveIn16: Device Type Register =

0x%4X\n", memArray[1]);

/* Demonstrate FIFO read.

First set the source increment to 0 so we will

repetitively read from the same memory

location.*/

viSetAttribute( vi, VI_ATTR_SRC_INCREMENT, 0

);

/* Do a FIFO read of the Id Register */

viMoveIn16 (vi, VI_A16_SPACE, 0x00, 2,

memArray);

/* Print results */

printf (" viMoveIn16: 1 ID Register =

0x%4X\n",

memArray[0]);

printf (" viMoveIn16: 2 ID Register =

0x%4X\n",

memArray[1]);

/* Close sessions */

viClose (vi);

viClose (defaultRM); }

105

4

Programming via GPIB and VXI

Using the Memory Access Resource

For VISA 1.1 and later, the Memory Access (MEMACC) resource type has been added to VXI and GPIB-VXI. VXI::MEMACC and

GPIB-VXI::MEMACC allow access to all of the A16, A24, and A32 memory by providing the controller with access to arbitrary registers or memory addresses on memory-mapped buses.

The MEMACC resource, like any other resource, starts with the basic operations and attributes of other VISA resources. For example, modifying the state of an attribute is done via the operation

viSetAttribute (see VISA Resource Classes in the VISA Online Help for details).

Memory I/O Services

Memory I/O services include high-level memory I/O services and low-level memory I/O services.

High-Level Memory I/O Services

High-level memory I/O services allow register-level access to the interfaces that support direct memory access, such as the VXIbus,

VMEbus, MXIbus, or even VME or VXI memory through a system controlled by a GPIB-VXI controller. A resource exists for each interface to which the controller has access.

You can access memory on the interface bus through operations such as

viIn16 and viOut16. These operations encapsulate the map/unmap and peek/poke operations found in the low-level service. There is no need to explicitly map the memory to a window.

Low-Level Memory I/O Services

Low-level memory I/O services also allow register-level access to the interfaces that support direct memory access. Before an application can use the low-level service on the interface bus, it must map a range of addresses using the operation viMapAddress.

106 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Although the resource handles the allocation and operation of the window, the programmer must free the window via viUnMapAddress when finished. This makes the window available for the system to reallocate.

Sample: MEMACC Resource Program

This program demonstrates one way to use the MEMACC resource to open the entire VXI A16 memory and then calculate an offset to address a specific device.

/* peek16.c */

#include <stdio.h>

#include <stdlib.h>

#include <visa.h>

#define EXIT1

#define NO_EXIT 0

/* This function simplifies checking for VISA errors. */ void checkError( ViSession vi, ViStatus status, char

*errStr,int doexit){

char buf[256];

if (status >= VI_SUCCESS)

return;

buf[0] = 0;

viStatusDesc( vi, status, buf );

printf( "ERROR 0x%lx (%s)\n ’%s’\n", status, errStr,

buf );

if ( doexit == EXIT )

exit ( 1 );

} void main() {

ViSession drm;

ViSession vi;

ViUInt16inData16 = 0;

ViUInt16peekData16 = 0;

ViUInt8*addr;

107

4

Programming via GPIB and VXI

108

ViUInt16*addr16;

ViStatusstatus;

ViUInt16offset;

status = viOpenDefaultRM ( &drm );

checkError( 0, status, "viOpenDefaultRM",

EXIT );

/* Open a session to the VXI MEMACC Resource*/

status = viOpen( drm, "vxi0::memacc",

VI_NULL, VI_NULL,

&vi );

checkError (0, status, "viOpen", EXIT );

/* Calculate the A16 offset of the VXI

REgisters for

the device at VXI logical address 8. */

offset = 0xc000 + 64 * 8;

/* Open a map to all of A16 memory space. */

status = viMapAddress(vi,VI_A16_SPACE,0,0x10000,

VI_FALSE,0,(ViPAddr)(&addr));

checkError( vi, status, "viMapAddress", EXIT

);

/* Offset the address pointer returned from

viMapAddress for use with viPeek16. */

addr16 = (ViUInt16 *) (addr + offset);

/* Peek the contents of the card’s ID register

(offset

0 from card’s base address. Note that viPeek does

not return a status code. */

viPeek16( vi, addr16, &peekData16 );

/* Now use viIn16 and read the contents of the same

register */

status = viIn16(vi, VI_A16_SPACE,

ViBusAddress)offset, &inData16 );

checkError(vi, status, "viIn16", NO_EXIT );

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

/* Print the results. */

printf( "inData16 : 0x%04hx\n", inData16 );

printf( "peekData16: ox%04hx\n", peekData16

);

viClose( vi );

viClose (drm );

}

MEMACC Attribute Descriptions

Generic MEMACC Attributes

The following read-only attributes (VI_ATTR_TMO_VALUE is read/write) provide general interface information.

Table 22 Attributes That Provide General Interface Information

Attribute

VI_ATTR_INTF_TYPE

VI_ATTR_INTF_NUM

VI_ATTR_TMO_VALUE

VI_ATTR_INTF_INST_NA

ME

VI_ATTR_DMA_ALLOW_

EN

Description

Interface type of the given session.

Board number for the given interface.

Minimum timeout value to use, in milliseconds. A timeout value of

VI_TMO_IMMEDIATE means operation should never wait for the device to respond.

A timeout value of VI_TMO_INFINITE disables the timeout mechanism.

Human-readable text describing the given interface.

Specifies whether I/O accesses should use

DMA (VI_TRUE) or Programmed I/O

(VI_FALSE).

Agilent VISA User’s Guide 109

4

Programming via GPIB and VXI

VXI and GPIB-VXI Specific MEMACC Attributes

The following attributes, most of which are read/write, provide memory window control information.

Table 23 Attributes That Provide Memory Window Control

Information

Attribute

VI_ATTR_VXI_LA

Description

Logical address of the local controller.

VI_ATTR_SRC_INCREMENT Used in viMoveInxx operation to specify how much the source offset is to be incremented after every transfer. The default value is 1 and the viMoveInxx operation moves from consecutive elements.

If this attribute is set to 0, the viMoveInxx operation will always read from the same element, essentially treating the source as a

FIFO register.

VI_ATTR_DEST_INCREMEN

T

Used in viMoveOutxx operation to specify how much the destination offset is to be incremented after every transfer. The default value is 1 and the viMoveOutxx operation moves into consecutive elements.

VI_ATTR_WIN_ACCESS

VI_ATTR_WIN_BASE_ADD

R

VI_ATTR_WIN_SIZE

If this attribute is set to 0, the

viMoveOutxx operation will always write to the same element, essentially treating the destination as a FIFO register.

Specifies modes in which the current window may be addressed: not currently mapped, through the viPeekxx or viPokexx operations only, or through operations and/or by directly de-referencing the address parameter as a pointer.

Base address of the interface bus to which this window is mapped.

Size of the region mapped to this window.

110 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Table 23 Attributes That Provide Memory Window Control

Information

VI_ATTR_SRC_BYTE_ORDE

R

Specifies the byte order used in high-level access operations, such as viInxx and

viMoveInxx, when reading from the source.

VI_ATTR_DEST_BYTE_ORD

ER

Specifies the byte order used in high level access operations, such as viOutxx and

viMoveOutxx, when writing to the destination.

VI_ATTR_WIN_BYTE_ORD

ER

Specifies the byte order used in low-level access operations, such as viMapAddress,

viPeekxx, and viPokexx, when accessing the mapped window.

VI_ATTR_SRC_ACCESS_PRI

V

Specifies the address modifier used in high-level access operations, such as

viInxx and viMoveInxx, when reading from the source.

VI_ATTR_DEST_ACCESS_P

RIV

VI_ATTR_WIN_ACCESS_PR

IV

Specifies the address modifier used in high-level access operations such as

viOutxx and viMoveOutxx, when writing to destination.

Specifies the address modifier used in low-level access operations, such as

viMapAddress, viPeekxx, and viPokexx, when accessing the mapped window.

GPIB-VXI Specific MEMACC Attributes

The following read-only attributes provide specific address information about GPIB hardware.

Table 24 Attributes that Provide Specific Address Information

Attribute

VI_ATTR_INTF_PARENT_NUM

Description

Board number of the GPIB board to which the GPIB-VXI is attached.

111

4

Programming via GPIB and VXI

Table 24 Attributes that Provide Specific Address Information

VI_ATTR_GPIB_PRIMARY_ADD

R

VI_ATTR_GPIB_SECONDARY_A

DDR

Primary address of the GPIB-VXI controller used by the session.

Secondary address of the GPIB-VXI controller used by the session.

MEMACC Resource Event Attribute

The following read-only events provide notification that an asynchronous operation has completed.

Table 25 Events Providing Notification About Asynchronous

Operations

Attribute

VI_ATTR_EVENT_T

YPE

VI_ATTR_STATUS

Description

Unique logical identifier of the event.

VI_ATTR_JOB_ID

VI_ATTR_BUFFER

VI_ATTR_RET_COU

NT

Return code of the asynchronous I/O operation that has completed.

Job ID of the asynchronous I/O operation that has completed.

Address of a buffer used in an asynchronous operation.

Actual number of elements that were asynchronously transferred.

112 Agilent VISA User’s Guide

Programming via GPIB and VXI

4

Using VXI-Specific Attributes

VXI-specific attributes can be useful to determine the state of your VXI system. Attributes are read-only and read/write. Read-only attributes specify things such as the logical address of the VXI device and information about where your VXI device is mapped. This section shows how you might use some of the VXI-specific attributes. See VISA

Resource Classes in the VISA Online Help for information on VISA attributes.

Using the Map Address as a Pointer

The VI_ATTR_WIN_ACCESS read-only attribute specifies how a window can be accessed. You can access a mapped window with the

VISA low-level memory functions or with a C pointer if the address is de-referenced. To determine how to access the window, read the

VI_ATTR_WIN_ACCESS attribute.

VI_ATTR_WIN_ACCESS Settings

The VI_ATTR_WIN_ACCESS read-only attribute can be set to one of the following:

Table 26 Settings for the VI_ATTR_WIN_ACCESS Attribute

Setting Description

VI_NMAPPED Specifies that the window is not mapped.

VI_USE_OPERS Specifies that the window is mapped and you can only use the low-level memory functions to access the data.

VI_DEREF_AD

DR

Specifies that the window is mapped and has a de-referenced address. In this case you can use the low-level memory functions to access the data, or you can use a C pointer. Using a de-referenced C pointer will allow faster access to data.

Agilent VISA User’s Guide 113

4

Programming via GPIB and VXI

Sample: Determining Window Mapping

ViAddr address;

Vi UInt16 access;

ViUInt16 value;

.

.

.

viMapAddress(vi, VI_A16_SPACE, 0x00, 0x04,

VI_FALSE,

VI_NULL, &address); viGetAttribute(vi, VI_ATTR_WIN_ACCESS, &access);

.

.

If(access==VI_USE_OPERS) {

viPeek16(vi, (ViAddr)(((ViUInt16 *)address) +

4/sizeof(ViUInt16)), &value)

}else if (access==VI_DEREF_ADDR){

value=*((ViUInt16

*)address+4/sizeof(ViUInt16));

}else if (access==VI_NMAPPED){

return error;

}

.

.

Setting the VXI Trigger Line

The VI_ATTR_TRIG_ID attribute is used to set the VXI trigger line.

This attribute is listed under generic attributes and defaults to

VI_TRIG_SW (software trigger). To set one of the VXI trigger lines, set the VI_ATTR_TRIG_ID attribute as follows: viSetAttribute(vi, VI_ATTR_TRIG_ID,

VI_TRIG_TTL0);

114 Agilent VISA User’s Guide

Agilent VISA User’s Guide

Programming via GPIB and VXI

4

The above function sets the VXI trigger line to TTL trigger line 0

(VI_TRIG_TTL0). The following are valid VXI trigger lines. (Panel In is an Agilent extension of the VISA specification.)

Table 27 VXI Trigger Lines and Values

VXI Trigger

Line

VI_ATTR_TRIG_ID Value

TTL 0

TTL 1

VI_TRIG_TTL0

VI_TRIG_TTL1

TTL 2

TTL 3

TTL 4

TTL 5

VI_TRIG_TTL2

VI_TRIG_TTL3

VI_TRIG_TTL4

VI_TRIG_TTL5

TTL 6

TTL 7

ECL 0

ECL 1

Panel In

VI_TRIG_TTL6

VI_TRIG_TTL7

VI_TRIG_ECL0

VI_TRIG_ECL1

VI_TRIG_PANEL_IN

Once you set a VXI trigger line, you can set up an event handler to be

called when the trigger line fires. See “Using Events and Handlers” on page 46 for more information on setting up an event handler. Once the

VI_EVENT_TRIG event is enabled, the VI_ATTR_TRIG_ID becomes a read only attribute and cannot be changed. You must set this attribute prior to enabling event triggers.

The VI_ATTR_TRIG_ID attribute can also be used by viAssertTrigger function to assert software or hardware triggers. If VI_ATTR_TRIG_ID is VI_TRIG_SW, the device is sent a Word Serial Trigger command. If the attribute is any other value, a hardware trigger is sent on the line corresponding to the value of that attribute.

115

4

Programming via GPIB and VXI

116 Agilent VISA User’s Guide

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals

Download PDF

advertisement

Table of contents