This example shows how to call functions across Simulink® and Stateflow®. The
slexPrinterExample model consists of three computer clients that share a printer. Each computer creates print jobs by calling the Simulink function
In this example, the Stateflow chart communicates with the model by:
Defining and exporting a graphical function that is called by Simulink.
Calling a Simulink function that is defined in Simulink.
Each computer client invokes the printer server with a call to the Simulink function,
addPrintJob function calls the Stateflow graphical function
queuePrintJob to add the print job to the work load. The chart processes the work and calls the Simulink function
printerInk to model usage of printer ink.
printerInk is defined in a Simulink Function block at the top level of the model. The function interface
printerInk(work) defines one input argument. The Simulink Function, printerInk, also interacts with the model with signal lines through the inport
ink and outport
ink'. The state
Busy matches the function signature for
printerInk(work) by passing one input argument.
In the chart
Processing Incoming Jobs, the properties Export chart level functions and Treat exported functions as globally visible are selected. These properties allow the Simulink function
addPrintJob to call the chart graphical function,