Reading data via tcp

14 visualizaciones (últimos 30 días)
Katzlberger
Katzlberger el 22 de Abr. de 2020
Editada: Walter Roberson el 22 de Abr. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Abr. de 2020
Editada: Walter Roberson el 22 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by