We'll develop the simplest possible S-functions to enable our models to communicate with the application we described earlier: a file-source block and a file-sink block.
These S-functions will have only one port and be able to read/write a scalar real signal from/to a file. The file path will be passed as a parameter; and the files will have only one line containing the new signal value.
The sink block, called filesink_msfun
, will receive the input and convert it to a string that will be written to the file. The file path is passed as parameter, no DWork
vector is needed because we don't have to output a default value.
The source block, called filesource_msfun
, will read one line from the file, attempt to convert it into a real number, and output it. When the file is not readable, the last line is empty, or an error occurs, the last valid value will be used. This means that we'll have to use one DWork
vector, and one more parameter for the initial...