Reading data via tcp
13 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2020 年 4 月 22 日
編集済み: Walter Roberson
2020 年 4 月 22 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!