Using Low-Level Memory Functions with GPIB and VXI
This section contains information specific to the Windows product.
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:
Map memory space using viMapAddress.
Read and write to the register's contents using viPeek32 and viPoke32.
Unmap the memory space using viUnmapAddress.
Low-Level Memory Functions
You can program the registers using low-level functions for 8-, 16-, 32-, or 64-bit transfers. The following table summarizes the low-level memory functions.
|
Function |
Description |
|---|---|
|
viMapAddress(vi, mapSpace, mapBase, mapSize, access, suggested, address); |
Maps the specified memory space. |
|
viPeek8(vi, addr, val8); |
Reads 8 bits of data from address specified. |
|
viPeek16(vi, addr, val16); |
Reads 16 bits of data from address specified. |
|
viPeek32(vi, addr, val32); |
Reads 32 bits of data from address specified. |
|
viPeek64(vi, addr, val64); |
Reads 64 bits of data from address specified. |
|
viPoke8(vi, addr, val8); |
Writes 8 bits of data to address specified. |
|
viPoke16(vi, addr, val16); |
Writes 16 bits of data to address specified. |
|
viPoke32(vi, addr, val32); |
Writes 32 bits of data to address specified. |
|
viPoke64(vi, addr, val64); |
Writes 64 bits of data to address specified. |
|
viUnmapAddress(vi); |
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
VI_A64_SPACE - Maps in VXI/MXI A64 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);
/* 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.
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
The vxill.c sample program uses low-level memory functions and the VXI interface to read the ID and Device Type registers of a device at VXI0::24.
Sample: Using the GPIB-VXI Interface (Low-Level) Memory Functions
The gpibvxil.c sample 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.