Fread-Function mysterious behaviour

1 view (last 30 days)
Norbert
Norbert on 1 Jun 2011
Hello my dear friends,
data = fread (s, [1 15], 'int32');
I think, in this example the fread function should read 15*4 Bytes (= 60 Bytes) from serial input stream. This is a blockin function, so that calculation of following blocks continues after receiving these count of bytes.
On tests with outputing a message counter, we detected that the fread function is blocking until twice the count of bytes is received. After receiving 120Bytes (instead of 60) the block works as we would expect.
Any ideas or explanations why the function works that way?
Thanks and kind regards, Nobert
  1 Comment
Jan
Jan on 1 Jun 2011
Please explain what "tests with outputing a message counter" means. After the command you've shown, 60 bytes are read, but "data" contains 15 DOUBLEs, which occupy 120 bytes in the memory.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 1 Jun 2011
data = fread (s, [1 15], '*int32');
Otherwise it is reading double (8 bytes) and converting the result to int32.
  2 Comments
Jan
Jan on 1 Jun 2011
Do you mean the other way around: fread(s, 1, 'int32') reads 4 bytes as INT32 and converts it to DOUBLE value.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!