The error occurs because Simulink does not allow changing certain block parameters while the model is running in External mode. In this case, the "Constant block value" inside the Start and Stop Motor subsystem is a non-tunable parameter, so when the model is executing on the target, Simulink cannot update it and throws that error.
To fix this:
One quick ways is to stop the simulation before modifying that Constant value, then run again.
And a more proper way is to:
- Make the parameter tunable by replacing the constant with a variable (e.g., a Simulink.Parameter)
StartMotor = Simulink.Parameter(1);
StartMotor.CoderInfo.StorageClass = 'ExportedGlobal';
and now if we set the value of constant block as "StartMotor", it will become tunable.
- Using an input/dashboard control instead of a Constant block.
For start/stop signals specifically, it’s better to use a runtime input (button, switch, or Inport) rather than a Constant block, since constants are compiled as fixed values during code generation.
For more information, refer to the following documentations: