Control Real-Time Application by Using C++

9 visualizzazioni (ultimi 30 giorni)
Byron Hatfield
Byron Hatfield il 26 Ott 2022
Risposto: Jon Lobo il 19 Dic 2022
I have a requirement to control my Speedgoat real-time application using C++ and deploy to customers that do not have MATLAB. Prior to MATLAB 2020a there used to be a C SLRT API that allowed you to do the following things with your Speedgoat real-time application from C/C++ (load model, start model set model parameters, stop model and some other things). Post MATLAB 2020a the Speedgoat real-time operating system was updated to QNX and support for the C SLRT API was dropped. Furthermore there was no external interface that allowed external applications to interface to the Speedgoat real-time application.
Since MATLAB 2021b Simulink real-time applications can be controlled from C# using the ASAM XIL API as per the documentation: https://au.mathworks.com/help/slrealtime/ug/control-real-time-application-by-using-c-sharp.html
What is the recommended way to interface my C++ application with my Speedgoat real-time application. Please note that years of effort have gone into developing this C++ application, and hence it is not an option to re-code it to C# or other programming languages. Is it possible to call C# from C++?

Risposte (1)

Jon Lobo
Jon Lobo il 19 Dic 2022
Hi Byron,
There are two ways to do this. The first is available from R2020b onwards, and the second is available from R2021b onwards.
MATLAB has documented interfaces that allow MATLAB code to be called from external languages such as C/C++, Python and others. You can use this to call the Simulink Real-Time API along with other MATLAB code. There is a shipping example that demonstrates how to Run Real-Time Applications by using Python Script. The caveat with this approach is that it does require MATLAB and Simulink Real-Time on the same computer where your external code is running.
Option 2: MATLAB Compiler SDK (R2021b onwards)
MATLAB Compiler SDK builds on the capabilities of MATLAB Compiler by enabling users to build C/C++ shared libraries, Python packages and other components that can be integrated into external code. These components are dependent on the MATLAB Compiler Runtime, which is freely avialable for your end-user to download. In order to use this approach, you'll need to write the functions your external code would need (start, stop, setparam etc.) that would in turn call the Simulink Real-Time API. You could then create a shared library that your external code could leverage.
-Jon

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by