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

matlab s-functionreal time workshopsimulink coder

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

Best Answer

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.
Related Question