Main Content

Monitoring Ink Status on a Shared Printer Using Simulink Functions

This example shows how clients, in this case three computers, can send jobs to a server, a printer, and receive status from that server. This example highlights how Simulink Functions can be called from different subsystems and interact both in Simulink® and Stateflow®.

Example Requirements

Note that when you simulate the example, Stateflow might generate code in the current working folder.


In this example, the computers each generate randomly sized print jobs at regular intervals. The printer interacts with the computers through two Simulink Functions on the Simulink canvas and one Exported Graphical Function in Stateflow.

1. The clients use Function Caller blocks to invoke the addPrintJob interface of the printer.

2. The client-server interaction, modeled by this call, may have a negative return value if the printer has run out of ink.

The example shows how to interface Simulink and Stateflow using functions.

1. The implementation of addPrintJob uses a Function Caller block to invoke queuePrintJob, which is a Stateflow Exported Graphical Function.

2. The queuePrintJob function interacts with other content in the chart using a local chart variable 'work'.

3. The implementation of the chart makes a call to printerInk, which is a Simulink Function.

4. The printerInk function job uses the graphical input and outputs to interact with the addPrintJob function.

The example also shows how to visualize and debug Simulink Functions.

1. You can enable the visualization lines connecting functions and their respective callers. In the Simulink Editor, on the Debug tab, under Information Overlays, click Function Connectors.

2. The Message Viewer block shows where calls to functions are generated, and which functions are called at different times. This helps to understand the flow of calls with respect to time, and also analyze the arguments sent during these calls to functions.