I have a statechart that does stuff depending on another statechart. Let's call them Master and Slave.
In the Slave statechart I import the Master and assign it to a variable.
import: "Master.ysc"
var master: Master
Let's say the Slave statechart is in StateA
and wants to go to StateB
when Master triggers an event B
. Then as a transition trigger I use master.B
My problem is that the Slave statechart doesn't see the Master events. In the generated (Python) code self.master = None
in the init method of the Slave, and it always stays None
. Is there a way to do this properly?
I also tried to raise an event in the Slave directly from Master, as in this question:
import: "Slave.ysc"
var slave: Slave
raise slave.goto_b
But here I also have a problem with the reference being None.
self.slave.raise_goto_b()
AttributeError: 'NoneType' object has no attribute 'raise_goto_b'
Am I missing something simple (an assignment to the master/slave variable or something), or is it a problem with the Python bindings?
I was indeed missing an assignment. I should just have tried harder with the answer in this question.
So I sent a reference of the Master statemachine to the Slave. In Main:
master_fsm = MasterFsm()
slave_fsm = SlaveFsm(master_fsm)
The 'Fsms' have an sm
attribute with the generated class.
So in the SlaveFsm's init method I did:
def __init__(self, master_fsm):
self.sm = Slave()
self.sm.master = master_fsm.sm
And then it works!