86 LibraryControler = None |
87 LibraryControler = None |
87 |
88 |
88 def _AddParamsMembers(self): |
89 def _AddParamsMembers(self): |
89 self.PlugParams = None |
90 self.PlugParams = None |
90 if self.XSD: |
91 if self.XSD: |
91 Classes = GenerateClassesFromXSDstring(self.XSD) |
92 self.Classes = GenerateClassesFromXSDstring(self.XSD) |
92 Classes = [(name, XSDclass) for name, XSDclass in Classes.items() if XSDclass.IsBaseClass] |
93 Classes = [(name, XSDclass) for name, XSDclass in self.Classes.items() if XSDclass.IsBaseClass] |
93 if len(Classes) == 1: |
94 if len(Classes) == 1: |
94 name, XSDclass = Classes[0] |
95 name, XSDclass = Classes[0] |
95 obj = XSDclass() |
96 obj = XSDclass() |
96 self.PlugParams = (name, obj) |
97 self.PlugParams = (name, obj) |
97 setattr(self, name, obj) |
98 setattr(self, name, obj) |
811 def GetPlugInfos(self): |
812 def GetPlugInfos(self): |
812 childs = [] |
813 childs = [] |
813 for child in self.IterChilds(): |
814 for child in self.IterChilds(): |
814 childs.append(child.GetPlugInfos()) |
815 childs.append(child.GetPlugInfos()) |
815 return {"name" : "PLC (%s)"%self.GetProjectName(), "type" : None, "values" : childs} |
816 return {"name" : "PLC (%s)"%self.GetProjectName(), "type" : None, "values" : childs} |
|
817 |
|
818 def GetDefaultTarget(self): |
|
819 target = self.Classes["BeremizRoot_TargetType"]() |
|
820 if wx.Platform == '__WXMSW__': |
|
821 target.setcontent({"name": "Win32", "value": self.Classes["TargetType_Win32"]()}) |
|
822 else: |
|
823 target.setcontent({"name": "Linux", "value": self.Classes["TargetType_Linux"]()}) |
|
824 return target |
|
825 |
|
826 def GetParamsAttributes(self, path = None): |
|
827 params = PlugTemplate.GetParamsAttributes(self, path) |
|
828 if params[0]["name"] == "BeremizRoot": |
|
829 for child in params[0]["children"]: |
|
830 if child["name"] == "TargetType" and child["value"] == '': |
|
831 child.update(self.GetDefaultTarget().getElementInfos("TargetType")) |
|
832 return params |
|
833 |
|
834 def SetParamsAttribute(self, path, value): |
|
835 if path.startswith("BeremizRoot.TargetType.") and self.BeremizRoot.getTargetType().getcontent() is None: |
|
836 self.BeremizRoot.setTargetType(self.GetDefaultTarget()) |
|
837 return PlugTemplate.SetParamsAttribute(self, path, value) |
816 |
838 |
817 def NewProject(self, ProjectPath, BuildPath=None): |
839 def NewProject(self, ProjectPath, BuildPath=None): |
818 """ |
840 """ |
819 Create a new project in an empty folder |
841 Create a new project in an empty folder |
820 @param ProjectPath: path of the folder where project have to be created |
842 @param ProjectPath: path of the folder where project have to be created |
905 if self.AppFrame is not None: |
927 if self.AppFrame is not None: |
906 self.AppFrame.RefreshLibraryTree() |
928 self.AppFrame.RefreshLibraryTree() |
907 self.AppFrame.RefreshEditor() |
929 self.AppFrame.RefreshEditor() |
908 |
930 |
909 def GetVariableLocationTree(self): |
931 def GetVariableLocationTree(self): |
910 return PlugTemplate.GetVariableLocationTree(self) |
932 ''' |
|
933 This function is meant to be overridden by plugins. |
|
934 |
|
935 It should returns an list of dictionaries |
|
936 |
|
937 - IEC_type is an IEC type like BOOL/BYTE/SINT/... |
|
938 - location is a string of this variable's location, like "%IX0.0.0" |
|
939 ''' |
|
940 children = [] |
|
941 for child in self.IECSortedChilds(): |
|
942 children.append(child.GetVariableLocationTree()) |
|
943 return children |
911 |
944 |
912 def PluginPath(self): |
945 def PluginPath(self): |
913 return os.path.join(os.path.split(__file__)[0], "plugins") |
946 return os.path.join(os.path.split(__file__)[0], "plugins") |
914 |
947 |
915 def PlugPath(self, PlugName=None): |
948 def PlugPath(self, PlugName=None): |
1065 def GetBuilder(self): |
1098 def GetBuilder(self): |
1066 """ |
1099 """ |
1067 Return a Builder (compile C code into machine code) |
1100 Return a Builder (compile C code into machine code) |
1068 """ |
1101 """ |
1069 # Get target, module and class name |
1102 # Get target, module and class name |
1070 targetname = self.BeremizRoot.getTargetType().getcontent()["name"] |
1103 target = self.BeremizRoot.getTargetType() |
|
1104 if target.getcontent() is None: |
|
1105 target = self.GetDefaultTarget() |
|
1106 targetname = target.getcontent()["name"] |
1071 modulename = "targets." + targetname |
1107 modulename = "targets." + targetname |
1072 classname = targetname + "_target" |
1108 classname = targetname + "_target" |
1073 |
1109 |
1074 # Get module reference |
1110 # Get module reference |
1075 try : |
1111 try : |
1245 "retrieve_calls":"\n", |
1281 "retrieve_calls":"\n", |
1246 "publish_calls":"\n", |
1282 "publish_calls":"\n", |
1247 "init_calls":"\n", |
1283 "init_calls":"\n", |
1248 "cleanup_calls":"\n" |
1284 "cleanup_calls":"\n" |
1249 } |
1285 } |
1250 |
1286 |
1251 target_name = self.BeremizRoot.getTargetType().getcontent()["name"] |
1287 target = self.BeremizRoot.getTargetType() |
|
1288 if target.getcontent() is None: |
|
1289 target = self.GetDefaultTarget() |
|
1290 target_name = target.getcontent()["name"] |
1252 plc_main_code += targets.targetcode(target_name) |
1291 plc_main_code += targets.targetcode(target_name) |
1253 return plc_main_code |
1292 return plc_main_code |
1254 |
1293 |
1255 |
1294 |
1256 def _build(self): |
1295 def _build(self): |
1405 status = self._connector.GetPLCstatus() |
1444 status = self._connector.GetPLCstatus() |
1406 else: |
1445 else: |
1407 status = "Disconnected" |
1446 status = "Disconnected" |
1408 _ = lambda x : x |
1447 _ = lambda x : x |
1409 for args in { |
1448 for args in { |
|
1449 _("Starting"): [("_Run", True), |
|
1450 ("_Debug", True), |
|
1451 ("_Stop", False)], |
1410 _("Started"): [("_Run", False), |
1452 _("Started"): [("_Run", False), |
1411 ("_Debug", False), |
1453 ("_Debug", False), |
1412 ("_Stop", True)], |
1454 ("_Stop", True)], |
1413 _("Stopped"): [("_Run", True), |
1455 _("Stopped"): [("_Run", True), |
1414 ("_Debug", True), |
1456 ("_Debug", True), |
1573 elif debug_tick == -1: |
1615 elif debug_tick == -1: |
1574 #wx.CallAfter(self.logger.write, "Debugger unavailable\n") |
1616 #wx.CallAfter(self.logger.write, "Debugger unavailable\n") |
1575 pass |
1617 pass |
1576 else: |
1618 else: |
1577 wx.CallAfter(self.logger.write, _("Debugger disabled\n")) |
1619 wx.CallAfter(self.logger.write, _("Debugger disabled\n")) |
1578 self.debug_break = True |
1620 if self._connector.PLCIsStarting(): |
|
1621 time.sleep(0.01) |
|
1622 else: |
|
1623 self.debug_break = True |
1579 self.IECdebug_lock.release() |
1624 self.IECdebug_lock.release() |
1580 |
1625 |
1581 def KillDebugThread(self): |
1626 def KillDebugThread(self): |
1582 self.debug_break = True |
1627 self.debug_break = True |
1583 self.DebugThread.join(timeout=1) |
1628 self.DebugThread.join(timeout=1) |