Reading data via tcp
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Katzlberger
il 22 Apr 2020
Modificato: Walter Roberson
il 22 Apr 2020
Hello,
I want to read data from the tcpobj which is created using the Instrument Control Toolbox in Matlab.
When I am calling
get (tcpobj, 'ValuesReceived')
I receive as an answer 349. But if I use fread, fscanf, fgets or fgetl I get an empty set of data.
Can someone please help?
Thanks and greetings
Christian
0 Commenti
Risposta accettata
Walter Roberson
il 22 Apr 2020
Modificato: Walter Roberson
il 22 Apr 2020
This is correct. ValuesReceived is the number of values that have been received since you opened the socket, so it is telling you that you have already used fread() to read 349 values. It does not tell you anything about how many bytes are already waiting in the buffer. If you have read all of the queued values, then it is not unreasonable at all that fread() and so on might find nothing there.
If you want to know how much data is available to be read, example the BytesAvailable property -- and remember to divide by the size of one value to find out how big the buffer is in terms of values.
Note that if the number of bytes that were sent through the pipe exceeds the input buffer size, then after you read some of the values, the BytesAvailable might not change, because some of the queued values would have been rolled in to fill the buffer. You will not see BytesAvailable decrease below the input buffer size until there is less queued data than the size of your input buffer.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su GPU Computing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!