| 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
This section describes the FIFO Read and Write blocks. Of particular note are the FIFO Read blocks, of which there are three. Use the following guidelines when using these blocks:
Simple data streams — Use the FIFO Read block to read simple data streams. An example of a simple data stream is one that has numbers, separated by spaces, and that is terminated by a newline. The FIFO Read block is a simple block that can easily extract these numbers.
More complicated data streams — Use the FIFO Read HDRS and FIFO Binary blocks for more complicated data streams. A more complicated data stream can be one that contains headers, messages of varying lengths, or messages with no specific terminators. A message header consists of one or more character identifiers at the beginning of a message that specify what data follows. ASCII messages normally have a variable length and a terminator. Typically, all messages of a particular device use the same predefined terminator. Binary messages are normally of fixed length with no specific terminator.
The FIFO Read HDRS or FIFO Binary blocks are also useful to work with devices that can send different messages at different times.
All three FIFO read block types need their input to be of type serialfifoptr, which is output from F type Send Receive subsystems.
The following are examples of when you can use the FIFO read block.
For an instrument that sends a string like the form
<number> <number> ... <CR><LF>
use the simple FIFO Read block to read the message. Configure the FIFO Read block Delimiter parameter for a line feed (value of 10).

You should then connect the output to an ASCII Decode block with a format that separates the numbers and feeds them to the output ports.
For an instrument that can send one of a number of different messages, and each message begins with a different fixed string, use the FIFO Read HDRS block. For example, a digital multimeter connected through an RS-232 port, might send a voltage reading and an amp reading with messages of the following format:
volts <number> <CR><LF> amps <number> <CR><LF>
Configure the FIFO Read HDRs block Header parameter for the volts and amps headers, in a cell array. Also configure the Terminating string parameter for carriage return (value of 13) and line feed (value of 10).

You should then connect the output to multiple ASCII Decode blocks, one for each header and message. See the xpcserialasciitest and xpcserialasciisplit models in xpcdemos for examples of how to use this block in a model.
For an instrument that sends a binary message, you typically know the length of each full message, including the header. Configure the FIFO Read Binary block Header parameter for the headers of the message, in a cell array, and the Message Lengths parameter for the message lengths. See the xpcserialbinarytest and xpcserialbinarysplit models in xpcdemos for further examples of how to use this block in a model.
The FIFO Read block is the read side of a FIFO read/write pair. There are two modes for this block:
If Read to delimiter is checked, this block only reads elements if the chosen delimiter is found in the FIFO. If the delimiter has not yet been written to the write side of this FIFO, the block returns a zero length vector, as determined by the data type. (If you have a zero length vector, you might want to have your application perform a particular operation, or ignore the case.) If the delimiter is found, the block returns elements up to and including the delimiter in the output vector. Selecting this check box causes the block to perform ASCII reads.
If Read to delimiter is not checked, this block returns a number of elements between Minimum read size and the smaller of the number of elements currently in the FIFO and Maximum read size. Selecting this check box cause the block to perform binary reads.
The FIFO Write block is the write side of a FIFO read/write pair.
Specify the maximum number of characters that you will ever expect to be returned by this block. The resulting vector size will be one more than this maximum number of characters. This block needs the extra element to contain the number of characters that are being returned. The block contains the characters as either
A null terminator for the 8–bit data types
The character count for the 16– and 32–bit data types
Be sure to enter a large enough number. If this number is too small, the block might not be able to return anything. If this number is larger than necessary, there is no effect. For example, if you enter a value 10, but on execution there are 11 characters up to the terminator in the FIFO, the block will not return any characters.
If you select the parameter Max and Min read size ports, the block interprets the value input on this port to be the maximum number of characters to return. The actual maximum number of characters to return is the smaller of the value on the max input port or the maximum read size in the block parameters. This is mainly useful in binary mode when the Read to delimiter check box is not selected.
Enter the smallest desired read size in bytes. The FIFO must contain at least this number of elements before any elements will be returned. If you select the Max and Min read size ports check box, this value is superseded by the external signals.
Select this check box to enable the return of element sets that terminate with the Delimiter value. Use this parameter when working with character-based elements.
Enter the decimal value for an 8-bit input terminator. This parameter specifies the value on which a FIFO read operation should terminate. It works with the Read to delimiter parameter. By default, this block looks for a carriage return. It only returns characters when one is found. For reference, the decimal value of a carriage return is 13, a line feed is 10.
From the list, select count+32 bit int, count+32 bit uint, count+16 bit int, count+16 bit uint, 8 bit int null terminated, or 8 bit uint null terminated. This parameter specifies the output vector type. The 8-bit data types produce a null terminated string in the output vector. For 16- and 32-bit data types, the first element contains the number of elements to expect in the rest of the output vector.
Select this check box to enable the maximum and minimum input ports. When this check box is selected,
The value from the maximum input port is the maximum number of characters to be removed from the FIFO. Note that if this number exceeds the value of Maximum read size, the block disregards the value from the maximum input port and takes the value of Maximum read size as the maximum number of characters to be removed from the FIFO.
The value from the minimum input is the minimum number of characters the FIFO must contain before any elements can be returned. This value supersedes the value set with the Minimum read size parameter.
Select this check box to pass the maximum read input through to the passthrough output.
Base sample time or a multiple of the base sample time.
Enter the number of elements that can be held in the FIFO at any one time. If a write operation to the FIFO causes the number of elements to exceed Size, an error occurs.
From the list, select count+32 bit int, count+32 bit uint, count+16 bit int, count+16 bit uint, 8 bit int null terminated, or 8 bit uint null terminated. This parameter specifies the input vector type. The 8-bit data types need a null terminated string in the output vector. For 16- and 32-bit data types, the first element contains the number of elements to expect in the rest of the input vector.
Select this check box to create a Boolean output that is true if data is present in the FIFO. The transmit side of the send/receive subsystem uses this output. This output is given to the Enable TX block, which enables the transmitter buffer empty interrupt.
Base sample time or a multiple of the base sample time.
Enter a user-defined identifier for overflow messages.
The following are some examples of how you can set up the FIFO Read block:
In the transmit side of the interrupt service routine, the maximum input port receives a value of 0 if the interrupt reason is not an empty hardware FIFO, and the hardware FIFO size if the hardware FIFO is empty. The minimum input port receives the constant value of 1.
On the receive side, the typical case with ASCII data has the minimum and maximum input ports disabled. The Read to delimiter parameter check box is selected and the Delimiter parameter has the value of carriage return or line feed. The value of the Maximum read size parameter is large (along the order of the FIFO size) and the value of Minimum read size parameter is 1. In this form, the driver acts like a nonblocking read line.
An alternate receive-side configuration for fixed-length binary blocks of data has the value of the Maximum read size and Minimum read size parameters set to the fixed length of the block. The Read to delimiter parameter is not selected.
![]() | ASCII Decode V2 | FIFO Read HDRS (Composite) | ![]() |

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 |