xPC Target    

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 uses 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.

For more information on this example, see Creating RS-232 Message Structures (Asynchronous).


  Simulink Blocks for RS-232 Host and Target PC Communication