Error Running Simulink in External Mode on Raspberry Pi
12 次查看(过去 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!