Manipulating the Pointer
- Updated2025-10-10
- 2 minute(s) read
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.
C Example
#include "visa.h"
#define ADD_OFFSET(addr, offs) (((ViPByte)addr) + (offs))
int main(void)
{
ViStatus status; /* For checking errors */
ViAddr defaultRM, instr; /* Communication channels */
ViUInt16 address; /* User pointer */
ViSession value; /* 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;
}
Visual Basic Example
Private Sub vbMain()
Dim stat As ViStatus
Dim dfltRM As ViSession
Dim sesn As ViSession
Dim addr As ViAddr
Dim mSpace As Integer
Dim Value As Integer
Rem Open Default Resource Manager
stat = viOpenDefaultRM(dfltRM)
If (stat < VI_SUCCESS) Then
Rem Error initializing VISA...exiting
Exit Sub
End If
Rem Open communication with VXI Device at Logical Address 16
Rem NOTE: For simplicity, we will not show error checking
stat = viOpen(dfltRM, "VXI0::16::INSTR", VI_NULL, VI_NULL, sesn)
mSpace = VI_A16_SPACE
stat = viMapAddress(sesn, mSpace, 0, &H40, VI_FALSE, VI_NULL, addr)
viPeek16 sesn, addr, Value
Rem Access a different register by manipulating the pointer.
viPeek16 sesn, addr + 2, Value
stat = viUnmapAddress(sesn)
Rem Close down the system
stat = viClose(sesn)
stat = viClose(dfltRM)
End Sub