modelStateMachinePy

Serial device whose behaviour is described by a state-machine Python script: its reply depends on what happened before

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

A serial device whose behaviour is not a table but a Python script: device.behaviour = Script, and scriptPath designates Device/state_machine.py.

The command table maps a command to a reply, without memory. This script keeps a state: the device only accepts a read if it has been started, refuses a second start, and counts the reads served. The same READ command therefore gets three different replies over the scenario.

The state is made observable by outputs(), which feeds the valueOut connector: plotting device.valueOut[1] shows the device starting then going back to stopped, and device.valueOut[2] shows the read counter. The script's messages appear in the simulation log, prefixed with the component name.

Each received line is delivered only once to the script, even if the simulation evaluates the same instant several times: a state transition is never replayed.

Components

TypeNameDefaultDescription
MCUmcuscriptPath = Resources/Scripts/MCU/uart_state_machine.py
MicroPythonMCU.Peripherals.UartGenericDevicedeviceBehaviour described by Resources/Scripts/Device/state_machine.py
Modelica.Blocks.Sources.SinemeasurementQuantity published in the replies to READ
Modelica.Electrical.Analog.Basic.Groundground