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

3 visualizzazioni (ultimi 30 giorni)

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 9 Mar 2020
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.

Più risposte (0)

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by