xPC Target    

Creating GPIB Message Structures

GPIB drivers use MATLAB structures to send and receive messages, and map the input and output ports on the GPIB driver blocks to the data written and read from the GPIB devices.

After you add GPIB driver blocks to your Simulink model, you can create the message structures to communicate with the GPIB controller. You need to create and load these structures into the MATLAB workspace before you build your target application. The easiest way to create these structures is to create an M-file and load that M-file into the MATLAB workspace.

  1. In the MATLAB command window, and from the File menu, point to New, and then click M-file.
  1. A MATLAB text editor window opens.

  1. Enter the initialization and send/receive messages. Each message is an element in a MATLAB structure array with a series of fields. For information and examples of these fields, see GPIB Initialization and Termination Message Structures and GPIB Send/Receive Message Structure.
  1. As an example, if you have a multimeter attached to a GPIB bus that has an address of 16, needs the initialization command :conf:volt:dc to set the device to read DC voltages, and uses the command :read? to read one voltage value, you could type the following.

    Note Field names in the structures are case-sensitive.

    This example did not need a termination structure. But if it did, the format of the structure is the same as the initialization structure. For example, a termination structure could have a message with the .Command and .SendData fields.

  1. From the File menu, click Save As. In the Save As File dialog box, enter the name of the M-file script. For example, enter
  2. Close the text editing window.
  3. In the MATLAB command window, type the name of the M-file script you created with the GPIB structures. For example, type
  1. MATLAB loads and runs the M-file script to create the message structures in the MATLAB workspace needed by the GPIB driver blocks.

  1. Open your Simulink model, or press Ctrl+D.
  1. The GPIB driver blocks are updated with the information from the structures. For example, inputs and outputs defined in the structures are now visible on the driver blocks.

  1. Connect the input and output ports on the RS-232 driver blocks to other blocks in your Simulink model.
  1. Your model should look similar to the figure shown below.

  1. Set the PreLoadFcn for your Simulink model to load the message structures when you open the model. For example, if you saved the message structures in the M-file GPIB_messages, type
  1. Note If you do not manually load the message structures before opening your Simulink model, or have the message structures automatically loaded with the model, the port connections to the GPIB driver blocks break.

Your next task is to build the target application and download it to the target PC.


  Adding GPIB Driver Blocks GPIB Simulink Block Reference