MATLAB: Is there a simple example that demonstrates serial port I/O with xPC Target

-setupcom1com2inputmainboardoutputrs232Simulink Real-Time

I am trying to set up basic serial port communication with my target machine running an xPC Target model. This model is using the Baseboard Serial block along with the ASCII Encode/Decode block, similar to the model shown in the MATLAB 7.1 (R14SP3) documentation here:
web([docroot,'/toolbox/xpc/ch_io_rs2326.html'])
However, this example does not show any of the block parameters for the ASCII Encode/Decode block or the Baseboard Serial block. I would like a more in depth explanation of this example or a similar example that details the serial port I/O setup.

Best Answer

This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
Documentation on basic serial port I/O is limited in the xPC Target I/O reference documentation. Currently, the only documentation examples that show serial port I/O use the FIFO Read and FIFO Write blocks. These blocks are for simulation only, and do not send data to actual hardware. You need to replace these blocks to use the example with actual hardware. There are notes in the xPC Target demos that describe how to replace these blocks with appropriate blocks for use with hardware.
A significant amount of confusion for performing basic serial port I/O in xPC Target comes from the number of blocks that are available for this action. xPC Target supplies two types of drivers to support RS-232 I/O communication, conventional and composite. For backwards compatibility, xPC Target continues to support the conventional blocks. These are blocks that you can use for input or output to a serial port on the computer motherboard. As of xPC Target 2.5 (R14), use the composite Baseboard Serial block for input or output to a serial port on the computer motherboard. An example of this is described in the documentation under xPC Target > I/O Reference > Serial Communications Support > xPC Target RS-232 and 422/485 Drivers (Composite) > Adding RS-232 Blocks.
Another common source of confusion when using the composite blocks stems from the existence of the ASCII Encode/Decode blocks. In other blocks, such as the older RS232 Mainboard Send/Receive block, you can enter the data to be sent directly into the block that sends it. When using the composite Baseboard Serial block, you need to encode/decode the data into ASCII before sending and after receiving. This extra step enables another layer of debugging; you can view exactly what is sent to the block or received from the block within the simulation.
See the attached model for a demonstration of this. Note, this model was created in MATLAB 7.1 (R14SP3).
In this model, the number 3006 is sent to the COM1 port. First, the ASCII Encoder block converts the number to ASCII. The Display block in the model displays the ASCII values output from that block. Note that the values are
51 48 48 44 13
These are the ASCII values that correspond to "3 0 0 6 \r", where \r represents a carriage return. You need to insert the carriage return because it is specified in the "Format String" parameter of the ASCII Encoder block.