0
votes

I have a very big C/C++ software project in Visual Studio and Eclipse. There are some third party software in the form of SIMULINK models. Is it currently possible to:

1) Write C/C++ wrapper functions for SIMULINK models? 2) Invoke the functions from external environment such as VS or Eclipse C/C++ projects to perform integration and further tasks?

I know that you can use MEX (MATLAB Exec.) functions which are C/C++ or FORTRAN wrapped for MATLAB usage. But this is not ideal for me.

USE CASE

My use case is based on modelling and simulation, but my subsystems are quite diverse in terms of data format. 50% is in C/C++, 35% is in SIMULINK models, and the rest are in binary executables, object code, symbol data, etc. I am doing some complex system modelling; Sorry, but cannot tell you further due to protective reasons.

From the answers I am getting, it seems people are keen to just use what Mathworks offers. My intention was to get more like a yes no answer, but so far I got good explanations too.

UPDATE

I will have to evaluate SIMULINK's embedded coder and see how much extra effort is required on polishing the generated code. I read that there is production-level code generation facility in Embedded Coder; should be interesting.

1
It appears that you don't want to use any of the mainstream methods to access simulink generated code. What is it you wish to do?macduff
@macduff Just because there is a code generator doesn't mean that I have to use it. i was trying to find out if it is possible to use C/C++ wrapper to invoke SIMULINK models. And what I am trying to do is create a complex system where the subsystem designs are either in SIMULINK models, C/C++ source code, executable application, object files, binary data, etc. If you want specific details, sorry I cannot disclose due to confidentiality.ha9u63ar
You could invoke Matlab and do a co-simulation using TCP/IP or some other IPC to communicate with the model during co-sim. However, If the c-code generated is not efficient enough, this approach may be lacking as well.macduff
@macduff I am glad that you understood! I am pretty certain that MATLAB's code generator is not good enough. SIMULINK's one - I am not sure, in the process of trying at the moment. I am keen to try what you are saying about TCP comms. So, should I "fake" remote execution of my .m scripts then?ha9u63ar
While this is possible, it will require a reasonable amount of effort. If at all possible, use the code generated by Simulink.macduff

1 Answers

2
votes

There are two choices depending on exactly what your requirements are:

  • convert the Simulink models to C using Simulink Coder. This effectively gets you out of the Simulink environment, so integrating the model functionality into you existing environment is identical to incorporating any other C code. Of course you need access to Simulink Coder to do this.

  • Calling the MATLAB Engine. Note you cannot call just Simulink. You call MATLAB and issue various MATLAB commands to load, execute, and interrogate the Simulink model.