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

조회 수: 2 (최근 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에서 Simulink Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by