Write binary data or a CAN message to a communication channel
Simulink Desktop Real-Time
Connect to and write unformatted binary data to a port, file, or CAN device. After you add a Packet Output block to your model, double-click the block to set its parameters.
The driver must be one of:
Standard Devices > File
Standard Devices > Serial Port
Standard Devices > TCP Protocol
Standard Devices > UDP Protocol
Kvaser > CAN Device
PEAK-System > CAN Device
Vector > CAN Device
MathWorks > virtual CAN (requires Vehicle Network Toolbox™)
When you install a UDP device, enter port addresses in decimal format in the Standard Devices UDP Protocol dialog box.
Any serial output port can send data with sample rates up to 500 Hz. To enable a faster sample rate of up to 10 kHz for some output serial ports, click Install new board, select Standard Devices > Serial Port, and select Direct port access.
The block does not support this option with all types of serial output hardware.
Input Data— Data to write to communication channel
Data values that are sent to communication channel as unformatted binary data.
Output packet size— Number of bytes that each input packet contains
32(default) | integer
Enter the number of bytes expected in each input packet. This number must match the number of bytes required by the type specifications in Output packet data types.
Output packet field data types— Output type and grouping of data in the packet sent to the device
'4*double'(default) | character vector | cell array of character vector
One or more character vectors that specify how data provided by the application is formatted into a packet. The Packet Output block has an input port corresponding to each character vector in Output packet field data types. Changing the number of character vectors changes the number of ports.
Each character vector has the format [
The data that the character vector describes has the type specified
datatype and the width specified by
n is not specified, the width is
'double' means one
'4*int8' means a vector of four
You can also type
'CAN_MESSAGE' to specify a single
The signal input to each port of the Packet Output block can be a scalar or vector of the data type. The character vector for each port specifies the type to be used when its signal is output to the device. If the character vector for a port matches the type of the signal input to that port, the signal value appears verbatim in the output packet.
You can also perform type conversion on output. For example,
assume that the input is a four-element
and the character vector is
'4*int8'. The four
integers are converted to
int8 before being written
to the packet. The resulting data occupies 4 bytes in the output packet.
The block forces an out-of-range value to the maximum value for that data type.
Output packet field byte order— Byte order of packet being sent to device
Little Endian(default) |
From the list, select:
Little Endian (default)
— Receive multibyte values in little-endian format.
Big Endian — Receive
multibyte values in big-endian format.
Initial value— Data to send when simulation begins
Optional. Enter a vector that has the same number of elements as the sum of the widths of the input signals across all ports. When simulation begins, send the specified data before the other data that is sent during simulation.
Final value— Data to send when simulation ends
Optional. Enter a vector that has the same number of elements as the sum of the widths of the input signals across all ports. When simulation ends, after the other data that is sent during simulation, send the specified data.