28 from copy import deepcopy |
28 from copy import deepcopy |
29 import os,sys,re |
29 import os,sys,re |
30 import datetime |
30 import datetime |
31 from time import localtime |
31 from time import localtime |
32 |
32 |
33 from plcopen import* |
33 from plcopen import * |
34 from graphics.GraphicCommons import * |
34 from graphics.GraphicCommons import * |
35 from PLCGenerator import * |
35 from PLCGenerator import * |
36 |
36 |
37 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
37 duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?") |
38 |
38 |
1295 variables_infos_xslt_tree(object_with_vars) |
1295 variables_infos_xslt_tree(object_with_vars) |
1296 |
1296 |
1297 return variables |
1297 return variables |
1298 |
1298 |
1299 # Add a global var to configuration to configuration |
1299 # Add a global var to configuration to configuration |
1300 def AddConfigurationGlobalVar(self, config_name, type, var_name, |
1300 def AddConfigurationGlobalVar(self, config_name, var_type, var_name, |
1301 location="", description=""): |
1301 location="", description=""): |
1302 if self.Project is not None: |
1302 if self.Project is not None: |
1303 # Found the configuration corresponding to name |
1303 # Found the configuration corresponding to name |
1304 configuration = self.Project.getconfiguration(config_name) |
1304 configuration = self.Project.getconfiguration(config_name) |
1305 if configuration is not None: |
1305 if configuration is not None: |
1306 # Set configuration global vars |
1306 # Set configuration global vars |
1307 configuration.addglobalVar(type, var_name, location, description) |
1307 configuration.addglobalVar( |
|
1308 self.GetVarTypeObject(var_type), |
|
1309 var_name, location, description) |
1308 |
1310 |
1309 # Replace the configuration globalvars by those given |
1311 # Replace the configuration globalvars by those given |
1310 def SetConfigurationGlobalVars(self, name, vars): |
1312 def SetConfigurationGlobalVars(self, name, vars): |
1311 if self.Project is not None: |
1313 if self.Project is not None: |
1312 # Found the configuration corresponding to name |
1314 # Found the configuration corresponding to name |
1631 # Return Data Type Object |
1633 # Return Data Type Object |
1632 def GetPou(self, typename, debug = False): |
1634 def GetPou(self, typename, debug = False): |
1633 project = self.GetProject(debug) |
1635 project = self.GetProject(debug) |
1634 if project is not None: |
1636 if project is not None: |
1635 result = project.getpou(typename) |
1637 result = project.getpou(typename) |
|
1638 if result is not None: |
|
1639 return result |
|
1640 for standardlibrary in [StdBlockLibrary, AddnlBlockLibrary]: |
|
1641 result = standardlibrary.getpou(typename) |
1636 if result is not None: |
1642 if result is not None: |
1637 return result |
1643 return result |
1638 for confnodetype in self.ConfNodeTypes: |
1644 for confnodetype in self.ConfNodeTypes: |
1639 result = confnodetype["types"].getpou(typename) |
1645 result = confnodetype["types"].getpou(typename) |
1640 if result is not None: |
1646 if result is not None: |
2408 connection.setconnectionParameter(idx, formalParameter) |
2414 connection.setconnectionParameter(idx, formalParameter) |
2409 else: |
2415 else: |
2410 connection.setconnectionParameter(idx, None) |
2416 connection.setconnectionParameter(idx, None) |
2411 idx += 1 |
2417 idx += 1 |
2412 |
2418 |
2413 def AddEditedElementPouVar(self, tagname, type, name, location="", description=""): |
2419 def GetVarTypeObject(self, var_type): |
|
2420 var_type_obj = PLCOpenParser.CreateElement("type", "variable") |
|
2421 if not var_type.startswith("ANY") and TypeHierarchy.get(var_type): |
|
2422 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
|
2423 var_type.lower() if var_type in ["STRING", "WSTRING"] |
|
2424 else var_type, "dataType")) |
|
2425 else: |
|
2426 derived_type = PLCOpenParser.CreateElement("derived", "dataType") |
|
2427 derived_type.setname(var_type) |
|
2428 var_type_obj.setcontent(derived_type) |
|
2429 return var_type_obj |
|
2430 |
|
2431 def AddEditedElementPouVar(self, tagname, var_type, name, location="", description=""): |
2414 if self.Project is not None: |
2432 if self.Project is not None: |
2415 words = tagname.split("::") |
2433 words = tagname.split("::") |
2416 if words[0] in ['P', 'T', 'A']: |
2434 if words[0] in ['P', 'T', 'A']: |
2417 pou = self.Project.getpou(words[1]) |
2435 pou = self.Project.getpou(words[1]) |
2418 if pou is not None: |
2436 if pou is not None: |
2419 pou.addpouLocalVar(type, name, location, description) |
2437 pou.addpouLocalVar( |
2420 |
2438 self.GetVarTypeObject(var_type), |
2421 def AddEditedElementPouExternalVar(self, tagname, type, name): |
2439 name, location, description) |
|
2440 |
|
2441 def AddEditedElementPouExternalVar(self, tagname, var_type, name): |
2422 if self.Project is not None: |
2442 if self.Project is not None: |
2423 words = tagname.split("::") |
2443 words = tagname.split("::") |
2424 if words[0] in ['P', 'T', 'A']: |
2444 if words[0] in ['P', 'T', 'A']: |
2425 pou = self.Project.getpou(words[1]) |
2445 pou = self.Project.getpou(words[1]) |
2426 if pou is not None: |
2446 if pou is not None: |
2427 pou.addpouExternalVar(type, name) |
2447 pou.addpouExternalVar( |
|
2448 self.GetVarTypeObject(var_type), name) |
2428 |
2449 |
2429 def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): |
2450 def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name): |
2430 if self.Project is not None: |
2451 if self.Project is not None: |
2431 words = tagname.split("::") |
2452 words = tagname.split("::") |
2432 if words[0] in ['P', 'T', 'A']: |
2453 if words[0] in ['P', 'T', 'A']: |