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.
:conf:volt:d
c 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.
GPIB_Initialize(1).Command = 'wrt 16'; GPIB_Initialize(1).SendData = ':conf:volt:dc'; GPIB_Send_Receive(1).Address= 16; GPIB_Send_Receive(1).Command = 'wrt 16'; GPIB_Send_Receive(1).SendData = ':read?'; GPIB_Send_Receive(1).Timeout = 0.05; GPIB_Send_Receive(2).Command = 'rd 16'; GPIB_Send_Receive(2).RecData = '%f'; GPIB_Send_Receive(2).RdLength = 20; GPIB_Send_Receive(2).OutputPorts = [1]; GPIB_Send_Receive(2).OutputDataTypes = {'double'}; GPIB_Send_Receive(2).Timeout = 0.15;
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.
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
Your next task is to build the target application and download it to the target PC.
![]() | Adding GPIB Driver Blocks | GPIB Simulink Block Reference | ![]() |