xPC Target | ![]() ![]() |
Creating RS-232 Message Structures (Synchronous)
RS-232 drivers use MATLAB structures to send and receive 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.
After you add an RS-232 Setup and RS-232 Send/Receive block to your Simulink model, you can create the message structures to communicate with the RS-232 devices. You need to create and load these structures into the MATLAB workspace before you build your target application. The easiest way to create these structures is using an M-file and load that M-file into the MATLAB workspace.
'identifier, channel, value;\n'
. Identifier is any string. Channel is an integer value between 1 and 2, defining which D/A channel to update. Value is a floating-point value indicating the new voltage for the D/A output.
Additionally, when the external device receives a legal string, it accepts the string as an input message, and returns the message 'noerror;\n'
. This message is provided as a confirmation. As an example, you could type the following
PreLoadFcn
for your Simulink model to load the message structures when you open your model. For example, if you saved the message structures in the M-file RS232Sync_messages
, type
Your next task is to build and run the target application. However, the example above only illustrates how to set up the dialog entries when using the Send & Receive block. Without an external RS-232 device to receive the messages, and return a reply "no error\n", this model cannot run successfully on your target PC. It will block and wait for a reply each time the application sends a message.
![]() | Adding RS-232 Driver Blocks (Synchronous) | RS-232 Asynchronous Mode | ![]() |