Matlab UDP randomly missing data
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a test I would like to run for many hours. It is very simple, I send a command to my network device and expect an acknowledge message back. I utilize fwrite and fread to send/receive these messages.
Sometimes when I set this test to run overnight I find the next morning that the test failed to receive an acknowledge. The response I expect is only 4 bytes long: 0x01; 0x7F; 0x06; 0x10.
I can look at my UDP socket after this failure and I noticed in the Read/Write state there were "BytesAvailable". Looking here I found 3 bytes: 0x7F; 0x06; 0x10. It appears that the socket failed to read the first byte.
Like I said before, this happens very intermittently and I haven't found a way to reliably reproduce.
Does anyone know what could be causing this, is this a known issue, or maybe a way to work around this issue? Thanks for any help!
4 commentaires
Réponses (1)
Walter Roberson
le 10 Juin 2013
datagram terminate mode means that the data becomes available with each datagram instead of waiting for a terminator such as linefeed. But becomes available means it goes into the buffer. If you only ask to fread() a single byte then the remaining bytes stay in the buffer.
You can ask to read (object).BytesAvailable bytes from (object) and then use the bytes from where you store them instead of reading as-you-need-them.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!