PLCGenerator.py
changeset 68 66308e07402c
parent 66 fd138fc77510
child 70 0e48629c1e6d
--- a/PLCGenerator.py	Thu Aug 09 18:07:44 2007 +0200
+++ b/PLCGenerator.py	Fri Aug 10 16:14:33 2007 +0200
@@ -61,6 +61,7 @@
         self.ReturnType = None
         self.Interface = []
         self.InitialSteps = []
+        self.BlockComputed = {}
         self.SFCNetworks = {"Steps":{}, "Transitions":{}, "Actions":{}}
         self.ActionNumber = 0
         self.Program = ""
@@ -84,15 +85,15 @@
             located = False
             for var in varlist["value"].getVariable():
                 type = var.getType().getValue()
+                if not isinstance(type, (StringType, UnicodeType)):
+                    type = type.getName()
                 initial = var.getInitialValue()
                 if initial:
                     initial_value = initial.getValue()
                 else:
                     initial_value = None
                 address = var.getAddress()
-                if address == "":
-                    address = None
-                else:
+                if address:
                     located = True
                 variables.append((type, var.getName(), address, initial_value))
             self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
@@ -159,10 +160,7 @@
                 variable = instance.outputVariables.getVariable()[0]
                 return self.ExtractModifier(variable, "%s(%s)"%(type, ", ".join(vars)))
             elif block_infos["type"] == "functionBlock":
-                if self.Interface[-1][0] != "VAR" or self.Interface[-1][1] or self.Interface[-1][2] or self.Interface[-1][3]:
-                    self.Interface.append(("VAR", False, False, False, []))
-                if not self.IsAlreadyDefined(name):
-                    self.Interface[-1][4].append((type, name, None, None))
+                if not self.BlockComputed.get(name, False):
                     vars = []
                     for variable in instance.inputVariables.getVariable():
                         connections = variable.connectionPointIn.getConnections()
@@ -171,6 +169,7 @@
                             value = self.ComputeFBDExpression(body, connections[0])
                             vars.append(self.ExtractModifier(variable, "%s := %s"%(parameter, value)))
                     self.Program += "  %s(%s);\n"%(name, ", ".join(vars))
+                    self.BlockComputed[name] = True
                 connectionPoint = link.getPosition()[-1]
                 for variable in instance.outputVariables.getVariable():
                     blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()