Browse Source

Add example code to run the SCCD binding with an activity

Yentl Van Tendeloo 3 years ago
parent
commit
c4655db3ac
2 changed files with 81 additions and 0 deletions
  1. 36 0
      examples/SCCD_callback.py
  2. 45 0
      examples/SCCD_callback_SCCD.xml

+ 36 - 0
examples/SCCD_callback.py

@@ -0,0 +1,36 @@
+import sys
+sys.path.append("wrappers")
+sys.path.append("examples")
+
+from modelverse import *
+import SCCD_callback_SCCD
+
+init()
+login("admin", "admin")
+
+model_add("models/my_FSA", "formalisms/MyOwnFSA", """
+    InitialState init{
+        name = "initial"
+    }
+    State s1{
+        name = "S1"
+    }
+    State s2{
+        name = "S2"
+    }
+    Transition (init, s1) {
+        trigger = "B"
+        raise = "C"
+    }
+    Transition (s1, s2) {
+        trigger = "A"
+        raise = "D"
+    }
+    """)
+
+ctrl = SCCD_callback_SCCD.Controller(keep_running=False)
+thrd = threading.Thread(target=ctrl.start)
+thrd.daemon = True
+thrd.start()
+
+transformation_execute_AL("formalisms/MyOwnFSA_activities/simulate", {"FSA": "models/my_FSA"}, {}, (ctrl, "inp", "outp"))

+ 45 - 0
examples/SCCD_callback_SCCD.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<diagram author="Yentl Van Tendeloo" name="Logging">
+    <inport name="inp"/>
+    <outport name="outp"/>
+
+    <class name="Logging" default="true">
+        <scxml initial="init">
+            <state id="init" initial="wait_output">
+                <state id="wait_output">
+                    <transition event="input" port="inp" target=".">
+                        <parameter name="value"/>
+                        <script>
+                            print("SCCD got input " + str(value))
+                        </script>
+                    </transition>
+
+                    <transition after="0.1" target="."/>
+                </state>
+
+                <transition after="2.0" target=".">
+                    <raise event="output" scope="output" port="outp">
+                        <parameter expr="'B'"/>
+                    </raise>
+                    <script>
+                        print("SCCD sent output 'B'")
+                    </script>
+                </transition>
+
+                <transition event="terminate" port="inp" target="../finished">
+                    <script>
+                        print("Got terminate")
+                    </script>
+                </transition>
+            </state>
+
+            <state id="finished">
+                <onentry>
+                    <script>
+                        print("FINISHED")
+                    </script>
+                </onentry>
+            </state>
+        </scxml>
+    </class>
+</diagram>