fprintf not working in Raspberry Pi when 'fid' is passed through input port in Simulink
4 ビュー (過去 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?
0 件のコメント
採用された回答
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 Center および File Exchange で Raspberry Pi Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!