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 LoadChilds(self): |
|
435 PlugTemplate.LoadChilds(self) |
|
436 |
|
437 if self.GetChildByName("Master") is None: |
|
438 master = self.PlugAddChild("Master", "CanOpenNode", 0) |
|
439 master.BaseParams.setEnabled(False) |
|
440 |
|
441 if self.GetChildByName("Slave") is None: |
|
442 slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) |
|
443 slave.BaseParams.setEnabled(False) |
|
444 |
|
445 |
|
446 #------------------------------------------------------------------------------- |
358 # LPCPluginsRoot Class |
447 # LPCPluginsRoot Class |
359 #------------------------------------------------------------------------------- |
448 #------------------------------------------------------------------------------- |
360 |
449 |
361 def mycopytree(src, dst): |
450 def mycopytree(src, dst): |
362 """ |
451 """ |
409 def __init__(self, frame, logger, buildpath): |
498 def __init__(self, frame, logger, buildpath): |
410 self.OrigBuildPath = buildpath |
499 self.OrigBuildPath = buildpath |
411 |
500 |
412 PluginsRoot.__init__(self, frame, logger) |
501 PluginsRoot.__init__(self, frame, logger) |
413 |
502 |
414 self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")] |
503 self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] |
415 self.PlugType = "LPC" |
504 self.PlugType = "LPC" |
416 |
505 |
417 self.OnlineMode = "OFF" |
506 self.OnlineMode = "OFF" |
418 self.LPCConnector = None |
507 self.LPCConnector = None |
419 |
508 |
798 # Check remote target PLC correspondance to that md5 |
892 # Check remote target PLC correspondance to that md5 |
799 if MD5 is not None and self.LPCConnector.MatchMD5(MD5): |
893 if MD5 is not None and self.LPCConnector.MatchMD5(MD5): |
800 # warns controller that program match |
894 # warns controller that program match |
801 self.ProgramTransferred() |
895 self.ProgramTransferred() |
802 |
896 |
|
897 def ResetBuildMD5(self): |
|
898 builder=self.GetBuilder() |
|
899 if builder is not None: |
|
900 builder.ResetBinaryCodeMD5() |
|
901 |
803 def GetLastBuildMD5(self): |
902 def GetLastBuildMD5(self): |
804 builder=self.GetBuilder() |
903 builder=self.GetBuilder() |
805 if builder is not None: |
904 if builder is not None: |
806 return builder.GetBinaryCodeMD5(self.OnlineMode) |
905 return builder.GetBinaryCodeMD5(self.OnlineMode) |
807 else: |
906 else: |
809 |
908 |
810 def _Transfer(self): |
909 def _Transfer(self): |
811 if self.CurrentMode is None and self.OnlineMode != "OFF": |
910 if self.CurrentMode is None and self.OnlineMode != "OFF": |
812 self.CurrentMode = TRANSFER_MODE |
911 self.CurrentMode = TRANSFER_MODE |
813 |
912 |
814 PluginsRoot._Build(self) |
913 if PluginsRoot._Build(self): |
815 |
914 |
816 ID_ABORTTRANSFERTIMER = wx.NewId() |
915 ID_ABORTTRANSFERTIMER = wx.NewId() |
817 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER) |
916 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER) |
818 self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer) |
917 self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer) |
819 |
918 |
820 if self.OnlineMode == "BOOTLOADER": |
919 if self.OnlineMode == "BOOTLOADER": |
821 self.BeginTransfer() |
920 self.BeginTransfer() |
822 |
921 |
823 else: |
922 else: |
824 self.logger.write(_("Resetting PLC\n")) |
923 self.logger.write(_("Resetting PLC\n")) |
825 #self.StatusTimer.Stop() |
924 #self.StatusTimer.Stop() |
826 self.LPCConnector.ResetPLC() |
925 self.LPCConnector.ResetPLC() |
827 self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True) |
926 self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True) |
828 |
927 |
829 def BeginTransfer(self): |
928 def BeginTransfer(self): |
830 self.logger.write(_("Start PLC transfer\n")) |
929 self.logger.write(_("Start PLC transfer\n")) |
831 |
930 |
832 self.AbortTransferTimer.Stop() |
931 self.AbortTransferTimer.Stop() |
1036 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1135 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1037 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1136 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1038 |
1137 |
1039 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1138 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1040 |
1139 |
|
1140 leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) |
|
1141 leftwindow.SetSizer(leftwindowvsizer) |
|
1142 |
1041 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1143 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1042 leftwindow.SetSizer(leftwindowsizer) |
1144 leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) |
1043 |
1145 |
|
1146 self.GenerateEnableButton(leftwindow, leftwindowsizer, plugin) |
|
1147 |
1044 st = wx.StaticText(leftwindow, -1) |
1148 st = wx.StaticText(leftwindow, -1) |
1045 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1149 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1046 st.SetLabel(plugin.GetFullIEC_Channel()) |
1150 st.SetLabel(plugin.GetFullIEC_Channel()) |
1047 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1151 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1048 |
1152 |
1098 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1202 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1099 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1203 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1100 st.SetLabel(plugin.MandatoryParams[1].getName()) |
1204 st.SetLabel(plugin.MandatoryParams[1].getName()) |
1101 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1205 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1102 |
1206 |
1103 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1207 rightwindow = self.GenerateParamsPanel(plugin, bkgdclr) |
1104 rightwindow.SetBackgroundColour(bkgdclr) |
|
1105 |
|
1106 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1208 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1107 |
1209 |
1108 self.PluginInfos[plugin]["left"] = leftwindow |
1210 self.PluginInfos[plugin]["left"] = leftwindow |
1109 self.PluginInfos[plugin]["right"] = rightwindow |
1211 self.PluginInfos[plugin]["right"] = rightwindow |
1110 for child in self.PluginInfos[plugin]["children"]: |
1212 for child in self.PluginInfos[plugin]["children"]: |