Programmatically change UDP Packet Output IP: Desktop Real-Time

조회 수: 4 (최근 30일)
Spencer Chen
Spencer Chen 2020년 4월 30일
댓글: Manuel K 2020년 8월 4일
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
Spencer Chen
Spencer Chen 2020년 7월 30일
편집: Spencer Chen 2020년 7월 30일
I'm adopting a Variant solution with a small set of hardcoded IPs as a workaround.
Manuel K
Manuel K 2020년 8월 4일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Model Preparation for Real-Time Simulation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by