Error Running Simulink in External Mode on Raspberry Pi
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi everyone, I've been trying to deploy some standalone code from Simulink on a Raspberry Pi 4B but I am having some issues. My application requires the generated code to read from a file within the directory, and also write to a file within the directory on the Raspberry Pi. There doesn't appear to be any blocks that can do this, so I wrote some code in a Matlab Function block with some guidance from one of the examples that came with the toolbox. My model builds and is sent to the device no issues, but there are two errors that occur at Run Time and I haven't found any useful solutions to the issues in the documentation or online anywherer yet. I tried running it in externel mode with "Monitor and Tune", as well as the "Build, Deploy, and Start".
Right now I am trying to make a very basic model run, It has a Matlab Function block for reading a file, a Matlab Function block for writing to a file, and one display block for when I was trying to run it in Externel mode. Here are the codes:
Read Function:
function output = ReadFromFile()
%#codegen
% Include the C header stdio.h
coder.cinclude('stdio.h');
% Define the file name
filename = 'SimulinkInputTest.txt';
% Open the file for reading
fid = coder.opaque('FILE *');
fid = coder.ceval('fopen', filename, ['r', 0]);
% Read the number from the file
output = coder.nullcopy(0.0);
coder.ceval('fscanf', fid, coder.const('%f'), coder.wref(output));
% Close the file
coder.ceval('fclose', fid);
end
Write Function:
function appendToTextFile(value)
%#codegen
% Include the C header stdio.h
coder.cinclude('stdio.h');
% Define the file name (you can specify any file name)
filename = 'SimulinkOutputTest.txt';
% Open the file in append mode
fd = coder.opaque('FILE *');
fd = coder.ceval('fopen', filename, ['a', 0]);
% Write the value to the file
coder.ceval('fprintf', fd, '%g\n', value);
% Close the file
coder.ceval('fclose', fd);
end
And this is a picture of the Model:
And here is the error:
Error occurred while executing External Mode MEX-file 'ext_comm': ExtTargetPktPending() call failed while checking for target pkt
Component:Simulink | Category:Block diagram error
Error occurred while executing External Mode MEX-file 'ext_comm': ExtSetTargetPkt() call failed on CLOSE. Ensure target is still running
Component:Simulink | Category:Block diagram error.
I am connected to the Pi with an ethernet cable.
I am not sure how to fix this error and get this very basic example working. Thanks for the help in advance.
댓글 수: 0
채택된 답변
Dinesh
2023년 9월 21일
Hi Kyle,
I understand that you are currently trying to deploy standalone code onto a Raspberry Pi, but you are encountering an error message: 'ext_comm': ExtTargetPktPending() call failed.
This error typically occurs when Simulink fails to receive acknowledgment from the target, indicating a loss of communication between Simulink and the board. One possible reason for this could be high communication bandwidth usage or running out of memory, resulting in temporary communication loss during runtime in external mode simulation.
Please refer to the following MATLAB Answers thread for suggestions on how to deal this issue
Hope this helps.
Best Regards,
Dinesh Reddy Gatla.
추가 답변 (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!