Manipulating the Pointer

NI-VISA

Manipulating the Pointer

Every time you call viMapAddress(), the pointer you get back is valid for accessing a region of addresses. Therefore, if you call viMapAddress() with mapBase set to address 0 and mapSize to 0x40 (the configuration register space for a VXI device), you can access not only the register located at address 0, but also registers in the same vicinity by manipulating the pointer returned by viMapAddress(). For example, if you want to access another register at address 0x2, you can add 2 to the pointer. You can add up to and including 0x3F to the pointer to access these registers in this example because we have specified 0x40 as the map size. However, notice that you cannot subtract any value from the address variable because the mapping starts at that location and cannot go backwards. The following example shows how you can access other registers from address.

Example

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

#include "visa.h"

#define ADD_OFFSET(addr, offs) (((ViPByte)addr) + (offs))

int main(void)
{

ViStatus
ViAddr
ViUInt16
ViSession
status;
defaultRM, instr;
address;
value;
/* For checking errors */
/* Communication channels */
/* User pointer */
/* To store register value */
/* Begin by initializing the system */
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS) {

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

}

/* Open communication with VXI Device at Logical Address 16 */
/* NOTE: For simplicity, we will not show error checking */
status = viOpen(defaultRM, "VXI0::16::INSTR", VI_NULL, VI_NULL, &instr);

status = viMapAddress(instr, VI_A16_SPACE, 0, 0x40, VI_FALSE, VI_NULL, &address);

viPeek16(instr, address, &value);
/* Access a different register by manipulating the pointer. */
viPeek16(instr, ADD_OFFSET(address, 2), &value);

status = viUnmapAddress(instr);

/* Close down the system */
status = viClose(instr);
status = viClose(defaultRM);
return 0;

}