PLCGenerator.py
changeset 93 c3c24b979a4d
parent 80 c798a68c5560
child 104 a9b8916d906d
--- a/PLCGenerator.py	Mon Sep 17 10:13:56 2007 +0200
+++ b/PLCGenerator.py	Mon Sep 17 17:50:41 2007 +0200
@@ -198,16 +198,22 @@
                 if not isinstance(type, (StringType, UnicodeType)):
                     type = type.getName()
                     GeneratePouProgram(type)
-                initial = var.getInitialValue()
-                if initial:
-                    initial_value = initial.getValue()
+                    blocktype = GetBlockType(type)
+                    if blocktype:
+                        variables.extend(blocktype["initialise"](type, var.getName()))
+                        located = False
                 else:
-                    initial_value = None
-                address = var.getAddress()
-                if address:
-                    located = True
-                variables.append((type, var.getName(), address, initial_value))
-            self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
+                    initial = var.getInitialValue()
+                    if initial:
+                        initial_value = initial.getValue()
+                    else:
+                        initial_value = None
+                    address = var.getAddress()
+                    if address:
+                        located = True
+                    variables.append((type, var.getName(), address, initial_value))
+            if len(variables) > 0:
+                self.Interface.append((varTypeNames[varlist["name"]], varlist["value"].getRetain(), 
                             varlist["value"].getConstant(), located, variables))
     
     def GenerateProgram(self, pou):
@@ -622,7 +628,9 @@
                 program += " CONSTANT"
             program += "\n"
             for var_type, var_name, var_address, var_initial in variables:
-                program += "    %s "%var_name
+                program += "    "
+                if var_name:
+                    program += "%s "%var_name
                 if var_address != None:
                     program += "AT %s "%var_address
                 program += ": %s"%var_type