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 in both Simulink® and Stateflow®. (Note that when you simulate the example, Stateflow might generate code in the current working folder.)

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.

The clients use Function Caller blocks to invoke the addPrintJob interface of the printer. The client-server interaction modeled by this call may have a negative return value if the printer has run out of ink.

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

The implementation of addPrintJob uses a Function Caller block to invoke queuePrintJob, a Stateflow exported graphical function. The queuePrintJob function interacts with other content in the chart using a local chart variable work.

The implementation of the chart makes a call to printerInk, a Simulink function, which uses the graphical input and outputs to interact with the addPrintJob function.

You can also visualize and debug Simulink functions. To visualize lines connecting functions and their respective callers, in the Simulink Editor, on the Debug tab, under Information Overlays, click Connectors. Select Function Connectors option from the Connectors pane that appears on the Simulink canvas.

The Sequence Viewer block shows where calls to functions are generated and which functions are called at different times. This information allows you to understand the flow of calls with respect to time and analyze the arguments sent during these calls to functions.