| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
| On this page… |
|---|
GPIB Initialization and Termination Message Structures GPIB Send/Receive Message Structure |
You do not use all message fields in all messages. For example, a message to send data would not use the message field .RecData, but would use the field .SendData. However, knowing the possible message fields is helpful when you are creating any of the message structures.
The formats for the initialization and termination structures are similar to the send/receive structure except for a few differences:
The initialization and termination structures do not need to receive or send information through driver block ports on your Simulink model. Therefore, the initialization and termination structures do not use the message fields .InputPorts, .OutputPorts, .RecData, and .OutputDataTypes.
Below is a description of the possible message fields for the initialization and termination structures. The order of the message fields does not matter. However, the field names are case sensitive.
Message Fields | Description |
|---|---|
Address | Sets the GPIB address for the device being accessed and defines the keyword ADDR. Default value = []. |
Command | GPIB command sent to a GPIB device. Default value = ''. |
SendData | Data sent with the GPIB command. Default value = ''. |
RdLength | Defines the length of the acknowledge string, in bytes, from the GPIB controller. |
Ack | The expected acknowledgment string from the controller as a result of an initialization or termination message. If this value is set, you need to set the time-out value. If no string is defined, then no acknowledge is expected. |
Timeout | Time, in seconds, allowed for the GPIB controller to respond to a message and send back an acknowledge string. Default value = 0.049 seconds. If the time-out value is exceeded, a time-out error is reported. |
Below is a description of the possible fields for the send/receive message structure. The order of the message fields in a message does not matter. However, the field names are case sensitive.
Message Fields | Description |
|---|---|
Address | Sets the GPIB address for the device being accessed. After the GPIB address is set, the remaining messages use this address value until another message changes the address value. Default value = 0. The keyword ADDR is equal to the value in the message field .Address. You can use this keyword in the message fields .Command or .SendData to replace the numerical value of the GPIB address. For example, you can write GPIB_Send_Receive(1).Command='wrt 16'; Or you can write GPIB_Send_Receive(1).Address = 16; GPIB_Send_Receive(1).Command='wrt ADDR'; |
Command | GPIB command sent to a GPIB device. Default value = ''. |
SendData | Data sent with the GPIB command. Default value = ''. |
InputPorts | Defines the input ports for the driver block. Data from the input ports is sent to the GPIB device with the message fields .Command and .SendData. Default value = []. The highest number you enter determines the number of input ports on the driver block. For example, the following message creates two input ports on the driver block, and passes data from the input ports to the read command. GPIB_Send_Receive(1).Command = 'rd #%d %d'; GPIB_Send_Receive(1).InputPorts= [1 2]; The first port is used to dynamically provide the length of the receive string, while the second port provides the value of the GPIB device. |
RecData | Format of the data received from the GPIB device. Default value = ''. The format of this statement is very similar to a scanf statement. The read data is mapped to the output ports defined in the field .OutputPorts. If a negative output port is given, the data is read in, but not sent to any output port. For example, to read from a GPIB device with an address of 16, one floating-point number with a maximum number of bytes of 20, and send the data to the first driver block output, type the following: GPIB_Send_Receive(1).Command = 'rd #20 16'; GPIB_Send_Receive(1).RecData = '%f'; GPIB_Send_Receive(1).OutputPorts = [1]; |
RdLength | Defines the length of the data, in bytes, received with the read command and defines the keyword LENGTH. Default value = 0. |
OutputPorts | Defines the output ports from the driver block. Data received from a GPIB device with the read command is sent to the output ports. Default value = []. The highest number you enter determines the number of output ports on the driver block. For example, to use output ports 1 and 2 on the driver block, type GPIB_Send_Receive.OutputPorts = [1 2]; |
OutputData Types | Defines the data types for the output ports on the driver block. Default value = []. If this value is not defined, and there are output ports, the default type is double. Also, if there are more output ports than output data types listed, the default type for the undefined ports is double. |
Wait | The amount of time, in seconds, to wait before executing the next message. This value is limited to 50 milliseconds. Default value = 0. |
Timeout | Time, in seconds, the driver block waits for data to be returned. Default value = 0.049. |
xPC Target defines the abbreviations wrt and rd to make message writing with GPIB commands easier. When the message interpreter sees the statements
Structure_name(index).'wrt', it is replaced with Structure_name(index).'wrt ADDR'. For example, you could write
GPIB_Initialize(1).Command = 'wrt 8';
or you could write
GPIB_Initialize(1).Address = 8; GPIB_Initialize(1).Command = 'wrt';
The following message fields, with the keyword ADDR, use the address value 8 defined in the message field .Address.
Structure_name (index).Command = 'rd', it is replaced with Structure_name(index).Command = 'rd #LENGTH ADDR'. For example, you could write
GPIB_Initialize(1).Command = 'rd #10 8';
or you could write
GPIB_Initialize(1).Address = 8; GPIB_Initialize(1).RdLength = 10 GPIB_Initialize(1).Command = 'wrt';
If you enter numerical values in the wrt and rd commands, then the command uses those values instead of the values in the variables ADDR and LENGH. For example, the following message uses the GPIB address 10 even though the value for ADDR is defined as 8.
GPIB_Initialize(1).Address = 8; GPIB_Initialize(1).Command = 'wrt 10';
When a GPIB rd command is sent to the GPIB controller, the controller responds with the data and length of data. To make using this command easier, the xPC Target driver block discards the length of data information. For example, using the normal GPIB rd command, you could write
GPIB_Message(1).Command = 'rd #20 16'; GPIB_Message(1).RecData = '%f%d'; GPIB_Message(1).OutputPorts = [1 -1];
The code %d reads the length of data and the -1 discards the length. Using the modified xPC Target rd command, you would write
GPIB_message(1).Command = 'rd #20 16'; GPIB_message(1).RecData = '%f'; GPIB_message(1).OutputPorts = [1];
The message interpreter automatically places the correct escape characters at the end of the message fields .Command, .SendData, and .Ack. However, if you add the escape characters, then the message interpreter does not add additional characters.
The escape characters are \\, \a, \b, \f, \r, \t, \v, \', \'', and \n.
For example, you can write
GPIB_Message.Command = 'wrt 16\n'; GPIB_Message.SendData = ':conf:volt:dc\r'; GPIB_Message.Ack = '10\n\r';
or you can write the following, and the appropriate escape characters are added.
GPIB_Message.Command = 'wrt 16'; GPIB_Message.SendData = ':conf:volt:dc'; GPIB_Message.Ack = '10';
The following table lists the supported data types for the message fields .SendData and .RecData:
Format | Description |
|---|---|
%c and %C | Single character and wide character |
%d or %I | Signed decimal integer |
%u | Unsigned decimal integer |
%o | Unsigned octal integer |
%x or %X | Unsigned hexadecimal integer using 'abcdef' or 'ABCDEF' for the hexadecimal digits. |
%e or %E | Exponential format using e or E |
%f | Floating point |
%g | Signed value printed in f or e format depending on which is smaller |
%G | Signed value printed in f or E format depending on which is smaller |
![]() | Using GPIB Drivers | Boards and Blocks — Alphabetical List | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |