Share Functions Across Simulink and Stateflow

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 addPrintJob.

Communicate and Share Resources with Functions

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. The 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.

Call a Simulink Function from Stateflow

The function 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.

Export Stateflow Functions to Simulink

In the chart Queuing and 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, queuePrintJob.

See Also

Related Topics