SCI Receive
Configure host-side serial communications interface to receive data from serial port
- Library:
Embedded Coder / Embedded Targets / Host Communication
Description
The SCI Receive block specifies the configuration of a data package that is received from a target computer by this block.
Ports
Output
data
— Data package
scalar (default) | vector
Data package, specified as a scalar or vector, which is received from a target computer. The package can consist of headers, terminators, and data elements. The package size is limited to 16 bytes of ASCII characters, including headers and terminators. Calculate the size of a package by adding the byte sizes of headers, terminators, and the data.
This table lists the number of bytes for supported data types.
Data Type | Byte Count |
---|---|
single | 4 bytes |
int8 and uint8 | 1 byte |
int16 and uint16 | 2 bytes |
int32 anduint32 | 4 bytes |
For example, if your data package includes a 1-byte package header,
'S'
, and a 1-byte package terminator, 'E'
, 14
bytes remain for data. If your data is of type int8
, the data can
consist of up to 14 data elements. If your data is of type uint16
,
the data can consist of up to 7 data elements. If your data is of type
int32
, the data package can consist of up to 3 data elements with
2 bytes left over. Because you cannot mix data types in a package, the remaining 2
bytes are not used.
The number of data elements that can fit into a data package determine the data
length (see the Data length parameter). In the
preceding example, the 14 data elements of type int8
and the 7 data
elements of type uint16
are the data lengths for each data package,
respectively. When the data length exceeds 16 bytes, unexpected behavior, including
run-time errors, can result.
Data Types: single
| int8
| int16
| int32
| uint8
| uint16
| uint32
status
— Error status of data transmission
0 | 1 | 2 | 3 | 4
Optional error status value for data transmissions.
Possible status values are listed in this table.
Status value | Condition |
---|---|
0 | No errors. |
1 | Connection timed out while block was waiting to receive data. |
2 | Checksum error. Received data contains an error. |
3 | SCI parity error. Character was received with a mismatch. |
4 | SCI framing error. Expected stop bit was found. |
Port Dependencies
To enable this port, select parameter Output receiving status.
Parameters
Port name
— Name of COM port
COM1 (default) | COM2 | COM3 | COM4
Specify the name of the COM port that you are configuring for this SCI Receive block. You can configure up to four COM ports for a model, one COM port for each SCI Receive block in the model.
Additional package header
— Header of received data package
'S' (default) | 'ASCII value'
Specify the header of the received data package as an ASCII value in single quotes. The value can be text or a number in the range 0 to 255. The quotes are not received and are not included in the package byte count.
The header is not part of the data being received. Typically, the header marks the start of the data. The header that you specify must match the header specified for the corresponding target computer SCI Transmit block.
Additional package terminator
— Terminator of received data package
'E' (default) | 'ASCII value'
Specify the terminator of the received data package as an ASCII value in single quotes. The value can be text or a number in the range 0 to 255. The quotes are not received and are not included in the package byte count.
The terminator is not part of the data being received. Typically, the terminator marks the end of the data. The terminator that you specify must match the terminator specified for the corresponding target computer SCI Transmit block.
Data type
— Data type of data in received data package
uint8 (default) | single | int8 | int16 | uint16 | int32 | uint32
Specify the data type of the input port of the corresponding target computer SCI Transmit block. The data type and corresponding byte count are inherited from the input port.
Data length
— Number of data elements of specified data type that block receives
1 (default) | vector
Specify the number of data elements of the specified data type that the block receives from the target computer SCI Transmit block. A value other than 1 is treated as a vector. The data length is inherited from the length of the target computer SCI Transmit block input data.
Initial output
— Default value from SCI Receive block
0 (default) | scalar
Specify a value that the block outputs as the last value received when these conditions exist:
Parameter Action taken when connection times out is set to
Output the last received value
.No data has been received.
A connection times out.
Parameter Dependencies
To enable this parameter, set Action taken when connection times
out to Output the last received value
.
Action Taken when connection times out
— Output value to write when connection times out
Output the last received value
(default) | Output custom value
Specify the output value that the block writes when a connection times out. The block can write the last value received or a custom value.
Parameter Dependencies
If you specify Output custom value
, use parameter
Output value when connection times out to set the custom
value.
Output value when connection times out
— Output value to write when connection times out
0 (default) | scalar | vector
Specify the custom value to output when a connection times out.
Parameter Dependencies
To enable this parameter, set Action taken when connection times
out to Output custom value
.
Sample time
— Frequency of calls to block
-1 (default) | scalar
Specify the frequency at which the scheduler calls the SCI Receive block in
seconds. To achieve either of these conditions, set this parameter to
-1
:
The block inherits the sample time setting of the model.
The block executes asynchronously.
Output receiving status
— Error status of data transmission
off (default) | on
Select this parameter to create a status block output port that provides the status of data transmissions.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
This block does not support code generation. The block is supported for simulations on a host development computer only.
Version History
Introduced in R2011a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)