PLCControler.py
changeset 2450 5024c19ca8f0
parent 2447 1c04a50dc7ff
child 2456 7373e3048167
equal deleted inserted replaced
2449:b0560adec4b7 2450:5024c19ca8f0
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    25 
    25 
    26 
    26 
    27 from __future__ import absolute_import
    27 from __future__ import absolute_import
    28 from __future__ import division
    28 from __future__ import division
    29 from types import TupleType
       
    30 from copy import deepcopy
    29 from copy import deepcopy
    31 import os
    30 import os
    32 import re
    31 import re
    33 import datetime
    32 import datetime
    34 from time import localtime
    33 from time import localtime
   872             # Create variable and change its properties
   871             # Create variable and change its properties
   873             tempvar = PLCOpenParser.CreateElement("variable", "varListPlain")
   872             tempvar = PLCOpenParser.CreateElement("variable", "varListPlain")
   874             tempvar.setname(var.Name)
   873             tempvar.setname(var.Name)
   875 
   874 
   876             var_type = PLCOpenParser.CreateElement("type", "variable")
   875             var_type = PLCOpenParser.CreateElement("type", "variable")
   877             if isinstance(var.Type, TupleType):
   876             if isinstance(var.Type, tuple):
   878                 if var.Type[0] == "array":
   877                 if var.Type[0] == "array":
   879                     _array_type, base_type_name, dimensions = var.Type
   878                     _array_type, base_type_name, dimensions = var.Type
   880                     array = PLCOpenParser.CreateElement("array", "dataType")
   879                     array = PLCOpenParser.CreateElement("array", "dataType")
   881                     baseType = PLCOpenParser.CreateElement("baseType", "array")
   880                     baseType = PLCOpenParser.CreateElement("baseType", "array")
   882                     array.setbaseType(baseType)
   881                     array.setbaseType(baseType)
  1365             if array_base_type.getLocalTag() == "derived":
  1364             if array_base_type.getLocalTag() == "derived":
  1366                 return self.IsLocatableType(array_base_type.getname(), debug)
  1365                 return self.IsLocatableType(array_base_type.getname(), debug)
  1367         return True
  1366         return True
  1368 
  1367 
  1369     def IsLocatableType(self, typename, debug=False):
  1368     def IsLocatableType(self, typename, debug=False):
  1370         if isinstance(typename, TupleType) or self.GetBlockType(typename) is not None:
  1369         if isinstance(typename, tuple) or self.GetBlockType(typename) is not None:
  1371             return False
  1370             return False
  1372 
  1371 
  1373         # the size of these types is implementation dependend
  1372         # the size of these types is implementation dependend
  1374         if typename in ["TIME", "DATE", "DT", "TOD"]:
  1373         if typename in ["TIME", "DATE", "DT", "TOD"]:
  1375             return False
  1374             return False
  1378         if datatype is not None:
  1377         if datatype is not None:
  1379             return self.IsLocatableDataType(datatype)
  1378             return self.IsLocatableDataType(datatype)
  1380         return True
  1379         return True
  1381 
  1380 
  1382     def IsEnumeratedType(self, typename, debug=False):
  1381     def IsEnumeratedType(self, typename, debug=False):
  1383         if isinstance(typename, TupleType):
  1382         if isinstance(typename, tuple):
  1384             typename = typename[1]
  1383             typename = typename[1]
  1385         datatype = self.GetDataType(typename, debug)
  1384         datatype = self.GetDataType(typename, debug)
  1386         if datatype is not None:
  1385         if datatype is not None:
  1387             basetype_content = datatype.baseType.getcontent()
  1386             basetype_content = datatype.baseType.getcontent()
  1388             basetype_content_type = basetype_content.getLocalTag()
  1387             basetype_content_type = basetype_content.getLocalTag()
  1392         return False
  1391         return False
  1393 
  1392 
  1394     def IsSubrangeType(self, typename, exclude=None, debug=False):
  1393     def IsSubrangeType(self, typename, exclude=None, debug=False):
  1395         if typename == exclude:
  1394         if typename == exclude:
  1396             return False
  1395             return False
  1397         if isinstance(typename, TupleType):
  1396         if isinstance(typename, tuple):
  1398             typename = typename[1]
  1397             typename = typename[1]
  1399         datatype = self.GetDataType(typename, debug)
  1398         datatype = self.GetDataType(typename, debug)
  1400         if datatype is not None:
  1399         if datatype is not None:
  1401             basetype_content = datatype.baseType.getcontent()
  1400             basetype_content = datatype.baseType.getcontent()
  1402             basetype_content_type = basetype_content.getLocalTag()
  1401             basetype_content_type = basetype_content.getLocalTag()
  1611                 datatype.baseType.setcontent(struct)
  1610                 datatype.baseType.setcontent(struct)
  1612                 for i, element_infos in enumerate(infos["elements"]):
  1611                 for i, element_infos in enumerate(infos["elements"]):
  1613                     element = PLCOpenParser.CreateElement("variable", "struct")
  1612                     element = PLCOpenParser.CreateElement("variable", "struct")
  1614                     element.setname(element_infos["Name"])
  1613                     element.setname(element_infos["Name"])
  1615                     element_type = PLCOpenParser.CreateElement("type", "variable")
  1614                     element_type = PLCOpenParser.CreateElement("type", "variable")
  1616                     if isinstance(element_infos["Type"], TupleType):
  1615                     if isinstance(element_infos["Type"], tuple):
  1617                         if element_infos["Type"][0] == "array":
  1616                         if element_infos["Type"][0] == "array":
  1618                             _array_type, base_type_name, dimensions = element_infos["Type"]
  1617                             _array_type, base_type_name, dimensions = element_infos["Type"]
  1619                             array = PLCOpenParser.CreateElement("array", "dataType")
  1618                             array = PLCOpenParser.CreateElement("array", "dataType")
  1620                             baseType = PLCOpenParser.CreateElement("baseType", "array")
  1619                             baseType = PLCOpenParser.CreateElement("baseType", "array")
  1621                             array.setbaseType(baseType)
  1620                             array.setbaseType(baseType)