Reference for the automation_machine Python DSL that backs .machine and .seq files. While most editing is performed visually in the Sequence Editor and Machine Editor, you can also inspect or write these declarations directly in Python.
from automation_machine import (
Machine,
Sequence,
SequenceType,
Step,
StepType,
Transition,
Action,
ActionQualifier,
ActionInstruction,
ActionOperand,
Variable,
)
| Symbol |
Kind |
Purpose |
Machine |
class |
Project configuration for instances, hardware stations, datatypes, and variables |
Sequence |
class |
Base class for every SFC sequence |
SequenceType |
enum |
NORMAL, MACRO, ENCLOSING |
Step |
class |
A step node in a sequence |
StepType |
enum |
INITIAL, NORMAL, MACRO, ENCLOSING |
Transition |
class |
A boolean-gated link between steps |
Action |
class |
A qualifier, condition, expression, or instruction attached to a step |
ActionQualifier |
enum |
Controls when the action runs (N, S, R, P, L, D, SD, DS, SL) |
ActionInstruction |
enum |
Controls what the action does (TON, MOVE, CTU, CONCAT, ...) |
ActionOperand |
class |
Operand for multi-input instructions |
Variable |
class |
A variable entry in the project variable table |
Defines the project configuration in main.machine.
| Field |
Type |
Description |
name |
str |
Project name |
version |
str |
Project version string |
description |
str |
Project summary |
author |
str |
Project author |
export_targets |
list[str] |
Configured export target IDs (for example ["codesys", "siemens"]) |
clients |
list[str] |
Connected client identifiers |
metadata |
dict[str, Any] |
Project metadata dictionary |
| Method |
Purpose |
setup() |
Configure project metadata, datatypes, variables, stations, and sequence instances |
add_instance(class_name, instance_name=None, options=None, **params) |
Register a sequence instance with optional boolean options and parameters |
add_station(label, *, protocol=None) |
Register a hardware station (profinet, ethercat, ethernet-ip, io-link, modbus-tcp, modbus-rtu, canopen, profibus, as-interface, opc-ua) |
declare_variable(name, data_type, initial_value=None, description="", usage="local", dimensions=None) |
Explicitly declare (freeze) a project variable |
declare_struct(name, **fields) |
Declare a custom STRUCT data type |
declare_enum(name, *values) |
Declare a custom ENUM data type |
from automation_machine import Machine
class LineMachine(Machine):
def setup(self):
self.name = "PackagingLine"
self.version = "1.2.0"
self.export_targets = ["codesys", "siemens"]
self.declare_enum("MachineMode", "MANUAL", "AUTO", "MAINTENANCE")
self.declare_struct("CylinderIO", extend="BOOL", retract="BOOL", at_work="BOOL", at_home="BOOL")
self.declare_variable("CurrentMode", "MachineMode", initial_value="MANUAL", usage="local")
self.add_instance("ClampUnit", "Clamp1", options={"WithPartCheck": True})
self.add_instance("ClampUnit", "Clamp2", options={"WithPartCheck": False})
Base class for .seq files. Subclass Sequence and define your logic in setup().
| Method |
Returns |
Purpose |
add_step(step_type=NORMAL, name=None, comment=None) |
Step |
Create a step |
add_transition(source, target, condition="True", comment=None) |
Transition |
Create a transition between steps (supports lists of steps for divergences and convergences) |
add_macro_step(name, sub_class_name, entry_step=None, exit_step=None) |
Step |
Create a macro step referencing a sub-sequence |
add_enclosing_step(name, sub_class_name) |
Step |
Create an enclosing step |
declare_variable(name, data_type, initial_value=None, description="") |
Variable |
Declare a sequence-scoped variable |
declare_option(name, default=False, label=None, description=None) |
None |
Declare a boolean sequence option |
option(name, when=True) |
Context Manager |
Gate steps, transitions, and actions inside a with self.option(...): block |
add_submodule(name, class_name, **params) |
Any |
Register a child sub-module instance on this sequence class |
add_command(name, condition) |
None |
Define a named command trigger for this sequence |
done(condition="True") |
None |
Mark the sequence completion condition |
from automation_machine import Sequence, StepType
class ClampUnit(Sequence):
def setup(self):
self.name = "ClampUnit"
self.declare_option("WithPartCheck", default=True, label="Verify part presence")
self.s0 = self.add_step(StepType.INITIAL, name="Idle")
self.s1 = self.add_step(name="Clamp")
self.s1.add_action("{ClampExtend}")
with self.option("WithPartCheck"):
self.s_check = self.add_step(name="VerifyPart")
self.add_transition(self.s0, self.s_check, "{StartCmd}")
self.add_transition(self.s_check, self.s1, "{PartSensor}")
with self.option("WithPartCheck", when=False):
self.add_transition(self.s0, self.s1, "{StartCmd}")
self.add_transition(self.s1, self.s0, "{ClampAtWork}")
¶ Step and Action
Returned by Sequence.add_step(). Attach actions to a step using step.add_action().
step.add_action(
name: str,
description: str = "",
qualifier: ActionQualifier = ActionQualifier.N,
instruction: ActionInstruction | str | None = None,
duration: float | ActionOperand | None = None,
operands: list[ActionOperand] | None = None,
preset_value: int | ActionOperand | None = None,
condition: str | None = None,
expression: str | None = None,
comment: str | None = None,
parameters: dict[str, Any] | None = None,
) -> Action
| Parameter |
Type |
Description |
name |
str |
Target variable or timer/counter instance name |
description |
str |
Human-readable label |
qualifier |
ActionQualifier |
Execution timing (N, S, R, P, L, D, SD, DS, SL) |
instruction |
ActionInstruction or None |
Optional function-block or operator instruction |
duration |
float or ActionOperand or None |
Duration in milliseconds (or variable operand) for timers and timed qualifiers |
operands |
list[ActionOperand] or None |
Input operands for multi-input instructions |
preset_value |
int or ActionOperand or None |
Target count for counter instructions |
condition |
str or None |
Optional boolean guard condition ([cond]) evaluated while the step is active |
expression |
str or None |
Optional boolean assignment expression (:= expr) |
comment |
str or None |
Optional action comment |
s1.add_action("MotorRun", description="Run conveyor", condition="SafetyOk")
s1.add_action("ReadyLamp", expression="AutoMode AND SensorHome")
s1.add_action("DelayTimer", instruction=ActionInstruction.TON, duration=2500)
| Value |
Name |
Behavior |
N |
Non-stored |
Active while the step is active (default) |
S |
Set (Stored) |
Latches TRUE when the step activates; remains TRUE until reset |
R |
Reset |
Resets a latched variable, timer, or counter to FALSE / 0 |
P |
Pulse |
Executes for one scan cycle on step activation |
L |
Time-limited |
Active for duration, then turns off |
D |
Time-delayed |
Turns on after duration if the step is still active |
SD |
Stored and time-delayed |
Latches TRUE after duration even if the step deactivates |
DS |
Delayed and stored |
Latches TRUE after duration only if the step stays active |
SL |
Stored and time-limited |
Latches TRUE for duration, then resets automatically |
| Value |
Description |
SR |
Set-dominant flip-flop |
RS |
Reset-dominant flip-flop |
R_TRIG |
Rising-edge trigger (FALSE -> TRUE) |
F_TRIG |
Falling-edge trigger (TRUE -> FALSE) |
| Value |
Description |
TON |
On-delay timer (.IN, .Q, .PT, .ET) |
TOF |
Off-delay timer (.IN, .Q, .PT, .ET) |
TP |
Pulse timer (.IN, .Q, .PT, .ET) |
RTO |
Retentive on-delay timer (.IN, .R, .Q, .PT, .ET) |
CTU |
Count-up counter (.CU, .R, .Q, .PV, .CV) |
CTD |
Count-down counter (.CD, .LD, .Q, .PV, .CV) |
CTUR |
Resettable count-up counter |
CTDR |
Resettable count-down counter |
| Value |
Description |
MOVE |
Copy value (IN -> target) |
ADD |
Addition (IN1 + IN2 -> target) |
SUB |
Subtraction (IN1 - IN2 -> target) |
MUL |
Multiplication (IN1 * IN2 -> target) |
DIV |
Division (IN1 / IN2 -> target) |
MOD |
Modulo remainder (IN1 MOD IN2 -> target) |
| Value |
Description |
EQ |
Equal (IN1 == IN2) |
NE |
Not equal (IN1 <> IN2) |
GT |
Greater than (IN1 > IN2) |
GE |
Greater than or equal (IN1 >= IN2) |
LT |
Less than (IN1 < IN2) |
LE |
Less than or equal (IN1 <= IN2) |
| Value |
Description |
CONCAT |
Concatenate two strings (IN1, IN2) |
LEN |
String length (IN) |
LEFT |
Leftmost L characters (IN, L) |
RIGHT |
Rightmost L characters (IN, L) |
MID |
Substring of length L at position P (IN, L, P) |
FIND |
Position of IN2 inside IN1 (IN1, IN2) |
REPLACE |
Replace L characters at position P (IN1, IN2, L, P) |
INSERT |
Insert IN2 into IN1 at position P (IN1, IN2, P) |
DELETE |
Delete L characters from IN at position P (IN, L, P) |
| Value |
Description |
INT_TO_STRING |
Convert INT to STRING |
DINT_TO_STRING |
Convert DINT to STRING |
REAL_TO_STRING |
Convert REAL to STRING |
STRING_TO_INT |
Convert STRING to INT |
STRING_TO_REAL |
Convert STRING to REAL |
BOOL_TO_STRING |
Convert BOOL to STRING |
¶ ActionOperand
from automation_machine import ActionOperand
ActionOperand("temperature")
ActionOperand("1500", is_literal=True)
| Parameter |
Type |
Description |
value |
str |
Variable name or literal value |
is_literal |
bool |
True for a constant literal, False for a variable reference (default False) |