39 |
39 |
40 #-------------------------------------------------- |
40 #-------------------------------------------------- |
41 # SLAVE |
41 # SLAVE |
42 #-------------------------------------------------- |
42 #-------------------------------------------------- |
43 |
43 |
44 class _SlavePlug(NodeManager): |
44 class _SlaveCTN(NodeManager): |
45 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
45 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
46 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
46 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
47 <xsd:element name="CanFestivalSlaveNode"> |
47 <xsd:element name="CanFestivalSlaveNode"> |
48 <xsd:complexType> |
48 <xsd:complexType> |
49 <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
49 <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
117 "name" : "Edit slave", |
117 "name" : "Edit slave", |
118 "tooltip" : "Edit CanOpen slave with ObjdictEdit", |
118 "tooltip" : "Edit CanOpen slave with ObjdictEdit", |
119 "method" : "_OpenView"}, |
119 "method" : "_OpenView"}, |
120 ] |
120 ] |
121 |
121 |
122 def OnPlugClose(self): |
122 def OnCTNClose(self): |
123 if self._View: |
123 if self._View: |
124 self._View.Close() |
124 self._View.Close() |
125 |
125 |
126 def PlugTestModified(self): |
126 def CTNTestModified(self): |
127 return self.ChangesToSave or self.OneFileHasChanged() |
127 return self.ChangesToSave or self.OneFileHasChanged() |
128 |
128 |
129 def OnPlugSave(self): |
129 def OnCTNSave(self): |
130 return self.SaveCurrentInFile(self.GetSlaveODPath()) |
130 return self.SaveCurrentInFile(self.GetSlaveODPath()) |
131 |
131 |
132 def SetParamsAttribute(self, path, value): |
132 def SetParamsAttribute(self, path, value): |
133 result = ConfigTreeNode.SetParamsAttribute(self, path, value) |
133 result = ConfigTreeNode.SetParamsAttribute(self, path, value) |
134 |
134 |
136 if path == "BaseParams.IEC_Channel" and self._View is not None: |
136 if path == "BaseParams.IEC_Channel" and self._View is not None: |
137 self._View.SetBusId(self.GetCurrentLocation()) |
137 self._View.SetBusId(self.GetCurrentLocation()) |
138 |
138 |
139 return result |
139 return result |
140 |
140 |
141 def PlugGenerate_C(self, buildpath, locations): |
141 def CTNGenerate_C(self, buildpath, locations): |
142 """ |
142 """ |
143 Generate C code |
143 Generate C code |
144 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
144 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
145 @param locations: List of complete variables locations \ |
145 @param locations: List of complete variables locations \ |
146 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
146 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
192 self.Fullname = fullname |
192 self.Fullname = fullname |
193 |
193 |
194 def OnCloseEditor(self, view): |
194 def OnCloseEditor(self, view): |
195 self.Parent.OnCloseEditor(view) |
195 self.Parent.OnCloseEditor(view) |
196 |
196 |
197 def PlugFullName(self): |
197 def CTNFullName(self): |
198 return self.Fullname |
198 return self.Fullname |
199 |
199 |
200 def GetBufferState(self): |
200 def GetBufferState(self): |
201 return self.GetCurrentBufferState() |
201 return self.GetCurrentBufferState() |
202 |
202 |
203 class _NodeListPlug(NodeList): |
203 class _NodeListCTN(NodeList): |
204 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
204 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
205 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
205 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
206 <xsd:element name="CanFestivalNode"> |
206 <xsd:element name="CanFestivalNode"> |
207 <xsd:complexType> |
207 <xsd:complexType> |
208 <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
208 <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/> |
217 EditorType = NetworkEditor |
217 EditorType = NetworkEditor |
218 |
218 |
219 def __init__(self): |
219 def __init__(self): |
220 manager = NodeManager() |
220 manager = NodeManager() |
221 NodeList.__init__(self, manager) |
221 NodeList.__init__(self, manager) |
222 self.LoadProject(self.PlugPath()) |
222 self.LoadProject(self.CTNPath()) |
223 self.SetNetworkName(self.BaseParams.getName()) |
223 self.SetNetworkName(self.BaseParams.getName()) |
224 |
224 |
225 def GetCanDevice(self): |
225 def GetCanDevice(self): |
226 return self.CanFestivalNode.getCan_Device() |
226 return self.CanFestivalNode.getCan_Device() |
227 |
227 |
245 def _ShowMasterGenerated(self): |
245 def _ShowMasterGenerated(self): |
246 if self._GeneratedView is None: |
246 if self._GeneratedView is None: |
247 buildpath = self._getBuildPath() |
247 buildpath = self._getBuildPath() |
248 # Eventually create build dir |
248 # Eventually create build dir |
249 if not os.path.exists(buildpath): |
249 if not os.path.exists(buildpath): |
250 self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n")) |
250 self.GetCTRoot().logger.write_error(_("Error: No PLC built\n")) |
251 return |
251 return |
252 |
252 |
253 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
253 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
254 if not os.path.exists(masterpath): |
254 if not os.path.exists(masterpath): |
255 self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n")) |
255 self.GetCTRoot().logger.write_error(_("Error: No Master generated\n")) |
256 return |
256 return |
257 |
257 |
258 app_frame = self.GetPlugRoot().AppFrame |
258 app_frame = self.GetCTRoot().AppFrame |
259 |
259 |
260 manager = MiniNodeManager(self, masterpath, self.PlugFullName() + ".generated_master") |
260 manager = MiniNodeManager(self, masterpath, self.CTNFullName() + ".generated_master") |
261 self._GeneratedView = SlaveEditor(app_frame.TabsOpened, manager, app_frame, False) |
261 self._GeneratedView = SlaveEditor(app_frame.TabsOpened, manager, app_frame, False) |
262 |
262 |
263 app_frame.EditProjectElement(self._GeneratedView, "MasterGenerated") |
263 app_frame.EditProjectElement(self._GeneratedView, "MasterGenerated") |
264 |
264 |
265 def _CloseGenerateView(self): |
265 def _CloseGenerateView(self): |
266 if self._GeneratedView is not None: |
266 if self._GeneratedView is not None: |
267 app_frame = self.GetPlugRoot().AppFrame |
267 app_frame = self.GetCTRoot().AppFrame |
268 if app_frame is not None: |
268 if app_frame is not None: |
269 app_frame.DeletePage(self._GeneratedView) |
269 app_frame.DeletePage(self._GeneratedView) |
270 |
270 |
271 ConfNodeMethods = [ |
271 ConfNodeMethods = [ |
272 {"bitmap" : os.path.join("images", "NetworkEdit"), |
272 {"bitmap" : os.path.join("images", "NetworkEdit"), |
282 def OnCloseEditor(self, view): |
282 def OnCloseEditor(self, view): |
283 ConfigTreeNode.OnCloseEditor(self, view) |
283 ConfigTreeNode.OnCloseEditor(self, view) |
284 if self._GeneratedView == view: |
284 if self._GeneratedView == view: |
285 self._GeneratedView = None |
285 self._GeneratedView = None |
286 |
286 |
287 def OnPlugClose(self): |
287 def OnCTNClose(self): |
288 ConfigTreeNode.OnPlugClose(self) |
288 ConfigTreeNode.OnCTNClose(self) |
289 self._CloseGenerateView() |
289 self._CloseGenerateView() |
290 return True |
290 return True |
291 |
291 |
292 def PlugTestModified(self): |
292 def CTNTestModified(self): |
293 return self.ChangesToSave or self.HasChanged() |
293 return self.ChangesToSave or self.HasChanged() |
294 |
294 |
295 def OnPlugSave(self): |
295 def OnCTNSave(self): |
296 self.SetRoot(self.PlugPath()) |
296 self.SetRoot(self.CTNPath()) |
297 return self.SaveProject() is None |
297 return self.SaveProject() is None |
298 |
298 |
299 def PlugGenerate_C(self, buildpath, locations): |
299 def CTNGenerate_C(self, buildpath, locations): |
300 """ |
300 """ |
301 Generate C code |
301 Generate C code |
302 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
302 @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
303 @param locations: List of complete variables locations \ |
303 @param locations: List of complete variables locations \ |
304 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
304 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
349 </xsd:complexType> |
349 </xsd:complexType> |
350 </xsd:element> |
350 </xsd:element> |
351 </xsd:schema> |
351 </xsd:schema> |
352 """ % DEFAULT_SETTINGS |
352 """ % DEFAULT_SETTINGS |
353 |
353 |
354 PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"), |
354 CTNChildrenTypes = [("CanOpenNode",_NodeListCTN, "CanOpen Master"), |
355 ("CanOpenSlave",_SlavePlug, "CanOpen Slave")] |
355 ("CanOpenSlave",_SlaveCTN, "CanOpen Slave")] |
356 def GetParamsAttributes(self, path = None): |
356 def GetParamsAttributes(self, path = None): |
357 infos = ConfigTreeNode.GetParamsAttributes(self, path = None) |
357 infos = ConfigTreeNode.GetParamsAttributes(self, path = None) |
358 for element in infos: |
358 for element in infos: |
359 if element["name"] == "CanFestivalInstance": |
359 if element["name"] == "CanFestivalInstance": |
360 for child in element["children"]: |
360 for child in element["children"]: |
371 can_driver += '_DEBUG.dll' |
371 can_driver += '_DEBUG.dll' |
372 else: |
372 else: |
373 can_driver += '.dll' |
373 can_driver += '.dll' |
374 return can_driver |
374 return can_driver |
375 |
375 |
376 def PlugGenerate_C(self, buildpath, locations): |
376 def CTNGenerate_C(self, buildpath, locations): |
377 |
377 |
378 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
378 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
379 "candriver" : self.GetCanDriver(), |
379 "candriver" : self.GetCanDriver(), |
380 "nodes_includes" : "", |
380 "nodes_includes" : "", |
381 "board_decls" : "", |
381 "board_decls" : "", |
388 "slavebootups" : "", |
388 "slavebootups" : "", |
389 "slavebootup_register" : "", |
389 "slavebootup_register" : "", |
390 "post_sync" : "", |
390 "post_sync" : "", |
391 "post_sync_register" : "", |
391 "post_sync_register" : "", |
392 } |
392 } |
393 for child in self.IECSortedChilds(): |
393 for child in self.IECSortedChildren(): |
394 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
394 childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
395 nodename = "OD_%s" % childlocstr |
395 nodename = "OD_%s" % childlocstr |
396 |
396 |
397 # Try to get Slave Node |
397 # Try to get Slave Node |
398 child_data = getattr(child, "CanFestivalSlaveNode", None) |
398 child_data = getattr(child, "CanFestivalSlaveNode", None) |