ASCII Encode
Libraries:
Simulink Real-Time /
RS232
Description
The ASCII Encode block generates a uint8
output
vector that contains a NULL-terminated character vector based on a
printf
like format string. The data comes from the input
ports.
For more information, see RS-232 Serial Communication and RS-232 Legacy Drivers.
Examples
ASCII Encoding/Decoding Resync Loopback Test
Use the ability of the FIFO Read HDRS block to resynchronize after being repeatedly disabled and apply this ability to resolve errors such as when a message is only partially complete at the time the read is attempted.
Binary Encoding/Decoding Resync Loopback Test
Use the ability of the FIFO Read BINARY block to handle messages that are interrupted and only partially complete.
Simple ASCII Encoding/Decoding Loopback Test (with Baseboard Blocks)
Convert a single floating point number to ASCII and transmit the value over a serial link.
ASCII Encoding/Decoding Loopback Test (with Baseboard Blocks)
Send ASCII data over a serial link.
ASCII Encoding/Decoding Resync Loopback Test (with Baseboard Blocks)
Use the ability of the FIFO Read HDRS block to resynchronize after being repeatedly disabled and apply this ability to resolve errors such as when a message is only partially complete at the time the read is attempted.
Binary Encoding/Decoding Loopback Test (with Baseboard Blocks)
Send Binary data over a serial link.
Binary Encoding/Decoding Resync Loopback Test (with Baseboard Blocks)
Use the ability of the FIFO Read BINARY block to handle messages that are interrupted and only partially complete.
Ports
Input
1 — Numbered ports that receive values to encode
numeric
Values that the block encodes as a null-terminated character vector.
Data Types: double
| int8
| uint8
| int16
| uint16
| int32
| uint32
Output
D — Null-terminated character vector
character vector
Generated uint8
output vector that contains a
NULL-terminated character vector.
Parameters
Format string — Format specifiers for converting values to ASCII
%d\r
(default) | %c
| %i
| %o
| %u
| %x
| %e
| %f
| %g
Enter a printf
like format string. For each format
specifier such as %d
, the block replaces the format
specifier by the converted value in the corresponding input variable. The
format specifiers follow the normal description for
printf
.
Programmatic Use
Block Parameter:
format |
Number of variables — Number of block inputs
1
(default) | integer
The value on each port is inserted into the output character vector with the format specified in Format string.
Programmatic Use
Block Parameter:
nvars |
Max output string length — Maximum length of converted character vector, in bytes
128
(default) | integer
The block allocates enough memory to support this length for the output port. When specifying this length, include the NULL termination on the character vector.
If the converted character vector exceeds this length, the block returns an error and does not write that character vector to the output port.
Programmatic Use
Block Parameter:
maxlength |
Variable types — Simulink® data types allowed for input ports
{'double'}
(default) | {'int8'}
| {'uint8'}
| {'int16}
| {'uint16'}
| {'int32'}
| {'uint32'}
A cell vector with the same number of elements as specified in Number of variables can specify a different data type for each input port. A single element is replicated. For example:
nvars=3
{ }
— The three inputs are doubles.
{'uint8'}
— The three inputs are
uint8
.
{'uint16', 'double', 'uint8'}
— The first input
is a uint16
, the second input is a
double
, and the third input is a
uint8
.
Programmatic Use
Block Parameter:
vartypes |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2020b
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)