Specifications
2 RS232 I/O Support
2-4
Simulink Blocks for RS-232
To support the use of RS-232, the xPC Target I/O library includes a set of
RS-232 driver blocks. These driver blocks can be added to your Simulink model
to provide inputs and outputs using one or more of the RS-232 ports:
•
RS-232 Setup — One setup block is needed for each RS-232 port you use in
your model. The setup block does not have any inputs or outputs, but sends
the initialization and termination messages.
•
RS-232 Send/Receive (Synchronous Mode) — Send/Receive blocks have
inputs and outputs from your Simulink model, and sequence both the send
and receive messages.
•
RS-232 Send (Asynchronous Mode) — Send blocks have inputs from your
Simulink model, and sequences the send messages.
•
RS-232 Receive (Asynchronous Mode) — Receive blocks have output from
your Simulink model, and sequences the receive messages.
MATLAB Message Structures for RS-232
Communication is through a series of messages passed back and forth between
the target PC and the RS-232 device. To accomplish this, the messages sent to
the RS-232 device must be in a format that the device understands. Likewise,
the target PC must know how to interpret the data returned from the RS-232
device.
xPC Target used MATLAB structures to create messages and map the input
and output ports on the RS-232 driver blocks to the data written and read from
the RS-232 devices. The RS-232 Setup block executes the messages in the
initialization structure after downloading the target application. The RS-232
Send/Receive, RS-232 Send, and, RS-232 Receive blocks repeat the execution
of the messages in the send/receive, send, and receive structures during each
sample interval. When the target application stops running, the RS-232 Setup
block executes the messages in the termination structure.
Below is an example of the send and receive message structure for
asynchronous communication. In this example, an external RS-232 device
requires a string with two floating-point numbers. The numbers are entered
from the Simulink model to the first and second input ports of the RS-232 Send
driver block. The RS-232 device sends back two floating-point numbers that are
passed to the outputs of the
RS-232 Receive driver block.