MATLAB: Does ssGetInputPortSignal fail when called from an S-function’s mdlUpdate method in Simulink 7.4 (R2009b)

simulinkss_reusable_and_globalss_reusable_and_local

When I execute the following code in my mdlUpdate method, I get a NULL pointer which indicates that ssGetInputPortSignal failed:
const void *ip = ssGetInputPortSignal(S, 0);

Best Answer

In Simulink 7.4 (R2009b), ssGetInputPortSignal will fail in the mdlUpdate method when the input port is set to REUSABLE. For example, inserting the following line in mdlInitializeSizes will result in the behavior described:
ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
The input port should not be set to REUSABLE if it is required in the mdlUpdate method. As mdlOutputs is called before mdlUpdate, the InputPortSignal memory location would have already been reused by the time it reached mdlUpdate resulting in ssGetInputPortSignal returning a NULL pointer. The process view in the following documentation page illustrates the order in which various functions within an S-function are called:
web([docroot '/toolbox/simulink/sfg/f8-37326.html'])