State Machine API documentation
rackio.RackioStateMachine
(name, **kwargs)Class used to define custom state machines.
This class is used to define custom machines, by defining parameters, states, transitions and by defining methods state behaviour can de defined.
Parameters:
- name (str): state machine name.
Usage:
from rackio import RackioStateMachine, State
class TwoStep(RackioStateMachine):
# states
state1 = State('State1', initial=True)
state2 = State('State2')
# transitions
forward = state1.to(state2)
back = state2.to(state1)
# parameters
count = 0
def on_back(self):
self.count = 0
def while_state1(self):
self.count += 1
logging.warning("{}: {}".format(self.name, self.count))
if self.count == 5:
self.forward()
def while_state2(self):
self.count += 1
logging.warning("{}: {}".format(self.name, self.count))
if self.count >= 10:
self.back()
Bindings
rackio.TagBinding
(tag, direction='read')Class used within Rackio State Machine.
This class is used to bind tag values with
an instance of a Rackio State Machine object,
in the machine loop, before executing current
state, tag bindings of an object are updated
with last values from the Tag Engine,
after execution, the Tag Engine is updated,
the direction of the binding must be provided,
otherwise read
direction is used.
Usage:
class TwoStep(RackioStateMachine):
# states
state1 = State('State1', initial=True)
state2 = State('State2')
# transitions
forward = state1.to(state2)
back = state2.to(state1)
# bindings
t1 = TagBinding("T1")
t2 = TagBinding("T2", direction="write")
rackio.GroupBinding
(group, direction='read')Class used within Rackio State Machine.
This class is used to bind a tag group values
with an instance of a Rackio State Machine object,
in the machine loop, before executing current
state, group bindings of an object are updated
with last values of all tags in that group from
the Tag Engine, after execution, the Tag Engine
is updated, the direction of the binding must be
provided, otherwise read
direction is used.
Usage:
class TwoStep(RackioStateMachine):
# states
state1 = State('State1', initial=True)
state2 = State('State2')
# transitions
forward = state1.to(state2)
back = state2.to(state1)
# bindings
g1 = GroupBinding("G1")
g2 = GroupBinding("G2", direction="write")