TLC for C++ S-Function

1 visualización (últimos 30 días)
Thomas Satterly Satterly
Thomas Satterly Satterly el 18 de Abr. de 2019
Comentada: Mark McBroom el 24 de Abr. de 2019
I have an S-function that needs to be nested inside of a for-each loop, which itself needs to be inside a reference model in accelerator mode. The S-function is written in C++ and makes heavy use of external libraries, classes, and the PWork and DWork vectors. It is also built to work with multiple instances and inside of iterator blocks (for, while). I'm new to TLC, and this seems a bit daunting due to the lack of clear documentation, but is writing a TLC file for such an S-function even possible?
For starters, I made a simple S-function in C and TLC that has one input and two outputs with very simple math in between. That was simple enough, but converting it to C++ immediately posed the issue of not being able to specify C++ as the target language because the simulink target was C. Is this avoidable?

Respuesta aceptada

Mark McBroom
Mark McBroom el 20 de Abr. de 2019
If the Simulink target is C, then the code that is emitted from your TLC will be placed into C files generated by Simuilnk and therefore will have to be C code. A common approach to interfacing with C++ code is to manually write a C++ file that contains a function to wrap your C++ code ( constructing objects, calling member functions, etc) and the use extern "C" to make your wrapper C++ function callable from the C code generated by Simulink.
#ifdef __cplusplus
extern "C" {
endif
  2 comentarios
Thomas Satterly Satterly
Thomas Satterly Satterly el 24 de Abr. de 2019
That's what I ended up doing, along with making use of a rtwmakecfg() function to link up the dependancies. It compiles in both normal and accelerated mode, but errors out at some point during the first call to the Output function in accelerated mode. Is there any support for debugging TLC files?
Mark McBroom
Mark McBroom el 24 de Abr. de 2019
Yes, there is a TLC debugger that you can use to set break points, look at variables, single step, etc. It is a command line debugger but works pretty good.
Start by setting a breakpoint in your TLC code. Easiest way is to just add
%breakpoint
to your TLC code. This link provides list of available debugger commands

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by