Documentation

Target to Target Transmission using UDP

This example shows how to use UDP blocks to send data between two target computers. The model TargetToTargetRealtimeUDP1 runs on TargetPC1. The model TargetToTargetRealtimeUDP2 runs on TargetPC2. Both models send and receive signal data packets.

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:

  • UDP is a connectionless protocol that does not check to confirm that packets were transmitted or received. Data packets can be lost or dropped.

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

Click here to open this example: TargetToTargetUDP.

Open, Build, and Download the TargetPC1 Model

Click here to open model 1: TargetToTargetRealtimeUDP1.

% Open the model.
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp('TargetToTargetRealtimeUDP1', systems))
  mdlOpen = 1;
  open_system('TargetToTargetRealtimeUDP1');
end

% Build the model and download to the target computer.
set_param('TargetToTargetRealtimeUDP1','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('TargetToTargetRealtimeUDP1');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: TargetToTargetRealtimeUDP1
### Generated code for 'TargetToTargetRealtimeUDP1' is up to date because no structural, parameter or code replacement library changes were found.
### Successful completion of build procedure for model: TargetToTargetRealtimeUDP1
### Looking for target: TargetPC1
### Download model onto target: TargetPC1
% Close the model if we opened it.
if (mdlOpen)
  bdclose('TargetToTargetRealtimeUDP1');
end

Open, Build, and Download the TargetPC2 Model

Click here to open model 2: TargetToTargetRealtimeUDP2.

% Open the model.
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if ~any(strcmp('TargetToTargetRealtimeUDP2', systems))
  mdlOpen = 1;
  open_system('TargetToTargetRealtimeUDP2');
end
% Build the model and download to the target computer.
set_param('TargetToTargetRealtimeUDP2','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('TargetToTargetRealtimeUDP2');                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: TargetToTargetRealtimeUDP2
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: TargetToTargetRealtimeUDP2
### Looking for target: TargetPC2
### Download model onto target: TargetPC2
% Close the model if we opened it.
if (mdlOpen)
  bdclose('TargetToTargetRealtimeUDP2');
end

Run both Models

Using the Simulink Real-Time object variables tg1 and tg2, start the models.

start(tg1); % Start the TargetPC1 model.
start(tg2); % Start the TargetPC2 model.
pause(5);   % Run for 5 seconds.

Stop both Models

Using the Simulink Real-Time object variables tg1 and tg2, stop the models.

stop(tg1); % Stop the TargetPC1 model.
stop(tg2); % Stop the TargetPC2 model.

Generate TargetPC1 Plot

tg1.viewTargetScreen();

Generate TargetPC2 Plot

tg2.viewTargetScreen();

Was this topic helpful?