In an S-Function Block, how do I call functions that are available on my target device but not on my host computer?

조회 수: 2 (최근 30일)

In an S-Function Block, how do I call functions that are available on my target device but not on my host computer?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 3월 9일
In order to get this to work with "coder.ceval()", you have to use "coder.target()" to specify that the functionality that you are leveraging is from the target device. This will cause the specific code to only run on the target device (when deployed) and not when run on the host device (simulated, etc.). Please see the following example:
x = 0;
if coder.target('Rtw')
% generating code for Arduino
coder.cinclude('Arduino.h')
x = coder.ceval('my_arduino_fcn', args...);
else
% simulating in Simulnk
% if there is a way to replicate this behavior in MATLAB, put it here
end
Here, "coder.target('Rtw')" will prevent the next few lines from being executed when running on your host computer, where "Arduino.h" is not defined. For more information on "coder.target()", please refer to the following documentation page:
In this case, you will only want to generate code and not build and run the resulting executable. If you try to run the executable on your host computer, it will fail, since "Arduino.h" and its dependencies are not on the path on your host machine.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by