How can I receive UDP broadcast data in MATLAB using Instrument Control Toolbox?

조회 수: 59 (최근 30일)
My device sends UDP broadcast data to all computers on my local area network.
How can I receive this data in MATLAB?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2017년 1월 18일
You can receive UDP broadcast data using the UDP functionality in Instrument Control Toolbox.
 
If you are only receiving UDP packets, and not sending out any UDP packets, the only relevant properties of the UDP object are LocalHost and LocalPort; the RemoteHost and RemotePort are not relevant in this case.
 
LocalHost is the host name or IP address of the Ethernet adapter you are receiving the UDP packets on, and the LocalPort is the port number you are receiving the UDP packets on.
Note: If you don't specify LocalHost (or if you set it to an empty string), you will receive UDP packets on all available Ethernet interfaces at the specified LocalPort.
 
% Listen on all available Ethernet interfaces at local port 8000.
% Specify a LocalHost (host name or IP address) if known
u = udp('', 'LocalHost', '', 'LocalPort', 8000);
fopen(u);
% Receive a single UDP packet
packetData = fread(u);
% Clean up
fclose(u);
delete(u);
clear u
 

추가 답변 (1개)

Vinod
Vinod 2017년 1월 12일
편집: MathWorks Support Team 2021년 8월 23일
Here's a file exchange example that shows you how you can broadcast and receive messages over UDP.

카테고리

Help CenterFile Exchange에서 Instrument Connection and Communication에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by