This example shows how to use UDP blocks to send data from a target computer to a development computer. Signal data are sent by the transmit model running on the target computer,
dxpcUDP1TgtTx, to the receiver model running in Simulink® on the development computer,
Note: When considering UDP as a protocol for communicating data to/from the Simulink® Real-Time™ environment it is important to be aware of the following:
The Simulink model on the development computer is running as fast as it can and is therefore not synchronized to a real-time clock.
UDP is a connectionless protocol that does not check to confirm that packets were transmitted. Data packets can be lost or dropped.
On the target computer, UDP blocks run in a background task that executes each time step after the real-time task completes. If the block cannot run or complete the background task before the next time step, data may not be communicated.
UDP data packets are transmitted over the Ethernet link between the development and target computers and must therefore share bandwidth with the Ethernet link.
For more information on using UDP with Simulink Real-Time, see the documentation on UDP I/O support.
Open, Build, and Download the Target Computer Model
Click here to open the Tx model:
dxpcUDP1TgtTxdxpcUDP1TgtTx. This model drives a first order transfer function with a square wave signal and sends the transfer function input and output signals to the development computer using UDP.
% Open the model. mdlOpened = 0; systems = find_system('type', 'block_diagram'); if ~any(strcmp('dxpcUDP1TgtTx', systems)) mdlOpened = 1; open_system('dxpcUDP1TgtTx'); end
% Build the model and download to the target computer. set_param('dxpcUDP1TgtTx','RTWVerbose','off'); % Configure for a non-Verbose build. rtwbuild('dxpcUDP1TgtTx'); % Build and download application.
### Starting Simulink Real-Time build procedure for model: dxpcUDP1TgtTx Warning: This model contains blocks that do not handle sample time changes at runtime. To avoid incorrect results, only change the sample time in the original model, then rebuild the model. ### Successful completion of build procedure for model: dxpcUDP1TgtTx ### Looking for target: TargetPC1 ### Download model onto target: TargetPC1
% Close the model if we opened it. if (mdlOpened) bdclose('dxpcUDP1TgtTx'); end
Open the development computer Model
mdlOpened = 0; systems = find_system('type', 'block_diagram'); if ~any(strcmp('dxpcUDP1HostRx', systems)) mdlOpened = 1; open_system('dxpcUDP1HostRx'); end
Run Both Models
Start model on target computer followed by model on development computer.
start(tg); % Start the target computer Tx model. pause(1); % Wait for 1 sec. set_param(bdroot,'SimulationCommand','start');% Start the development computer Rx model. pause(5); % Wait for 5 sec. while ~strcmpi(get_param(bdroot,'SimulationStatus'),'stopped') pause(1); % Wait another 1 sec. end
Generate development computer Plot
Generate Target Computer Plot