Instrument Control Toolbox    

Register-Based Communication

VXI instruments are either message-based or register-based. Generally, it is assumed that message-based instruments are easier to use, while register-based instruments are faster. A message-based instrument has its own processor that allows it to interpret high-level commands such as a SCPI command. Therefore, to communicate with a message-based instrument, you can use the read and write functions fscanf, fread, fprintf, and fwrite. For detailed information about these functions, refer to Writing and Reading Data.

If the message-based instrument also contains shared memory, then you can access the shared memory through register-based read and write operations. A register-based instrument usually does not have its own processor to interpret high-level commands. Therefore, to communicate with a register-based instrument, you need to use read and write functions that access the register.

There are two types of register-based write and read functions: low-level and high-level. The main advantage of the high-level functions is ease of use. Refer to Example: Using High-Level Memory Functions for more information. The main advantage of the low-level functions is speed. Refer to Example: Using Low-Level Memory Functions for more information.

The functions associated with register-based write and read operations are given below.

Table 4-5: VISA-VXI Register-Based Write and Read Functions 
Function Name
Description
memmap
Map memory for low-level memory read and write operations.
mempeek
Low-level memory read from VXI register.
mempoke
Low-level memory write to VXI register.
memread
High-level memory read from VXI register.
memunmap
Unmap memory for low-level memory read and write operations.
memwrite
High-level memory write to VXI register.

The properties associated with register-based write and read operations are given below.

Table 4-6: VISA-VXI Register-Based Write and Read Properties 
Property Name
Description
MappedMemoryBase
Indicate the base memory address of the mapped memory.
MappedMemorySize
Indicate the size of the mapped memory for low-level read and write operations.
MemoryBase
Indicate the base address of the A24 or A32 space.
MemoryIncrement
Specify if the VXI register offset increments after data is transferred.
MemorySize
Indicate the size of the memory requested in the A24 or A32 address space.
MemorySpace
Define the address space used by the instrument.

Example: Understanding Your Instrument's Register Characteristics

This example explores the register characteristics for an Agilent E1432A 16-channel 51.2 kSa/s digitizer with a DSP module.

All VXI instruments have an A16 memory space consisting of 64 bytes. It is known as an A16 space because the addresses are 16 bits wide. Register-based instruments provide a memory map of the address space that describes the information contained within the A16 space. Some VXI instruments also have an A24 or A32 space if the 64 bytes provided by the A16 space are not enough to perform the necessary tasks. A VXI instrument cannot use both the A24 and A32 space.

  1. Create an instrument object -- Create the VISA-VXI object vv associated with a VXI chassis with index 0, and an Agilent E1432A digitizer with logical address 130.
  2. Connect to the instrument -- Connect vv to the instrument.
  1. The MemorySpace property indicates the type of memory space the instrument supports. By default, all instruments support A16 memory space. However, this property can be A16/A24 or A16/A32 if the instrument also supports A24 or A32 memory space, respectively.

    If the VISA-VXI object is not connected to the instrument, MemorySpace always returns the default value of A16.

    The MemoryBase property indicates the base address of the A24 or A32 space, and is defined as a hexadecimal string. The MemorySize property indicates the size of the A24 or A32 space. If the VXI instrument supports only the A16 memory space, MemoryBase defaults to 0H and MemorySize defaults to 0.

  1. Disconnect and clean up -- When you no longer need vv, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.

Example: Using High-Level Memory Functions

This example uses the high-level memory functions, memread and memwrite, to access register information for an Agilent E1432A 16-channel 51.2 kSa/s digitizer with a DSP module. The main advantage of these high-level functions is ease of use -- you can access multiple registers with one function call, and the memory that is to be accessed is automatically mapped for you. The main disadvantage is the lack of speed -- they are slower than the low-level memory functions.

Each register contains 16 bits, and is associated with an offset value that you supply to memread or memwrite. The first four registers of the digitizer are accessed in this example, and are described below.

Table 4-7: Agilent E1432A Register Information  
Register
Offset
Description
ID
0
This register provides instrument configuration information and is always defined as CFFF. Bits 15 and 14 are 1, indicating that the instrument is register-based. Bits 13 and 12 are 0, indicating that the instrument supports the A24 memory space. The remaining bits are all 1, indicating the device ID.
Device Type
2
This register provides instrument configuration information. Bits 15-12 indicate the memory required by the A24 space. The remaining bits indicate the model code for the instrument.
Status
4
This register provides instrument status information. For example, bit 15 indicates whether you can access the A24 registers, and bit 6 indicates whether a DSP communication error occurred.
Offset
6
This register defines the base address of the instrument's A24 registers. Bits 15-12 map the VME Bus address lines A23-A20 for A24 register access. The remaining bits are all 0.

For more detailed information about these registers, refer to the HP E1432A User's Guide.

  1. Create an instrument object -- Create the VISA-VXI object vv associated with a VXI chassis with index 0, and an Agilent E1432A digitizer with logical address is 130.
  2. Connect to the instrument -- Connect vv to the instrument.
  3. Write and read data -- The following command performs a high-level read of the ID Register, which has an offset of 0.
  1. Convert reg1 to a hexadecimal value and a binary string. Note that the hex value is CFFF and the least significant 12 bits are all 1, as expected.

    You can read multiple registers with memread. The following command reads the next three registers. An offset of 2 indicates that the read operation begins with the Device Type Register.

    The following commands write to the Offset Register and then read the value back. Note that if you change the value of this register, you will not be able to access the A24 space.

    Note that the least significant 12 bits are all 0, as expected.

    Restore the original register value, which is stored in the reg24 variable.

  1. Disconnect and clean up -- When you no longer need vv, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.

Example: Using Low-Level Memory Functions

This example uses the low-level memory functions, mempeek and mempoke, to access register information for an Agilent E1432A 16-channel 51.2 kSa/s digitizer with a DSP module. The main advantage of these low-level functions is speed -- they are faster than the high-level memory functions. The main disadvantages include the inability to access multiple registers with one function call, errors are not reported, and you must map the memory that is to be accessed.

For information about the digitizer registers accessed in this example, refer to Example: Using High-Level Memory Functions.

  1. Create an instrument object -- Create the VISA-VXI object vv associated with a VXI chassis with index 0, and an Agilent E1432A digitizer with logical address 130.
  2. Connect to the instrument -- Connect vv to the instrument.
  3. Write and read data -- Before you can use the low-level memory functions, you must first map the memory space with the memmap function. If the memory requested by memmap does not exist, an error is returned. The following command maps the first 16 registers of the A16 memory space.
  1. The MappedMemoryBase and MappedMemorySize properties indicate if memory has been mapped. MappedMemoryBase is the base address of the mapped memory and is defined as a hexadecimal string. MappedMemorySize is the size of the mapped memory. These properties are similar to the MemoryBase and MemorySize properties that describe the A24 or A32 memory space.

    The following command performs a low-level read of the ID Register, which has an offset of 0.

    The following command performs a low-level read of the Offset Register, which has an offset of 6.

    The following commands write to the Offset Register and then read the value back. Note that if you change the value of this register, you will not be able to access the A24 space.

    Restore the original register value.

    When you have finished accessing the registers, you should unmap the memory with the memunmap function.

    If memory is still mapped when the object is disconnected from the instrument, the memory is automatically unmapped for you.

  1. Disconnect and clean up -- When you no longer need vv, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.

  The VISA-VXI Address The GPIB-VXI Interface