Compiling/inlining an M-file S-Function (which calls a MEX file)

Hello,
working with Real-Time Workshop (7.6.1) for the first time I am a bit unsure about the possibilities and whether I'm on the right track at all.
I wrote a relatively simple Level-2 MATLAB S-Function which converts its input to a string and utilizes Peter Rydesäter's TCP/UDP/IP toolbox to set up a UDP socket and send data. The TCP toolbox is made up by the source file, pnet.c, and the compiled pnet.mexw32, which I guess I call in my S-function.
The documentation regarding inlining S-functions contains a simple example for writing a TLC file, but as far as I understand that, it is merely replicating the output generation of the S-function in TLC code. Is that what TLC files do? Is there a chance to do the same for my task?
I'm still quite lost, so I'd appreciate any hints.
Thank you
Silvan

 采纳的回答

Yes, TLC files do indeed define how the outputs are to be calculated in the generated code (this may or may not match simulation - although that is preferred). For example, an S-function that is supposed to represent an LCD Display driver may do nothing in simulation, but generates code that calls into the LCD Display API for the target platform.
In your case, you will need to find the C/C++ equivalent of the TCP toolbox functions that you are currently calling, and call into those C/C++ functions in your TLC code. You can then compile those C files into the generated code. You may contact the author of the toolbox in question to see if they can provide a native binary for your target platform. Since they are already using MEX-functions underneath, it is possible that they are calling into C libraries already.

1 个评论

If I recall, that contribution is based upon the fairly standard netcat distribution, which can be downloaded from a number of places.

请先登录,再进行评论。

更多回答(1 个)

Thank you for your answers! As my M-file S-function is basically useless for Real-Time Workshop -- and not too complicated anyway -- I have started to implement it as a C MEX S-function.

1 个评论

Silvan: Even if you implement your S-function as a C-MEX S-function, I think you might still need to deal with the problem of calling MEX-functions underneath. MEX-functions need MATLAB-based libraries to execute and would never run in a standalone environment.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by