Sending UDP data from my Simulink model to some IP without passing by my MIMXRT1024 board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sending UDP data from my Simulink model to some IP without passing by my MIMXRT1024 board

992 Views
ylahdili
Contributor II

Hi. My Simulink model needs to run on my NXP MIMXRT1024 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" command 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.

ylahdili_0-1687572835599.png

Code inside the MATLAB System block:

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? thanks a lot for helping me.

0 Kudos
Reply
0 Replies