0

I am trying to call a Simulink function-call subsystem from within an s-function written in C.

This is in principle possible as documented in this tutorial: Implement Function-Call Subsystems with S-Functions.

What this example does is something like:

void mdlOutputs(SimStruct *S, int_T tid)
{
    // ...
    // The next statement calls the Simulink function-call subsystem and then returns execution
    if (!ssCallSystemWithTid(S,outputElement,tid)) { 
        return;
    }
    <next statement>
    // ...
}

This works fine but the example shows only how to call a function-call subsystem without inputs and outputs.

What I want is to call the function-call subsystem with inputs, specified in the C s-function and then use the output of the function-call subsystem in the next statement of the s-function. Something like this (this is pseudo code):

void mdlOutputs(SimStruct *S, int_T tid)
{
    // ...
    // Specify the input and output buffer for the function-call subsystem
    double u=1;
    double y;
    // Call the Simulink function-call subsystem with an input u and output y
    if (!ssCallSystemWithTid(S,outputElement,tid,u,&y)) { 
        return;
    }
    // Use the result of the function-call subsystem
    double temp = y + 1; // Just an example computation
    // ...
}

In this example the function-call subsystem is assumed to have one inport u and one outport y.

Is this possible? And if so, how?

SampleTime
  • 291
  • 3
  • 19

0 Answers0