Register-Based Communication Example Discussion
The general structure of this example is very similar to that of the message-based communication example. For this reason, we merely point out the basic differences as denoted in bold text:
- A different address string is used for the VXI device.
- The string functions from the message-based communication example are replaced with register functions.
The address string is still the same format as the address string in the message-based communication example, but it has replaced the GPIB with VXI. Again, remember that the difference in the address string name is the extent to which the specific interface bus will be important. Indeed, since this is a simple string, it is possible to have the program read in the string from a user input or a configuration file. Thus, the program can be compiled and is still portable to different platforms, such as from a GPIB-VXI to a MXIbus board.
As you can see from the programming code, you use different functions to perform I/O with a register-based device. The functions viIn16() and viOut16() read and write 16-bit values to registers in either the A16, A24, or A32 space of VXI. As with the message-based functions, you start by specifying which device you want to talk to by supplying the instr variable. You then identify the address space you are targeting, such as VI_A16_SPACE.
The next parameter warrants close examination. Notice that we want to read in the value of the Device ID register for the device at logical address 16. Logical addresses start at offset 0xC000 in A16 space, and each logical address gets 0x40 bytes of address space. Because the Device ID register is the first address within that 0x40 bytes, the absolute address of the Device ID register for logical address 16 is calculated as follows:
0xC000 + (0x40 * 16) = 0xC400
However, notice that the offset we supplied was 0. The reason for this is that the instr parameter identifies which device you are talking to, and therefore the VISA driver is able to perform the address calculation itself. The 0 indicates the first register in the 0x40 bytes of address space, or the Device ID register. The same holds true for the viOut16() call. Even in A24 or A32 space, although it is possible that you are talking to a device whose memory starts at 0x0, it is more likely that the VXI Resource Manager has provided some other offset, such as 0x200000 for the memory. However, because instr identifies the device, and the Resource Manager has told the driver the offset address of the device's memory, you do not need to know the details of the absolute address. Just provide the offset within the memory space, and VISA does the rest. For more detailed information about other defined VXI registers, refer to the NI-VXI Help.
Again, when you are done with the register I/O, use viClose() to shut down the system.