Programmatically change UDP Packet Output IP: Desktop Real-Time

2 views (last 30 days)
Hi,
I have a Simulink desktop real-time model that has a Packet Output set up to do UDP. I want to be able to set it up so it is sending to the correct IP in the InitFcn, rather than hard-coding the IP from the Simulink UI. Does anyone know if it is possible to do that?
I tried a couple approaches:
  1. Try accessing with get_param(), but eally cannot find the right model path.
  2. Try setting CLIENT_IP = '127.0.0.1' in the base workspace and fill in the IP field with CLIENT_IP instead of the actual IP address. At compile, I get error that this cannot be resolved.
Matlab R2018b, Windows 10.
Blessings,
Spencer
  4 Comments
Spencer Chen
Spencer Chen on 30 Jul 2020
Edited: Spencer Chen on 30 Jul 2020
I'm adopting a Variant solution with a small set of hardcoded IPs as a workaround.
Manuel K
Manuel K on 4 Aug 2020
I'm sorry, I totally missed what block you are using.
Netherless I played a bit and saw the following line:
DrvOptions: '[0 50021 49 50 55 46 48 46 48 46 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]'
The elements after your port address "50021" are the decimal-representation for the ASCII-characters of your IP-adress.
49 50 55 46 48 46 48 46 49
translates to
127.0.0.1
With the following command I could change the IP-adress accordingly.
set_param(gcb,'DrvOptions','[0 50021 49 50 55 46 48 46 48 46 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]')
So you just have to convert your IP-adress to the right representation and insert it in this array.
I hope this addresses your issue better.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!