Adding tests for detecting POUs with no variables or/and no body
authorlbessard
Thu, 26 Jun 2008 09:18:16 +0200
changeset 214 a88b377f75cb
parent 213 4931959ea256
child 215 dd3381f38a9e
Adding tests for detecting POUs with no variables or/and no body
PLCGenerator.py
--- a/PLCGenerator.py	Mon Jun 23 18:48:49 2008 +0200
+++ b/PLCGenerator.py	Thu Jun 26 09:18:16 2008 +0200
@@ -117,7 +117,7 @@
         if pou_type in pouTypeNames:
             pou_program = PouProgram(pou.getname(), pouTypeNames[pou_type])
         else:
-            raise PLCGenException, "Undefined pou type"
+            raise PLCGenException, "Undefined pou type \"%s\""%pou_type
         pou_program.GenerateInterface(pou)
         pou_program.GenerateConnectionTypes(pou)
         pou_program.GenerateProgram(pou)
@@ -565,7 +565,7 @@
                             expression = self.ComputeFBDExpression(body, connections[0], order)
                             self.ComputedConnectors[name] = expression
                             return expression
-            raise PLCGenException, "No connector found"
+            raise PLCGenException, "No connector found corresponding to \"%s\" continuation in \"%s\" POU"%(name, self.Name)
 
     def GenerateLDPaths(self, connections, body):
         paths = []
@@ -786,7 +786,7 @@
                 connections = transition.getconnections()
                 network_type = self.GetNetworkType(connections, body)
                 if network_type == None:
-                    raise Exception
+                    raise PLCGenException, "Type of network connected to transition impossible to define in \"%s\" POU"%self.Name
                 if len(connections) > 1 or network_type == "LD":
                     paths = self.GenerateLDPaths(connections, body)
                     expression = self.ComputeLDExpression(paths, True)
@@ -845,14 +845,14 @@
             elif len(transition_infos["from"]) == 1:
                 self.Program += "%s"%transition_infos["from"][0]
             else:
-                raise PLCGenException, "Not connected transition"
+                raise PLCGenException, "Transition with content \"%s\" not connected to a previous step in \"%s\" POU"%(transition_infos["content"], self.Name)
             self.Program += " TO "
             if len(transition_infos["to"]) > 1:
                 self.Program += "(%s)"%", ".join(transition_infos["to"])
             elif len(transition_infos["to"]) == 1:
                 self.Program += "%s"%transition_infos["to"][0]
             else:
-                raise PLCGenException, "Not connected transition"
+                raise PLCGenException, "Transition with content \"%s\" not connected to a next step in \"%s\" POU"%(transition_infos["content"], self.Name)
             self.Program += transition_infos["content"]
             self.Program += "  END_TRANSITION\n\n"
             for step_name in transition_infos["to"]:
@@ -902,6 +902,10 @@
             program = "%s %s : %s\n"%(self.Type, self.Name, self.ReturnType)
         else:
             program = "%s %s\n"%(self.Type, self.Name)
+        if len(self.Interface) == 0:
+            raise PLCGenException, "No variable defined in \"%s\" POU"%self.Name
+        if self.Program == "":
+            raise PLCGenException, "No body defined in \"%s\" POU"%self.Name
         for list_type, retain, constant, located, variables in self.Interface:
             program += "  %s"%list_type
             if retain: