Start of trail Serial Receiver Write navigation bar

Table of Contents

Serial Receiver Read

Receives commands from a serial receiver such as DSMX or S.BUS. This block is intended for use in the main diagram.

Library

QUARC Targets/Communications/Serial Receiver

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/Serial Receiver')

Description

Serial Receiver Read

The Serial Receiver Read block receives commands from a serial receiver over a stream. The stream is typically a serial connection. The commands for up to 16 channels are extracted from the incoming frames and output from the block, along with any extra information contained in the data. A vector is also output indicating which channel data is new, as some protocols do not send all the channel data in one frame.

This block does not wait for data to arrive. It is non-blocking since frames are received over the stream in a background thread. The most recent commands are output from the block.

The Serial Receiver Read block maintains a persistent connection with the stream, so it will reconnect automatically if the connection is lost. The current state of the connection is also output from the block.

If an error occurs, then the block returns a negative error code at its err output. The Compare to Error block may be used to check for specific error codes.

Configuration Requirements

DSM serial configuration

Configure The serial stream for DSMX or DSM2 is typically configured for 115200 baud, one stop bit, no parity and no flow control. The URI to use is:

serial://localhost:0?baud='115200',parity='none',stop='1',flow='none'.

Note that the port number in the URI must be changed to match the UART used to receive the DSMX or DSM2 signals.

S.BUS serial configuration

Configure The serial stream for S.BUS must be configured for 100000 baud, two stop bits, even parity and no flow control. The URI to use is:

serial://localhost:0?baud='100000',parity='even',stop='2',flow='none'.

Note that the port number in the URI must be changed to match the UART used to receive the S.BUS signals.

S.BUS signal inversion

Configure S.BUS signals are generally inverted from the signals produced by a standard UART, so an inverter may be required on the S.BUS signal prior to the UART. For serial ports which support polarity inversion, the polarity=on option can be added to the URI to do the polarity inversion so that an external logic inverter is not required. For example:

serial://localhost:0?baud='100000',parity='even',stop='2',flow='none',polarity='on'

Input Ports

This block has no input ports.

Output Ports

state

The current status of the connection. The possible states are tabulated below:

State

Name

Description

0

SERIAL_RECEIVER_STATE_NOT_CONNECTED

The stream is not connected.

1

SERIAL_RECEIVER_STATE_CLOSING

The stream is closing the connection to the receiver.

2

SERIAL_RECEIVER_STATE_CONNECTING

The stream is attempting to connect.

3

SERIAL_RECEIVER_STATE_CONNECTED

The stream is connected to the receiver.

4

SERIAL_RECEIVER_STATE_ACTIVE

The stream is connected to the receiver and packets are being actively received at the expected rate for the protocol.

err

If an error occurs receiving the data, then this output is a negative QUARC error code indicating the cause of the problem. Otherwise it is zero. It is a 32-bit signed integer.

int

A double scalar indicating the time interval between frames, in seconds. This value is useful for determining if a serial receiver is operating as expected.

ch

This output depends on the Map minimum to, Map maximum to and Output data type parameters. This output is always a 16 element vector where each element corresponds to a separate RC channel. However the data type and range changes depending on aforementioned parameters. Refer to the parameters for more details.

new

A 16-element vector indicating whether the values presented at the ch output port represent newly received data from the peer. If an element is false (zero) then no data for the corresponding channel has been received from the peer in this sampling instant.

This output is a vector because protocols like DSMX or DSM2 require more than one frame to be sent to provide 16 channels worth of data. Hence, not all channels will necessarily have new data each sampling instant.

fade

The number of missed frames for the DSM protocols, as a uint16.

sys

The system protocol identifier for the DSM protocols, as a uint8. Valid values are:

Value

Description

0x01

22ms 1024-bit DSM2 protocol

0x12

11ms 2048-bit DSM2 protocol

0xA2

22ms 2048-bit DSMX protocol

0xB2

11ms 2048-bit DSMX protocol

phase

A 16-bit boolean vector of the phases for each channel for the DSM protocols, as a boolean vector. Note that 22ms DSM2 does not support phases, but 11ms DSM2 and all speeds of DSMX do.

flg

The flags from the S.BUS frame, as a uint8.

Parameters and Dialog Box

Main Pane

The Main pane of the dialog appears as follows:

Serial Receiver Read Main tab

URI of serial receiver

The URI of the serial receiver. The URI typically refers to a serial port to which the receiver is connected. See the configuration options above for settings appropriate for each protocol.

Protocol

Indicates which protocol is being used. The block can autodetect between protocol variants, although error checking may be less stringent when autodetection between protocol variants is used.

Map minimum to (tunable online)

The values in a frame range typically range from 0 to 1023 or 0 to 2047 for each raw channel. This parameter is a scalar or vector used to transform the input before writing it to the ch output. A zero raw channel value in the frame will map to the value specified in this parameter. Other values will map linearly up to the value specified in the Map maximum to parameter.

If a vector is specified, then each element of the vector is used for the corresponding channel. If the vector is shorter than 16 elements, then the last element is used for the remaining channels.

Warning

The default output data type is uint16, so be sure to make the output data type consistent with the range specified for the output values.

Map maximum to (tunable online)

The values in a frame range typically range from 0 to 1023 or 0 to 2047 for each raw channel. This parameter is a scalar or vector used to transform the input before writing it to the ch output. The maximum raw value in the frame will map to the value specified in this parameter. Other values will map linearly down to the value specified in the Map minimum to parameter.

If a vector is specified, then each element of the vector is used for the corresponding channel. If the vector is shorter than 16 elements, then the last element is used for the remaining channels.

Warning

The default output data type is uint16, so be sure to make the output data type consistent with the range specified for the output values.

Synchronization byte(s) (tunable online)

Determines the synchronization value(s) used to detect the start of an S.BUS frame. The block will validate the synchronization byte to ensure the frame is properly received. This value is typically 0x0f in hexadecimal (or 15 decimal). If this argument is a vector then each element in the vector will be treated as a valid synchronization byte.

This parameter is only visible when an S.BUS protocol is selected.

External remote (tunable offline)

Indicates whether the receiver is an internal or external remote, since the DSM protocol varies slightly when an external remote is used.

This parameter is only visible when a DSM protocol is selected.

Advanced Pane

The Advanced pane of the dialog appears as follows:

Serial Receiver Read Advanced tab

Receive thread priority (tunable offline)

The priority of the receive thread that is used to receive frames from the serial receiver. Higher priority values indicate higher priority. A priority of zero is the lowest priority.

Signal Attributes Pane

The Signal Attributes pane of the dialog appears as follows:

Serial Receiver Read Signal Attributes tab

Channel output data type

Sets the data type of the ch output.

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

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

See Also

 

navigation bar