Skip to content

Machine Manager API

The Machine class acts as the supervisor for all state machines.

class automation.state_machine.Machine(*args, **kwargs)

Singleton class that manages the lifecycle and execution of all state machines in the system.

It handles the registration, starting, stopping, and configuration of state machines, including Data Acquisition (DAQ) machines and OPC UA Servers.

append_machine(self, machine, interval=, mode='async')

Registers a new state machine to be managed by the system.

Parameters:

  • machine (StateMachine): The state machine instance.
  • interval (FloatType): Execution interval in seconds.
  • mode (str): Execution mode ('async' or 'sync'). Default is 'async'.
drop(self, machine)

Removes a state machine from execution.

Parameters:

  • machine (StateMachine): The machine instance to remove.
get_machine(self, name)

Retrieves a registered state machine by its name.

Parameters:

  • name (str): The name of the state machine.

Returns:

  • StateMachine: The machine instance if found, otherwise None.

Usage:

>>> machine = app.get_machine('MyMachine')
get_machines(self)

Retrieves all registered state machines.

Returns:

  • list: A list of tuples containing (Machine, Interval, Mode).

Usage:

>>> machines = app.get_machines()
get_state_machine_manager(self)

Returns the internal StateMachineManager instance.

Returns:

  • StateMachineManager: The manager instance.
start(self, machines=None)

Initializes and starts the main StateMachineWorker.

It loads configuration from the database (if available) or uses the provided machines list.

Parameters:

  • machines (tuple, optional): A tuple of StateMachine instances to start immediately.
load_db_machines_config(self)

Reads machine configurations from the database.

join(self, machine)

Adds a machine to the running scheduler safely.

create_tag_internal_process_type(self, machine)

Automatically creates CVT tags for internal process variables defined in the state machine.

This allows internal variables of a state machine to be exposed as tags in the system.

Parameters:

  • machine (StateMachine): The machine instance.
create_alarm(self, name, tag, alarm_type='BOOL', trigger_value=True, description='', identifier=None, state='Normal', timestamp=None, ack_timestamp=None, user=None, reload=False)

Creates and registers an alarm in the Alarm Manager.

Parameters:

  • name (str): Alarm name.
  • tag (str): Associated tag name.
  • alarm_type (str): Type of alarm (e.g., 'BOOL', 'HIGH', 'LOW').
  • trigger_value (bool|float|int): Value that triggers the alarm.
  • description (str): Alarm description.
  • reload (bool): If True, forces reload/update.

Returns:

  • tuple: (Alarm object, Message string).
stop(self)

Safe stop of all state machine workers.