Write formatted ASCII data to communication channel
Simulink Desktop Real-Time
Write formatted ASCII data to a port or file. After you have added a Stream Output block to your model, double-click the Stream Output block to open the Block Parameters: Stream Output dialog box.
The driver must be one of:
Standard Devices > File
Standard Devices > Serial Port
Standard Devices > TCP Protocol
Standard Devices > UDP Protocol
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
numeric vector | string
Data values that are sent to the communication channel as ASCII data, encoded according to Format string.
Input port sizes — Specify number and width of ports
1 (default) | vector
Enter a port width, or vector of port widths. The number of elements
determines the number of input ports. Each port has the width specified by
the corresponding element. For example, specifying
[3,1,2] indicates that the block has three input
ports: a vector of width
3, a scalar, and a vector of
2, for a total of six elements. You specify only
Format string — Format of data items being written to the stream
'%g' (default) | character vector
Enter a specification in the same format used by C library I/O routines
printf. The format string describes the data to be
sent. The format string must have the same number of specifiers as the sum
of the elements of Input port sizes. If the
%c for string, the
created input port of type string only accepts string signals. The
Input port sizes parameter value for this input port
"1", because strings can only be scalars.
For example, assume that Input port sizes is
[3,1,2]. Then a Format string of
'%d %d %d %f %d %d' outputs ASCII
Three integers from the vector on the first input port
One double from the scalar on the input second port
Two integers from the vector on the third input port
If the data type specified in the Format string for a value differs from the type of the actual value, type conversion occurs. Converted data that conforms to the Format string is output as ASCII to the device.
Initial string — Data to send when simulation begins
Optional. Enter a character vector. When simulation begins, send the specified data before the other data that is sent during simulation.
The character vector can contain anything. You can use it to initialize a device. It is sent literally as specified, without reference to Format string.
Final string — Data to send when simulation ends
Optional. Enter a character vector. When simulation ends, after the other data that is sent during simulation, send the specified data.
The character vector can contain anything. You can use it to shut down a device. It is sent literally as specified, without reference to Format string
Version HistoryIntroduced in R2007b
R2019b: Stream Input and Stream Output Blocks Support String Signals
The Stream Input block and Stream Output block support Simulink string signals.
R2019a: RS-232 Serial Port Drivers Support for macOS
The serial port drivers for the Packet Input block, Packet Output block, Stream Input block, and Stream Output block support macOS systems. In previous releases, the serial port drivers for these blocks supported Windows® systems only.
R2018a: TCP and UDP Protocol Support for Stream Input and Stream Output
The TCP protocol and UDP protocol drivers for the Stream Input block and Stream Output block are available from the Standard Devices list. From the Install new board button, select Standard Devices > TCP Protocol or select Standard Devices > UDP Protocol.