Sending UDP data from my Simulink model in External Mode while bypassing the target hardware
5 views (last 30 days)
Show older comments
Hi. My Simulink model needs to run on my NXP MIMXRT1024 target board. I am running in External Mode, so that I can log some sensor measurements I receive using ADC block of MBDT toolbox.
Everything runs well, until I try to add a UDP communication block to transmit data from my ADC to a Unity game that listens on port 8000 of my localhost (i.e. same PC machine running the simulation).
None of the UDP methods I tried worked: I tried all Simulink library "UDP send" blocks, and writing custom MyUDP.m code inside MATLAB functions, MATLAB Systems, and Level-1 S Function using udpport and dsp.UDPSender objects, as well as trying NXP's own TCP/UDP block (which I believe will only work if we physically connect the board with Ethernet cable to my PC).
All of these methods mentioned, caused error when Simulink's Embedded Coder tries to code generate.
My question I guess is, in External Mode simulation, how can I force the UDP part of my model to not code generate itself (i.e. runs from the board), and instead make it run using the MATLAB engine from my PC without compiling (as if I was executing a "UDP send" commad from MATLAB shell, which works btw)?
PS: In trying to create a MATLAB System block, the block generated (see figure below) proposes the choices: "Code generation" and "Interpreted execution", but no matter what I choose, it throws the same error, as I believe it always tries to code generate. So I wonder if there is any actual effect of "Interpreted execution" choice.
Code inside the MATLAB System block to give you an idea:
classdef MyUDPSender < matlab.System
properties (Nontunable)
ipAddress = '127.0.0.1';
port = 8000;
end
properties (Access = private)
udpObject
end
methods (Access = protected)
function setupImpl(obj)
obj.udpObject = dsp.UDPSender('RemoteIPAddress', obj.ipAddress, 'RemoteIPPort', obj.port);
end
function stepImpl(obj, data)
data = uint8(data);
step(obj.udpObject, data);
end
function releaseImpl(obj)
release(obj.udpObject);
end
function resetImpl(obj)
obj.releaseImpl();
obj.setupImpl();
end
function numInputs = getNumInputsImpl(obj)
numInputs = 1;
end
function numOutputs = getNumOutputsImpl(obj)
numOutputs = 0;
end
end
end
Am I missing something? any other suggestions? thanks a lot for helping me.
0 Comments
Answers (1)
Adeline
on 14 Sep 2023
Hi,
I understand you are trying to run a Simulink model with a UDP communication block in external mode.
The external mode simulation allows communication between the Simulink block diagram and the standalone program that is built from the generated code. Hence, when a model runs in external mode every block which is part of that model must support code generation.
For more information about the external mode, please refer to the following documentation link:
In the current model, the code generation for the custom “MATLAB System” block fails due to its limited code generation capabilities. To avoid this error, reprogram the block code by considering its code generation limitations or choose an UDP send block with required code generation properties. The “Extended Capabilities” section of the documentation page describes the code generation properties of the block.
For example: The “UDP send” block from the Embedded Coder library supports code generation without limitations. While the “UDP send” block from the DSP System toolbox supports code generation with a few limitations. Further, the “UDP send” blocks from the Instrumentation Control Toolbox and NXP support library do not support code generation.
For detailed information on the full list UDP send blocks available in Simulink, please refer to the following documentation link:
Hope this information was helpful.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!