PLCControler.py
changeset 1306 1ff1cdf6c318
parent 1304 6be6c1e0e4d0
child 1308 ad61268dbdb6
equal deleted inserted replaced
1305:714f1381a09a 1306:1ff1cdf6c318
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 from xml.dom import minidom
    25 from xml.dom import minidom
    26 from types import StringType, UnicodeType, TupleType
    26 from types import StringType, UnicodeType, TupleType
    27 import cPickle
       
    28 from copy import deepcopy
    27 from copy import deepcopy
    29 import os,sys,re
    28 import os,sys,re
    30 import datetime
    29 import datetime
    31 from time import localtime
    30 from time import localtime
    32 
    31 
  1175             var_type = PLCOpenParser.CreateElement("type", "variable")
  1174             var_type = PLCOpenParser.CreateElement("type", "variable")
  1176             if isinstance(var["Type"], TupleType):
  1175             if isinstance(var["Type"], TupleType):
  1177                 if var["Type"][0] == "array":
  1176                 if var["Type"][0] == "array":
  1178                     array_type, base_type_name, dimensions = var["Type"]
  1177                     array_type, base_type_name, dimensions = var["Type"]
  1179                     array = PLCOpenParser.CreateElement("array", "dataType")
  1178                     array = PLCOpenParser.CreateElement("array", "dataType")
       
  1179                     baseType = PLCOpenParser.CreateElement("baseType", "array")
       
  1180                     array.setbaseType(baseType)
  1180                     for i, dimension in enumerate(dimensions):
  1181                     for i, dimension in enumerate(dimensions):
  1181                         dimension_range = PLCOpenParser.CreateElement("range", "dimension")
  1182                         dimension_range = PLCOpenParser.CreateElement("dimension", "array")
  1182                         if i == 0:
  1183                         if i == 0:
  1183                             array.setdimension([dimension_range])
  1184                             array.setdimension([dimension_range])
  1184                         else:
  1185                         else:
  1185                             array.appenddimension(dimension_range)
  1186                             array.appenddimension(dimension_range)
  1186                         dimension_range.setlower(dimension[0])
  1187                         dimension_range.setlower(dimension[0])
  1187                         dimension_range.setupper(dimension[1])
  1188                         dimension_range.setupper(dimension[1])
  1188                     if base_type_name in self.GetBaseTypes():
  1189                     if base_type_name in self.GetBaseTypes():
  1189                         array.baseType.setcontent(PLCOpenParser.CreateElement(
  1190                         baseType.setcontent(PLCOpenParser.CreateElement(
  1190                             base_type_name.lower()
  1191                             base_type_name.lower()
  1191                             if base_type_name in ["STRING", "WSTRING"]
  1192                             if base_type_name in ["STRING", "WSTRING"]
  1192                             else base_type_name, "dataType"))
  1193                             else base_type_name, "dataType"))
  1193                     else:
  1194                     else:
  1194                         derived_datatype = PLCOpenParser.CreateElement("derived", "dataType")
  1195                         derived_datatype = PLCOpenParser.CreateElement("derived", "dataType")
  1195                         derived_datatype.setname(base_type_name)
  1196                         derived_datatype.setname(base_type_name)
  1196                         array.baseType.setcontent(derived_datatype)
  1197                         baseType.setcontent(derived_datatype)
  1197                     var_type.setcontent(array)
  1198                     var_type.setcontent(array)
  1198             elif var["Type"] in self.GetBaseTypes():
  1199             elif var["Type"] in self.GetBaseTypes():
  1199                 var_type.setcontent(PLCOpenParser.CreateElement(
  1200                 var_type.setcontent(PLCOpenParser.CreateElement(
  1200                     var["Type"].lower()
  1201                     var["Type"].lower()
  1201                     if var["Type"] in ["STRING", "WSTRING"]
  1202                     if var["Type"] in ["STRING", "WSTRING"]
  1768         if datatype is not None:
  1769         if datatype is not None:
  1769             return self.IsLocatableDataType(datatype)
  1770             return self.IsLocatableDataType(datatype)
  1770         return True
  1771         return True
  1771     
  1772     
  1772     def IsEnumeratedType(self, typename, debug = False):
  1773     def IsEnumeratedType(self, typename, debug = False):
       
  1774         if isinstance(typename, TupleType):
       
  1775             typename = typename[1]
  1773         datatype = self.GetDataType(typename, debug)
  1776         datatype = self.GetDataType(typename, debug)
  1774         if datatype is not None:
  1777         if datatype is not None:
  1775             basetype_content = datatype.baseType.getcontent()
  1778             basetype_content = datatype.baseType.getcontent()
  1776             basetype_content_type = basetype_content.getLocalTag()
  1779             basetype_content_type = basetype_content.getLocalTag()
  1777             if basetype_content_type == "derived":
  1780             if basetype_content_type == "derived":
  1780         return False
  1783         return False
  1781 
  1784 
  1782     def IsSubrangeType(self, typename, exclude=None, debug = False):
  1785     def IsSubrangeType(self, typename, exclude=None, debug = False):
  1783         if typename == exclude:
  1786         if typename == exclude:
  1784             return False
  1787             return False
       
  1788         if isinstance(typename, TupleType):
       
  1789             typename = typename[1]
  1785         datatype = self.GetDataType(typename, debug)
  1790         datatype = self.GetDataType(typename, debug)
  1786         if datatype is not None:
  1791         if datatype is not None:
  1787             basetype_content = datatype.baseType.getcontent()
  1792             basetype_content = datatype.baseType.getcontent()
  1788             basetype_content_type = basetype_content.getLocalTag()
  1793             basetype_content_type = basetype_content.getLocalTag()
  1789             if basetype_content_type == "derived":
  1794             if basetype_content_type == "derived":