MATLAB Answers

Programmatically change UDP Packet Output IP: Desktop Real-Time

10 views (last 30 days)
Spencer Chen
Spencer Chen on 30 Apr 2020
Commented: Manuel K on 4 Aug 2020
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

Show 1 older comment
Spencer Chen
Spencer Chen on 30 Jul 2020
Thanks, Manuel. I finally got time to revisit this problem. But I could not follow your solution in my situation. I cannot find the "toAddress" or "IP" fields. I believe the difference is that I'm using the Packet Output block from "Desktop" Real-time rather the the Real-time toolbox. Here's what get(gcbh) yields me:
>> get(gcbh)
Path: 'AllegroDRT_20200430_v406_R2018b/SystemOutput/UDPOutput/UDPSend'
Name: 'UDP_STREAM_OUT'
Tag: ''
Description: ''
Type: 'block'
Parent: 'AllegroDRT_20200430_v406_R2018b/SystemOutput/UDPOutput/UDPSend'
Handle: 8168
HiliteAncestors: 'none'
RequirementInfo: ''
FontName: 'auto'
FontSize: -1
FontWeight: 'auto'
FontAngle: 'auto'
Selected: 'on'
MaskType: 'Simulink Desktop Real-Time Packet Output'
MaskDescription: 'sldrt:sldrtlib:DescPacketOutput'
MaskHelp: 'helpview(fullfile(docroot, 'toolbox', 'sldrt', 'helptargets.map'), 'rtw_packet_out')'
MaskPromptString: 'SampleTime|MaxMissedTicks|ShowMissedTicks|YieldWhenWaiting|DrvName|DrvAddress|DrvOptions|PacketSize|DataTypes|ShowReady|ShowError|PacketID|ByteOrder|InitialValue|FinalValue'
MaskStyleString: 'edit,edit,checkbox,checkbox,edit,edit,edit,edit,edit,checkbox,checkbox,edit,edit,edit,edit'
MaskVariables: 'SampleTime=@1;MaxMissedTicks=@2;ShowMissedTicks=@3;YieldWhenWaiting=@4;DrvName=&5;DrvAddress=@6;DrvOptions=@7;PacketSize=@8;DataTypes=@9;ShowReady=@10;ShowError=@11;PacketID=@12;ByteOrder=@13;InitialValue=@14;FinalValue=@15;'
MaskTunableValueString: 'off,on,off,on,off,off,off,off,off,off,off,on,off,on,on'
MaskCallbackString: '||||||||||||||'
MaskEnableString: 'on,on,on,on,on,on,on,on,on,on,on,on,on,on,on'
MaskVisibilityString: 'on,on,on,on,on,on,on,on,on,on,on,on,on,on,on'
MaskToolTipString: 'on,on,on,on,on,on,on,on,on,on,on,on,on,on,on'
MaskVarAliasString: ''
MaskInitialization: ''
MaskSelfModifiable: 'off'
MaskDisplay: 'disp('Packet\nOutput')'
MaskBlockDVGIcon: ''
MaskIconFrame: 'on'
MaskIconOpaque: 'opaque'
MaskIconRotate: 'none'
MaskPortRotate: 'default'
MaskIconUnits: 'autoscale'
MaskValueString: '-1|1000|off|on|Standard_Devices/UDP_Protocol|50012|[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]|STREAM_PACKET_SIZE|STREAM_PACKET_CONFIG|off|off|1|1|[]|[]'
MaskRunInitForIconRedraw: 'off'
MaskTabNameString: ''
Mask: 'on'
MaskCallbacks: {15×1 cell}
MaskEnables: {15×1 cell}
MaskNames: {15×1 cell}
MaskPropertyNameString: 'SampleTime|MaxMissedTicks|ShowMissedTicks|YieldWhenWaiting|DrvName|DrvAddress|DrvOptions|PacketSize|DataTypes|ShowReady|ShowError|PacketID|ByteOrder|InitialValue|FinalValue'
MaskPrompts: {15×1 cell}
MaskStyles: {15×1 cell}
MaskTunableValues: {15×1 cell}
MaskValues: {15×1 cell}
MaskToolTipsDisplay: {15×1 cell}
MaskVisibilities: {15×1 cell}
MaskVarAliases: {15×1 cell}
MaskWSVariables: [1×15 struct]
MaskTabNames: {15×1 cell}
MaskObject: []
Ports: [12 0 0 0 0 0 0 0 0]
Position: [435 77 565 638]
Orientation: 'right'
PortRotationType: 'default'
ForegroundColor: 'darkGreen'
BackgroundColor: 'white'
DropShadow: 'off'
IOType: 'none'
NamePlacement: 'normal'
ShowName: 'on'
HideAutomaticName: 'on'
Priority: ''
Commented: 'off'
CodeProfilingOverride: 'inherit'
AttributesFormatString: 'UDP Protocol [50012]'
InstantiateOnLoad: 'off'
PolySpaceEndComment: ''
PolySpaceStartComment: ''
AncestorBlock: ''
ReferenceBlock: 'sldrtlib/Packet Output'
SourceLibraryInfo: ''
LibraryVersion: '1.241'
UserDataPersistent: 'off'
UserData: []
CompiledIsActive: 'on'
RTWdata: []
HDLData: []
Diagnostics: ''
DialogParameters: [1×1 struct]
IntrinsicDialogParameters: [1×1 struct]
AlgorithmParameters: [1×1 struct]
SecondaryAlgorithmParameters: [1×1 struct]
CompiledSampleTime: [-1 0]
InputSignalNames: {1×12 cell}
OutputSignalNames: {1×0 cell}
ModelParamTableInfo: []
StatePerturbationForJacobian: '1.0e-05'
SCDEnableBlockLinearizationSpecification: 'off'
SCDBlockLinearizationSpecification: []
CopyFcn: ''
DeleteFcn: ''
UndoDeleteFcn: ''
LoadFcn: 'rtblkgui('Load')'
ModelCloseFcn: 'close(findall(0, 'Type', 'figure', 'Tag', 'SLDRT_RTBLKGUI', 'UserData', gcbh))'
PreSaveFcn: ''
PostSaveFcn: ''
InitFcn: ''
StartFcn: 'rtblkgui('Start',1)'
PauseFcn: ''
ContinueFcn: ''
StopFcn: 'rtblkgui('Start',0)'
NameChangeFcn: ''
ClipboardFcn: ''
DestroyFcn: ''
PreCopyFcn: ''
OpenFcn: 'rtblkgui('Open','PO')'
CloseFcn: ''
PreDeleteFcn: ''
ParentCloseFcn: 'eval(get_param(gcbh, 'ModelCloseFcn'))'
MoveFcn: ''
BlockType: 'S-Function'
BlockDescription: 'User-definable block. Blocks can be written in C, MATLAB (Level-1), and Fortran and must conform to S-function standards. The variables t, x, u, and flag are automatically passed to the S-function by Simulink. You can specify additional parameters in the 'S-function parameters' field. If the S-function block requires additional source files for building generated code, specify the filenames in the 'S-function modules' field. Enter the filenames only; do not use extensions or full pathnames, e.g., enter 'src src1', not 'src.c src1.c'.'
LinkStatus: 'resolved'
StaticLinkStatus: 'resolved'
PortConnectivity: [12×1 struct]
PortHandles: [1×1 struct]
LineHandles: [1×1 struct]
CompiledPortWidths: [0×0 struct]
CompiledPortDimensions: [0×0 struct]
CompiledPortDataTypes: [0×0 struct]
CompiledPortUnits: [0×0 struct]
CompiledPortComplexSignals: [0×0 struct]
CompiledPortFrameData: [0×0 struct]
DataTypeOverride_Compiled: 'UseLocalSettings'
MinMaxOverflowLogging_Compiled: 'UseLocalSettings'
Capabilities: [1×1 Capabilities]
IOSignalStrings: []
RuntimeObject: [0×1 double]
ExtModeUploadOption: 'none'
ExtModeLoggingSupported: 'off'
ExtModeLoggingTrig: 'off'
TargetArchitectureMapping: {}
FunctionName: 'sldrtpo'
Parameters: 'SampleTime,MaxMissedTicks,ShowMissedTicks,YieldWhenWaiting,DrvName,DrvAddress,DrvOptions,PacketSize,DataTypes,ShowReady,ShowError,PacketID,ByteOrder,InitialValue,FinalValue'
SFunctionModules: ''''
SampleTime: '-1'
MaxMissedTicks: '1000'
ShowMissedTicks: 'off'
YieldWhenWaiting: 'on'
DrvName: 'Standard_Devices/UDP_Protocol'
DrvAddress: '50012'
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]'
PacketSize: 'STREAM_PACKET_SIZE'
DataTypes: 'STREAM_PACKET_CONFIG'
ShowReady: 'off'
ShowError: 'off'
PacketID: '1'
ByteOrder: '1'
InitialValue: '[]'
FinalValue: '[]'
Spencer Chen
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!

Translated by