Table of Contents
SBus Read
Receives an S.BUS frame over a stream. This block is intended for use in the main diagram.
Library
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/S.BUS')Description
The SBus Read block receives an S.BUS frame, which is 25 bytes of packed 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. If a Stream Call or Stream Answer block is used to create the stream, then the stream will be non-blocking. If a Stream Connect or Stream Accept block is used to create the stream then the blocking mode of the stream is determined by the Stream Connect or Stream Listen block.
This block receives an S.BUS frame over a client stream and extracts its constituent components, including the 16 channels and flags.
When the stream is non-blocking, this block will not wait. If fewer bytes are available than the size of an S.BUS frame then the new output will be zero (false). If all the data requested is available then the new output will be non-zero (true). The err output will be 0, indicating that no errors occurred.
If the connection has been closed gracefully by the peer then it sets cls to a non-zero (true) value and returns zero (false) at its new output once there are fewer bytes left to read than the size of the output signal. Otherwise the cls output is zero and the new output returns true (non-zero). Once there are fewer bytes left in the stream buffer than the size of an S.BUS frame then it sets cls to true to indicate the connection has been closed. A graceful closure of the connection by the peer is not considered an error, so the err output is zero in this case.
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. If the stream is not valid because it is not yet connected, the err output will be zero since this condition is expected and the validity of the stream may be checked using the con output of the Stream Call or Stream Answer blocks.
This block does not support two threads calling SBus Read at the same time. However, SBus Read may be called by another thread at the same time as SBus Write.
Helpful Hints
Other uses of this block
Although it is intended for use in the main diagram with the other Intermediate stream blocks, the SBus Read block may be used with the Advanced stream blocks, even in an asynchronous thread.
Configuration Requirements
Serial configuration
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 for the Stream Call block 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.
Signal inversion
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
stm
A reference to the stream created by the Stream Call or Stream Answer block. If these blocks have not established a connection the err output of the SBus Read block will be zero.
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.
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.
flg
The flags from the S.BUS frame, as a uint8
.
new
Indicates whether the value(s) presented at the ch and flg output ports represent newly received data from the peer. If this output is zero (false) then no data has been received from the peer in this sampling instant.
cls
Indicates whether the connection has been closed by the peer. This output is non-zero (true) when the remote host gracefully closes the connection. Otherwise it is zero (false).
err
An int32 value indicating whether the data was read from the stream buffer successfully. This value will be 1 if data was read successfully. It will be zero if data could not be read immediately. If an error occurs then this value is a negative error code. If the connection is closed and not enough data is left in the stream buffer for an S.BUS frame then 0 is also returned. If the connection is closed but there is enough data in the stream buffer then this output returns 1. Zero is only returned once the stream buffer is exhausted. 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 the err output is less than zero.
Parameters and Dialog Box
Main Pane
The Main pane of the dialog appears as follows:
Protocol
Indicates whether the S.BUS 1 or S.BUS 2 protocol is being used. The default is designed to handle either protocol automatically, but has less strict error checking as a result.
Synchronization byte (tunable online)
Determines the synchronization value used to detect the start of an S.BUS frame. The block will scan the input stream for 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.
Map minimum to (tunable online)
The values in an S.BUS frame range from 0 to 2047 for each channel. This parameter is a scalar or vector used to transform the input before writing it to the ch output. A zero in the S.BUS 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.
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 an S.BUS frame range from 0 to 2047 for each channel. This parameter is a scalar or vector used to transform the input before writing it to the ch output. A value of 2047 in the S.BUS 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.
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. |
Signal Attributes Pane
The Signal Attributes pane of the dialog appears as follows:
Output data type
Sets the data type of the ch output.
Targets
Target Name |
Compatible* |
Model Referencing |
Comments |
---|---|---|---|
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
Yes |
Yes |
||
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 Call or Stream Answer block which created the stream is not active during normal simulation, then the SBus Read block does nothing. Otherwise it reads the data from the stream. |
See Also
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.