How to read the contents of the UDP packet?

9 views (last 30 days)
Aldas
Aldas on 24 Apr 2013
Commented: PTP on 27 Feb 2016
I have my PC connected to the FPGA board. The board is constantly sending me UDP packets with some random data. I am using this code to get packets and read them:
u = udp ('10.51.32.251', 8998, 'LocalPort', 20004);
fopen(u)
%check if the connection is open and data is received
get (u, 'Status')
get (u, 'ValuesReceived')
A = fread(u);
fclose(u)
delete (u);
clear u
All I get is error message: "Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period." Neither fread nor fscanf works. Wireshark shows that packets are incoming.
  1 Comment
PTP
PTP on 27 Feb 2016
Hi,
I am facing the same problem. Are you able to solve it now.
Regards

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Apr 2013
Either set datagram mode or else set the buffer size.
A read operation with fread completes when one of these conditions is satisfied:
The time specified by the Timeout property passes.
The input buffer is filled.
The specified number of values is read. For UDP objects, DatagramTerminateMode must be off.
A datagram is received (for UDP objects, only when DatagramTerminateMode is on).
As you did not specify the number of objects in your fread(), the number is implicitly "inf".

Community Treasure Hunt

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

Start Hunting!