Fixed bug in PLC code generated with binary, octal and hexadecimal literals
authorLaurent Bessard
Tue, 28 May 2013 21:52:02 +0200
changeset 1181 21e6db77eb29
parent 1180 276a30c68eaa
child 1182 208103fd9ad0
Fixed bug in PLC code generated with binary, octal and hexadecimal literals
PLCGenerator.py
--- a/PLCGenerator.py	Tue May 28 17:52:57 2013 +0200
+++ b/PLCGenerator.py	Tue May 28 21:52:02 2013 +0200
@@ -654,7 +654,16 @@
                     self.Interface.append((varTypeNames[varlist["name"]], option, False, variables))
                 if len(located) > 0:
                     self.Interface.append((varTypeNames[varlist["name"]], option, True, located))
-        
+    
+    LITERAL_TYPES = {
+        "T": "TIME",
+        "D": "DATE",
+        "TOD": "TIME_OF_DAY",
+        "DT": "DATE_AND_TIME",
+        "2": "ANY",
+        "8": "ANY",
+        "16": "ANY",
+    }
     def ComputeConnectionTypes(self, pou):
         body = pou.getbody()
         if isinstance(body, ListType):
@@ -681,7 +690,9 @@
                     elif var_type is None:
                         parts = expression.split("#")
                         if len(parts) > 1:
-                            var_type = parts[0]
+                            literal_prefix = parts[0].upper()
+                            var_type = self.LITERAL_TYPES.get(literal_prefix, 
+                                                              literal_prefix)
                         elif expression.startswith("'"):
                             var_type = "STRING"
                         elif expression.startswith('"'):