Can I tune the UDP Send & UDP Receive block IP address and port parameters with Simulink Real-Time (SLRT) and Speedgoat?

3 views (last 30 days)
I am using UDP Receive and UDP Send blocks in my Simulink Real-Time model to exchange data between my Speedgoat and an external device.
Is it possible to change the "To IP address" and "To port" parameters for the UDP Send block, or the "From IP address" parameter for the UDP Receive block, during the real-time simulation or between simulations without requiring a rebuild?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Apr 2025
Edited: MathWorks Support Team on 3 Apr 2025

For R2021a or later

Starting from R2021a, it is possible to tune the IP & port parameters for Simulink Real-Time UDP blocks during runtime.
Using our Target To Host UDP example, you can change the parameters in the UDP block masks if you started the model with the  "Run on Target" button (external mode). The MATLAB code syntax for "setparam" is the following:
tg.setparam('slrt_ex_target_to_host_UDP/UDP Send','toAddress',uint8([255 255 255 255]));
tg.setparam('slrt_ex_target_to_host_UDP/UDP Send','toPort',uint16(8004));
tg.setparam('slrt_ex_target_to_host_UDP/UDP Receive','fmAddress',uint8([10 10 10 100]));
Note that there is also a UDP Multicast Receive block available, as well as multicast and broadcast support for the UDP Send block.

For R2020b or prior

In R2020b and earlier, this feature is not available. IP Addresses are not tunable.
You can consider one of the following workarounds:
1. If supported in your release of Simulink Real-Time, use UDP multicasting or broadcasting as a workaround. Consult the documentation.
2. Place multiple UDP Send/Receive blocks. Place each in an enabled subsystem, triggered subsystem, or switch case action subsystem. If you know all possible ports that you may need to use, you can add a dedicated block for each port. Please see the attached R2013b example "multiUDPsend.slx" where 6 instances of UDP Send blocks are used in order to enable 6 different Local IP ports.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!