Continuous output of UDP Messages
3 views (last 30 days)
Show older comments
I am trying to setup a way to continually output data that I receive from a Multicast address but can only achieve printing out all received information in one go. I can confirm that this does work for receiving the packets but not for outputting them into a log file/ table as they are received.
The below script contains the pause because through trial and error it seems as though the port closes when the script ends, so I have a pause then start sending messages then when I no longer wish to receive messages I stop the script.
I currently have:
%Open a local port for listening
Port= udpport("datagram", "LocalPort", 50000, "EnablePortSharing", true);
%subscribe to a multicast location
configureMulticast(DiscoveryListeningPort, "224.1.1.1");
pause
data=read(Port,Port.NumDatagramsAvailable,"uint8");
NoMessages=size(data,2)
for x=1:NoMessages
DataRead=data(x).Data
%Manipulate DataRead below
end
0 Comments
Answers (1)
Vidip
on 20 Feb 2024
The data output can be empty if the amount of data read in a particular call to the read function in combination with the import configuration returns no values. So, to achieve continuous output of data received from a multicast address, you can set up a loop that repeatedly checks if datagrams are available, they are read and processed one by one. After processing the data, you can log the data to the console, and you can modify it to log to a file or a table by using functions like ‘table’ and add row entry inside the loop.
For further information, refer to the documentation link below:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!