58 if __name__ == '__main__': |
58 if __name__ == '__main__': |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
60 |
60 |
61 from Beremiz import * |
61 from Beremiz import * |
62 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
62 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
|
63 from plugins.canfestival import RootClass as CanOpenRootClass |
|
64 from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager |
63 from plcopen.structures import LOCATIONDATATYPES |
65 from plcopen.structures import LOCATIONDATATYPES |
64 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
66 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
65 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
67 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
66 from PLCOpenEditor import IDEFrame, ProjectDialog |
68 from PLCOpenEditor import IDEFrame, ProjectDialog |
67 |
69 |
185 |
187 |
186 def __getitem__(self, key): |
188 def __getitem__(self, key): |
187 if key == "children": |
189 if key == "children": |
188 return self.VariableLocationTree |
190 return self.VariableLocationTree |
189 raise KeyError, "Only 'children' key is available" |
191 raise KeyError, "Only 'children' key is available" |
|
192 |
|
193 def PlugEnabled(self): |
|
194 return None |
190 |
195 |
191 def SetIcon(self, icon): |
196 def SetIcon(self, icon): |
192 self.Icon = icon |
197 self.Icon = icon |
193 |
198 |
194 def _GetChildBySomething(self, something, toks): |
199 def _GetChildBySomething(self, something, toks): |
353 |
358 |
354 matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) |
359 matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) |
355 return [(Gen_Module_path, matiec_flags)],"",True |
360 return [(Gen_Module_path, matiec_flags)],"",True |
356 |
361 |
357 #------------------------------------------------------------------------------- |
362 #------------------------------------------------------------------------------- |
|
363 # LPC CanFestival Plugin Class |
|
364 #------------------------------------------------------------------------------- |
|
365 |
|
366 DEFAULT_SETTINGS = { |
|
367 "CAN_Baudrate": "125K", |
|
368 "Slave_NodeId": 2, |
|
369 "Master_NodeId": 1, |
|
370 } |
|
371 |
|
372 class LPCCanOpenSlave(_SlavePlug): |
|
373 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
374 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
375 <xsd:element name="CanFestivalSlaveNode"> |
|
376 <xsd:complexType> |
|
377 <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> |
|
378 <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/> |
|
379 <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> |
|
380 <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50"> |
|
381 <xsd:simpleType> |
|
382 <xsd:restriction base="xsd:integer"> |
|
383 <xsd:minInclusive value="1"/> |
|
384 <xsd:maxInclusive value="99"/> |
|
385 </xsd:restriction> |
|
386 </xsd:simpleType> |
|
387 </xsd:attribute> |
|
388 </xsd:complexType> |
|
389 </xsd:element> |
|
390 </xsd:schema> |
|
391 """ % DEFAULT_SETTINGS |
|
392 |
|
393 def __init__(self): |
|
394 # TODO change netname when name change |
|
395 NodeManager.__init__(self) |
|
396 odfilepath = self.GetSlaveODPath() |
|
397 if(os.path.isfile(odfilepath)): |
|
398 self.OpenFileInCurrent(odfilepath) |
|
399 else: |
|
400 self.CreateNewNode("SlaveNode", # Name - will be changed at build time |
|
401 0x00, # NodeID - will be changed at build time |
|
402 "slave", # Type |
|
403 "", # description |
|
404 "None", # profile |
|
405 "", # prfile filepath |
|
406 "heartbeat", # NMT |
|
407 []) # options |
|
408 self.OnPlugSave() |
|
409 |
|
410 def GetCanDevice(self): |
|
411 return str(self.BaseParams.getIEC_Channel()) |
|
412 |
|
413 class LPCCanOpenMaster(_NodeListPlug): |
|
414 XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
415 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
416 <xsd:element name="CanFestivalNode"> |
|
417 <xsd:complexType> |
|
418 <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/> |
|
419 <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/> |
|
420 <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/> |
|
421 </xsd:complexType> |
|
422 </xsd:element> |
|
423 </xsd:schema> |
|
424 """ % DEFAULT_SETTINGS |
|
425 |
|
426 def GetCanDevice(self): |
|
427 return str(self.BaseParams.getIEC_Channel()) |
|
428 |
|
429 class LPCCanOpen(CanOpenRootClass): |
|
430 XSD = None |
|
431 PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), |
|
432 ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")] |
|
433 |
|
434 def GetCanDriver(self): |
|
435 return "" |
|
436 |
|
437 def LoadChilds(self): |
|
438 PlugTemplate.LoadChilds(self) |
|
439 |
|
440 if self.GetChildByName("Master") is None: |
|
441 master = self.PlugAddChild("Master", "CanOpenNode", 0) |
|
442 master.BaseParams.setEnabled(False) |
|
443 |
|
444 if self.GetChildByName("Slave") is None: |
|
445 slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) |
|
446 slave.BaseParams.setEnabled(False) |
|
447 |
|
448 |
|
449 #------------------------------------------------------------------------------- |
358 # LPCPluginsRoot Class |
450 # LPCPluginsRoot Class |
359 #------------------------------------------------------------------------------- |
451 #------------------------------------------------------------------------------- |
360 |
452 |
361 def mycopytree(src, dst): |
453 def mycopytree(src, dst): |
362 """ |
454 """ |
409 def __init__(self, frame, logger, buildpath): |
501 def __init__(self, frame, logger, buildpath): |
410 self.OrigBuildPath = buildpath |
502 self.OrigBuildPath = buildpath |
411 |
503 |
412 PluginsRoot.__init__(self, frame, logger) |
504 PluginsRoot.__init__(self, frame, logger) |
413 |
505 |
414 self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")] |
506 self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] |
415 self.PlugType = "LPC" |
507 self.PlugType = "LPC" |
416 |
508 |
417 self.OnlineMode = "OFF" |
509 self.OnlineMode = "OFF" |
418 self.LPCConnector = None |
510 self.LPCConnector = None |
419 |
511 |
1041 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1138 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1042 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1139 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1043 |
1140 |
1044 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1141 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1045 |
1142 |
|
1143 leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) |
|
1144 leftwindow.SetSizer(leftwindowvsizer) |
|
1145 |
1046 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1146 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1047 leftwindow.SetSizer(leftwindowsizer) |
1147 leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) |
1048 |
1148 |
|
1149 self.GenerateEnableButton(leftwindow, leftwindowsizer, plugin) |
|
1150 |
1049 st = wx.StaticText(leftwindow, -1) |
1151 st = wx.StaticText(leftwindow, -1) |
1050 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1152 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1051 st.SetLabel(plugin.GetFullIEC_Channel()) |
1153 st.SetLabel(plugin.GetFullIEC_Channel()) |
1052 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1154 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1053 |
1155 |
1103 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1205 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1104 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1206 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1105 st.SetLabel(plugin.MandatoryParams[1].getName()) |
1207 st.SetLabel(plugin.MandatoryParams[1].getName()) |
1106 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1208 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1107 |
1209 |
1108 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1210 rightwindow = self.GenerateParamsPanel(plugin, bkgdclr) |
1109 rightwindow.SetBackgroundColour(bkgdclr) |
|
1110 |
|
1111 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1211 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1112 |
1212 |
1113 self.PluginInfos[plugin]["left"] = leftwindow |
1213 self.PluginInfos[plugin]["left"] = leftwindow |
1114 self.PluginInfos[plugin]["right"] = rightwindow |
1214 self.PluginInfos[plugin]["right"] = rightwindow |
1115 for child in self.PluginInfos[plugin]["children"]: |
1215 for child in self.PluginInfos[plugin]["children"]: |