Skip to content

Running C++ code in Simulink S-Functions

Hello,

We have some Simulink models developed and are planning to use an AXC F 2152 controller to use it as HIL (hardware in the loop), communicating the PLC via Modbus TCP.

I know that the Simulink plug-in creates C++ code and that code is then built into IEC, appearing as a library in the PLCnext project. My doubt is that inside the Simulink model there are some S-Functions with C++ code inside them and I would like to know if it would work correctly or if there are any limitations about using these kind of functions.

Related to this, and just to fulfill my curiosity, python programs can be called from Simulink too, would they also work?

Thanks in advance,

Asier

Comments

  • Hey asier,

    sorry for letting you wait, but I've had to catch one of our simulink experts.
    Here comes his feedback:
    SFunctions written in C++ will work. More flexible are TLC based S-Functions, where you can also extend the PLCnext component methods. But you need to take into account, that the SFunction code is executed cyclically in the real-time context and should be deterministic.

    About Python programs we don't have experience, but I could imagine that these calls should also work. If not out-of-the-box, then at least by using operating system functions, which are accessible from C++. But the execution of python programs from the model may affect the real-time context, if they are called cyclically from a program. I think a possible approach could be to create the caller functionality from a TLC based SFunction and generate the code into one of the component initialization methods. Extending these methods is a new feature in the 2.0 release.

    Another possible alternative to call python scripts might be the PLCnext Base library. With this lib it is possible to call bash commands and inside the command you can call your script.

    BR,
    Frank
  • Hello Frank,

    Thank you for your answer.
    I am glad the C++ writen F-functions will work. I will also take a look to the TLC based S-Funtions and to the PLCnext.Base library, both seem really useful.

    Best regards,

    Asier
Sign In or Register to comment.