fprintf not working in Raspberry Pi when 'fid' is passed through input port in Simulink

3 次查看(过去 30 天)
I'm developing an application to run in Raspberry Pi 3 that logs data from I2C sensors and store the values in a file.
I've structured the application using 3 blocks:
- One block (BLOCK1) that runs in the first frame and opens the file (using fopen mode 'a') and writes a header to it; this block outputs the 'fid' to be used by the next 2 blocks
- One block (BLOCK2) that runs at every frame, that uses 'fid' returned by BLOCK1 and writes sensor data to the file
- One block (BLOCK3) that runs at the last frame, that closes the file using 'fid' returned by BLOCK1
When I run this model in Normal mode, in Windows, everything is OK. But, when I run it in External Mode, the Raspberry Pi correclty executes only the first block, i.e., it opens the file and write the header. It seems to be something to do with the 'fid' argument passing.
I tried something that worked: to have the following 2 blocks:
- The same BLOCK1 above, but it closes the file and do not return the 'fid'
- The same BLOCK2 above, but it opens the file, writes the data, and then closes the file.
I'm willing to do the 1st manner in order not to pay the overhead of opening and closing the file at every frame.
Did anyone have a similar problem?

采纳的回答

Reeno Joseph
Reeno Joseph 2017-12-15
This is happening because for normal simulations, file I/O is extrinsic, while for the hardware targets it is not. Fid's cannot be shared between blocks when file IO is not extrinsic.
This is documented (although a little confusing) here:
https://in.mathworks.com/help/matlab/ref/fopen.html#bvlc5pc-1
If you disable extrinsic calls, then you cannot return file identifiers created with fopen to MATLAB functions or extrinsic functions. Use these file identifiers only internally.
In effect, passing fid's between blocks is sort of returning them to MATLAB.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Raspberry Pi Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by