MATLAB: How to integrate I/O commands such as CIN and COUT in the C++ S-function code in Real-Time Workshop (Embedded Coder)

realsimulink codertimetlc

I have 2 S-functions called "amplifier" and "ampifier_out" and I use them in my model which is called: test_amplifier1.mdl.
I want to be able to use CIN and COUT commands in the code of my inlined C++ S-functions.

Best Answer

In order to use I/O commands such as: CIN and COUT in C++ S-function, you need to include iostream library in your TLC-code.
Then you should be able to use the CIN, COUT commands in the TLC-file.
Please see the attached ampifier_out.tlc and ampifier.tlc files.
The TLC-files include "BlockTypeSetup" TLC function which will be executed only once for each type of an S-function block.
In that function we define a TLC global variable called "::ioinclude".
Using this global variable guarantees that the "#include iostream" statement will be executed only once in the code.