How to read the contents of the UDP packet?
9 views (last 30 days)
Show older comments
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
Answers (1)
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".
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!