| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → xPC Target |
| Contents | Index |
| Learn more about xPC Target |
xPC Target Library for RS232
The ASCII Encode block generates a UINT8 output vector that contains a NULL-terminated string based on a printf like format string and data on the input ports.
The ASCII Decode block parses an input vector according to a format specifier similar to scanf, and makes converted values available to a Simulink program. The input vector to the ASCII Decode block can be either 8-bit or 16-bit and signed or unsigned. If the data format is 16-bit, the ASCII Decode block ignores the upper eight bits of each entry.
Enter a printf like format string. Each format specifier such as %d is replaced by the converted value that is present on the corresponding input variable. Acceptable format specifiers are %c, %d, %i, %o, %u, %x, %e, %f, and %g. These follow the normal description for printf.
Enter the number of input ports to this block. The value on each port is inserted into the output string with the format specified in Format string.
Enter the maximum allowed length of the converted string, in bytes. The block allocates enough memory to support this length for the output port. When selecting this length, take into account the NULL termination on the string.
If the converted string exceeds this length, the block returns an error and does not write that string to the output port.
Enter one of the following: {'double'}, {'int8'}, {'uint8'}, {'int16}, {'uint16'}, {'int32'}, and {'uint32'}. The default is {'double'}. This parameter specifies the Simulink data types allowed for the input ports. 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
{ } — All three inputs are doubles.
{'uint8'} — All three inputs are uint8.
{'uint16', 'double', 'uint8'} — There are three inputs: the first is a uint16, the second is a double, and the third is a uint8.
Enter a scanf like format string. Each format specifier such as %d needs to match a corresponding part of the input vector. Literal strings in the format need to match the first character plus the number of characters. Acceptable format specifiers are %c, %d, %i, %o, %u, %x, %e, %f, and %g. These follow the normal description for scanf.
Enter the number of output ports for this block. For example,
If Format string has the value of %xmore text%x and the input vector for the block has cdmabcdefgh90, you must specify the value of the Number of variables parameter as 2.
The first variable is assigned the value 0xcd. Next, the string mabcdefgh is considered a match to more text because
The first character for both strings is m.
Both strings have the same number of characters.
The second variable is then assigned the value 0x90. Note that the string mabcdefgh does not have to match exactly the value of Format string. This behavior is different from that for scanf, which requires an exact match.
Enter one of the following: {'double'}, {'int8'}, {'uint8'}, {'int16}, {'uint16'}, {'int32'}, and {'uint32'}. The default is {'double'}. This parameter specifies the Simulink data types allowed for the output ports. A cell vector with the same number of elements as specified in Number of variables can specify a different data type for each output port. A single element is replicated. For example,
nvars=3
{ } — All three outputs are doubles.
{'uint8'} — All three outputs are uint8.
{'uint16', 'double', 'uint8'} — There are three outputs: the first is a uint16, the second is a double, and the third is a uint8.
![]() | xPC Target RS-232 and 422/485 Drivers (Composite) | ASCII Decode V2 | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |