Get the UDP sender adress and port in Simulink

조회 수: 4 (최근 30일)
Tim Remmert
Tim Remmert 2023년 2월 22일
댓글: Tim Remmert 2023년 3월 8일
I get a UDP message from an unkown IP-Adresse and unkown port to a known local port. I want to read that message, create an answer and reply to the same IP-Adresse and port I got the message from. In MATLAB, using the udpport, I get the message and the sender address / port but using udp recieve in Simulink just provides the message / data. Is there any other method I can use?
Thanks for your help

답변 (1개)

Animesh
Animesh 2023년 3월 7일
Hello,
Here's how you can modify your Simulink model to achieve this:
  • Drag and drop the "UDP Receive" block from the Simulink Library Browser into your model.
  • Double-click on the "UDP Receive" block to open its parameters dialog box.
  • Set the "Local IP port" parameter to the port number that your Simulink model will use to receive UDP packets.
  • Click the "Apply" button to apply the changes.
  • Connect the output of the "UDP Receive" block to a MATLAB Function block.
In the MATLAB Function block, write code to extract the received data and the remote sender's IP address and port number from the input signal. Here's an example code snippet that you can use:
function output = udp_receiver(input)
% Extract received data and remote sender's IP address and port number
data = input(1).Data;
ip_address = input(1).RemoteAddress;
port = input(1).RemotePort;
% Your code to process the received data and generate a reply message
% Create a UDP packet to send the reply message to the remote sender
packet = struct('Data', reply_data, 'RemoteAddress', ip_address, 'RemotePort', port);
% Output the packet to the next block
output = packet;
end
  • Connect the output of the MATLAB Function block to the input of a "UDP Send" block.
  댓글 수: 1
Tim Remmert
Tim Remmert 2023년 3월 8일
The "UDP Receive" block just returns the message it's self as and uint8 vector. Are there other "UDP Receive" blocks I dont have access to? I'm using "DSP System Toolbox / UDP Receive"

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

카테고리

Help CenterFile Exchange에서 Signal Import and Export에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by