Documentation Center

  • Trial Software
  • Product Updates

Target to Host Transmission using UDP

This example shows how to use UDP blocks to send data from a target computer to a host computer. Signal data are sent by the transmit model running on the target computer, dxpcUDP1TgtTx, to the receiver model running in Simulink® on the host computer, dxpcUDP1HostRx.

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 host 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 host-target Ethernet link and must therefore share bandwidth with host-target communications.

  • For more information on using UDP with Simulink Real-Time, see the documentation on UDP I/O support.

Click here to open this example: dxpcUDP1dxpcUDP1.

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 host computer using UDP.

% Open the model.
mdlOpened = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp('dxpcUDP1TgtTx', systems))
  mdlOpened = 1;

% 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)

Open the Host Computer Model

Click here to open the Rx model: dxpcUDP1HostRxdxpcUDP1HostRx. This model receives data sent by dxpcUDP1TgtTx and unpacks the data for display in a scope.

mdlOpened = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp('dxpcUDP1HostRx', systems))
  mdlOpened = 1;

Run Both Models

Start model on target computer followed by model on host computer.

start(tg); % Start the target computer Tx model.
pause(1);  % Wait for 1 sec.
set_param(bdroot,'SimulationCommand','start');% Start the host computer Rx model.
pause(5);  % Wait for 5 sec.
while ~strcmpi(get_param(bdroot,'SimulationStatus'),'stopped')
    pause(1); % Wait another 1 sec.

Generate Host Computer Plot


Generate Target Computer Plot


Was this topic helpful?