Stream Scan Stream Get Property navigation bar

Table of Contents

Stream Send

Sends data over a stream.

Library

QUARC Targets/Communications/Advanced

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

qc_open_library('quarc_library/Communications/Advanced')

Description

Stream Send

The Stream Send block sends data over a stream. The operation of this block is affected by the blocking mode of the stream connected to its input. Streams have two modes: blocking (the default) and non-blocking. The blocking mode of the stream is determined by the Stream Connect or Stream Accept block which created the stream. The Stream Send block cannot be used with streams created using the Stream Listen block.

This block writes data to the stream buffer. It attempts to store all of the data at its data input in the stream buffer. If the stream has been configured to swap bytes then this block will swap the order of the bytes within each element in the input signal when storing the data in the stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed using the Stream Flush block or there is no more room available in the stream buffer. If an error occurs, then it returns a negative error code at its err output. If the connection is closed it is considered an error condition.

For blocking streams, this block may wait while attempting to flush the stream buffer. All the data will be consumed and 1 is returned at its err output. Some of the data may remain in the stream buffer and not be sent until the next time the Stream Flush block is called or there is no more room available in the stream buffer. If an error occurs then the error code is returned at its err output and the stream should be closed.

If the stream is non-blocking, then this block always returns immediately. It returns 1 if all the elements of the input signal were sent successfully. If the array could not be sent without blocking, then -QERR_WOULD_BLOCK is returned at its err output. The Compare to Error block may be used to check for specific error codes. The Stream Poll block may be used to wait or poll for space in the stream buffer to store the data or other events. If any other error occurs then the stream should be closed.

This block does not support two threads calling Stream Send or Stream Flush at the same time. However, Stream Send or Stream Flush may be called by another thread at the same time as Stream Receive.

Helpful Hints

Simpler blocks

Hint The Stream Write block has similar functionality to Stream Send, but is easier to use. Although it is an Intermediate stream block, it may be used with the Advanced blocks also.

Variable-size signals

Hint When using the Stream Send block with variable-size signals in subsystems, make sure any

Action Port

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc ActionPort;
,
Enable

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc Enable
or
Trigger

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc Trigger
ports are configured to propagate the sizes of variable-size signals during execution. Refer to Variable-Size Signals for more information on variable-size signals.

Input Ports

stm

A reference to the stream created by the Stream Connect or Stream Accept block. If the stream is closed or is otherwise invalid then the negative error code -QERR_INVALID_STREAM is returned by the err output.

data

The data to write to the stream buffer. The input signal is treated as an atomic unit. It will never write part of the data to the stream buffer. These semantics make it much easier to deal with streams in Simulink where it is difficult to deal with "parts" of a signal. Note that the buffer size for the stream must be at least as large as the input signal or -QERR_STREAM_BUFFER_TOO_SMALL is returned by the err output. Multi-dimensional and variable-size signals as well as bus inputs are supported. See Using Bus Objects with QUARC for more information on bus signals, and refer to Variable-Size Signals for more details on variable-size signals.

Output Ports

stm

A reference to the stream. This output is merely a copy of the stm input. Providing this output makes it much easier to establish the execution order of Stream blocks in the diagram because Simulink generally executes daisy-chained blocks in sequence.

err

An int32 value indicating whether the input signal was written to the stream buffer successfully. For blocking streams, this value will be 1 unless an error occurs. If an error occurs then this value is a negative error code. If the stream is non-blocking and the data could not be written to the stream buffer then -QERR_WOULD_BLOCK is output. See Error Codes for the different error codes and their values. Use the Compare to Error block rather than the error code itself to check for specific error codes. To check for errors in general use the Compare to Zero block to check whether err output is less than zero.

Data Type Support

The Stream Send block accepts signals of any of the built-in Simulink data types at its data input, including multi-dimensional signals. Fixed point is not currently supported.

Variable-size signals are accepted at its data input. In this case, it uses the current dimensions of the signal to determine how many elements to send. Variable-size signals may be multi-dimensional, but cannot be bus signals. See Variable-Size Signals for more information on variable-size signals.

The Stream Send block also accepts bus signals at its data input. Buses are useful for sending a mix of different data types in a single send operation. Bus signals are created using the

Bus Creator

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc('Bus Creator')
block supplied with Simulink. A
Simulink.Bus

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc('Simulink.Bus')
object must be created that defines the data types of the signals within the bus. This object may be created using the Bus Editor and then saved to a MAT file. To ensure that the bus object is always defined, load this MAT file within the InitFcn callback of the Simulink model. See Using Bus Objects with QUARC for more information on bus signals.

Parameters and Dialog Box

Stream Send

Send dimensions

This option is used with variable-sized signals. Checking this option causes the current dimensions of the input signal to be sent prior to the data itself so that the peer knows the dimensions of the signal. The block automatically determines the appropriate integer size required for each dimension based on the maximum dimensions of the input signal. For example, if the maximum size of a dimension is less than 256 then a single 8-bit integer is used to transmit that dimension. If the maximum size is less than 65536 then a 16-bit integer is used. Dimensions larger than 32-bits are not supported. Refer to Variable-Size Signals for more information on variable-size signals.

Targets

Target Name

Compatible*

Model Referencing

Comments

QUARC Win32 Target

Yes

Yes

QUARC Win64 Target

Yes

Yes

QUARC Linux Nvidia Target

Yes

Yes

QUARC Linux QBot Platform Target

Yes

Yes

QUARC Linux QCar 2 Target

Yes

Yes

QUARC Linux QDrone 2 Target

Yes

Yes

QUARC Linux Raspberry Pi 3 Target

Yes

Yes

QUARC Linux Raspberry Pi 4 Target

Yes

Yes

QUARC Linux RT ARMv7 Target

Yes

Yes

QUARC Linux x64 Target

Yes

Yes

QUARC Linux DuoVero Target

Yes

Yes

QUARC Linux DuoVero 2016 Target

Yes

Yes

QUARC Linux Verdex Target

Yes

Yes

QUARC QNX x86 Target

Yes

Yes

Last fully supported in QUARC 2018.

Rapid Simulation (RSIM) Target

Yes

Yes

S-Function Target

No

N/A

Old technology. Use model referencing instead.

Normal simulation

Yes

Yes

If the Stream Connect block which created the stream is not active during normal simulation, then the Stream Send block does nothing. Otherwise it sends the data to the stream.

* Compatible means that the block can be compiled for the target.

See Also

 

navigation bar