Read UDP packets asynchronously from Simulink in MATLAB

조회 수: 1 (최근 30일)
Nick
Nick 2017년 4월 5일
답변: Michael 2019년 6월 7일
I have a very simple setup where I am generating a sine wave in simulink and sending it through a UDP block.
On the other hand I have MATLAB where I want to asynchronously fire a callback as soon as a packet is received.
On simulink I have my remote address set to 127.0.0.1 and my port to 25000.
In MATLAB I am using the following code.
u = udp('127.0.0.1', 25000);
u.ReadAsyncMode = 'continuous';
fopen(u);
u.BytesAvailableFcn = 'myfunction';
where myfunction simply prints a string.
However the callback is not being executed at all (it does work with echoudp). What could I be doing wrong?

답변 (1개)

Michael
Michael 2019년 6월 7일
I belive you need to use the function handle for myfunction
u = udp('127.0.0.1', 25000);
u.ReadAsyncMode = 'continuous';
fopen(u);
u.BytesAvailableFcn = @myfunction
function [] = myfunction(event, obj)
disp('Callback worked!')
end

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by