check before program generation whether SFC step, that is referenced
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 12 Jan 2017 14:37:55 +0300
changeset 1626 0779c1b18c01
parent 1625 be3f68731798
child 1627 c431d64589ef
check before program generation whether SFC step, that is referenced
by SFC jump, does exists
PLCGenerator.py
plcopen/plcopen.py
--- a/PLCGenerator.py	Wed Jan 11 14:15:45 2017 +0300
+++ b/PLCGenerator.py	Thu Jan 12 14:37:55 2017 +0300
@@ -1387,6 +1387,10 @@
 
     def GenerateSFCJump(self, jump, pou):
         jump_target = jump.gettargetName()
+        if not pou.hasstep(jump_target):
+            pname = pou.getname()
+            msg = _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\"").format( a1 = pname, a2 = jump_target)
+            raise PLCGenException, msg
         if jump.connectionPointIn is not None:
             instances = []
             connections = jump.connectionPointIn.getconnections()
--- a/plcopen/plcopen.py	Wed Jan 11 14:15:45 2017 +0300
+++ b/plcopen/plcopen.py	Thu Jan 12 14:37:55 2017 +0300
@@ -1245,6 +1245,14 @@
                                 self.interface.remove(varlist)
                             break
     setattr(cls, "removepouVar", removepouVar)
+
+    def hasstep(self, name=None):
+        if self.getbodyType() in ["SFC"]:
+            for instance in self.getinstances():
+                if isinstance(instance, PLCOpenParser.GetElementClass("step", "sfcObjects")) and TextMatched(instance.getname(), name):
+                    return True         
+        return False
+    setattr(cls, "hasstep", hasstep)
     
     def hasblock(self, name=None, block_type=None):
         if self.getbodyType() in ["FBD", "LD", "SFC"]: