# HG changeset patch # User smarteh-dev # Date 1329429148 -3600 # Node ID bb340874f09e75d0025fdf0c3d077bbc15a8607a # Parent ef60d7e188e6f57fc6de1dbc503000208321cf55 Fix bug with "Transfer" button diff -r ef60d7e188e6 -r bb340874f09e LPCBeremiz.py --- a/LPCBeremiz.py Thu Feb 16 15:13:05 2012 +0100 +++ b/LPCBeremiz.py Thu Feb 16 22:52:28 2012 +0100 @@ -60,13 +60,20 @@ from Beremiz import * from plugger import PluginsRoot, PlugTemplate, opjimg, connectors -from plugins.canfestival import RootClass as CanOpenRootClass -from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager from plcopen.structures import LOCATIONDATATYPES from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY from PLCOpenEditor import IDEFrame, ProjectDialog +havecanfestival = False +try: + from plugins.canfestival import RootClass as CanOpenRootClass + from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager + havecanfestival = True +except: + havecanfestival = False + + #------------------------------------------------------------------------------- # CANFESTIVAL PLUGIN HACK #------------------------------------------------------------------------------- @@ -363,87 +370,89 @@ # LPC CanFestival Plugin Class #------------------------------------------------------------------------------- -DEFAULT_SETTINGS = { - "CAN_Baudrate": "125K", - "Slave_NodeId": 2, - "Master_NodeId": 1, -} - -class LPCCanOpenSlave(_SlavePlug): - XSD = """ - - - - - - - - - - - - - - - - - - """ % DEFAULT_SETTINGS - - def __init__(self): - # TODO change netname when name change - NodeManager.__init__(self) - odfilepath = self.GetSlaveODPath() - if(os.path.isfile(odfilepath)): - self.OpenFileInCurrent(odfilepath) - else: - self.CreateNewNode("SlaveNode", # Name - will be changed at build time - 0x00, # NodeID - will be changed at build time - "slave", # Type - "", # description - "None", # profile - "", # prfile filepath - "heartbeat", # NMT - []) # options - self.OnPlugSave() - - def GetCanDevice(self): - return str(self.BaseParams.getIEC_Channel()) - -class LPCCanOpenMaster(_NodeListPlug): - XSD = """ - - - - - - - - - - """ % DEFAULT_SETTINGS - - def GetCanDevice(self): - return str(self.BaseParams.getIEC_Channel()) - -class LPCCanOpen(CanOpenRootClass): - XSD = None - PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), - ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")] - - def GetCanDriver(self): - return "" - - def LoadChilds(self): - PlugTemplate.LoadChilds(self) - - if self.GetChildByName("Master") is None: - master = self.PlugAddChild("Master", "CanOpenNode", 0) - master.BaseParams.setEnabled(False) - - if self.GetChildByName("Slave") is None: - slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) - slave.BaseParams.setEnabled(False) +if havecanfestival: + + DEFAULT_SETTINGS = { + "CAN_Baudrate": "125K", + "Slave_NodeId": 2, + "Master_NodeId": 1, + } + + class LPCCanOpenSlave(_SlavePlug): + XSD = """ + + + + + + + + + + + + + + + + + + """ % DEFAULT_SETTINGS + + def __init__(self): + # TODO change netname when name change + NodeManager.__init__(self) + odfilepath = self.GetSlaveODPath() + if(os.path.isfile(odfilepath)): + self.OpenFileInCurrent(odfilepath) + else: + self.CreateNewNode("SlaveNode", # Name - will be changed at build time + 0x00, # NodeID - will be changed at build time + "slave", # Type + "", # description + "None", # profile + "", # prfile filepath + "heartbeat", # NMT + []) # options + self.OnPlugSave() + + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) + + class LPCCanOpenMaster(_NodeListPlug): + XSD = """ + + + + + + + + + + """ % DEFAULT_SETTINGS + + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) + + class LPCCanOpen(CanOpenRootClass): + XSD = None + PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"), + ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")] + + def GetCanDriver(self): + return "" + + def LoadChilds(self): + PlugTemplate.LoadChilds(self) + + if self.GetChildByName("Master") is None: + master = self.PlugAddChild("Master", "CanOpenNode", 0) + master.BaseParams.setEnabled(False) + + if self.GetChildByName("Slave") is None: + slave = self.PlugAddChild("Slave", "CanOpenSlave", 1) + slave.BaseParams.setEnabled(False) #------------------------------------------------------------------------------- @@ -503,7 +512,10 @@ PluginsRoot.__init__(self, frame, logger) - self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] + if havecanfestival: + self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")] + else: + self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")] self.PlugType = "LPC" self.OnlineMode = "OFF" @@ -682,7 +694,7 @@ #Load and init all the childs self.LoadChilds() - if self.GetChildByName("CanOpen") is None: + if havecanfestival and self.GetChildByName("CanOpen") is None: canopen = self.PlugAddChild("CanOpen", "CanOpen", 0) canopen.BaseParams.setEnabled(False) canopen.LoadChilds() @@ -900,7 +912,7 @@ def ResetBuildMD5(self): builder=self.GetBuilder() if builder is not None: - builder.ResetBinaryCodeMD5() + builder.ResetBinaryCodeMD5(self.OnlineMode) def GetLastBuildMD5(self): builder=self.GetBuilder() @@ -927,6 +939,9 @@ #self.StatusTimer.Stop() self.LPCConnector.ResetPLC() self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True) + + else: + self.CurrentMode = None def BeginTransfer(self): self.logger.write(_("Start PLC transfer\n")) @@ -1367,7 +1382,7 @@ new_properties["productVersion"] = productversion new_properties["companyName"] = companyname if new_properties != properties: - self.PluginRoot.SetProjectProperties(properties=new_properties) + self.PluginRoot.SetProjectProperties(properties=new_properties, buffer=False) self.RestartTimer() def SetOnlineMode(self, mode, path=None): diff -r ef60d7e188e6 -r bb340874f09e targets/LPC/__init__.py --- a/targets/LPC/__init__.py Thu Feb 16 15:13:05 2012 +0100 +++ b/targets/LPC/__init__.py Thu Feb 16 22:52:28 2012 +0100 @@ -40,6 +40,16 @@ except IOError, e: return None + def ResetBinaryCodeMD5(self, mode): + if mode == "BOOTLOADER": + self.binmd5key = None + try: + os.remove(self._GetBinMD5FileName()) + except Exception, e: + pass + else: + return toolchain_makefile.ResetBinaryCodeMD5(self) + def GetBinaryCodeMD5(self, mode): if mode == "BOOTLOADER": return self._get_cached_md5_header() @@ -48,16 +58,17 @@ def build(self): res = toolchain_makefile.build(self) - self.binmd5key = self._get_md5_header() - f = open(self._GetBinMD5FileName(), "w") - f.write(self.binmd5key) - f.close() - try: - self.PluginsRootInstance.logger.write( - _("Binary is %s bytes long\n")% - str(os.path.getsize( - os.path.join(self.buildpath, "ArmPLC_rom.bin")))) - except Exception, e: - pass + if res: + self.binmd5key = self._get_md5_header() + f = open(self._GetBinMD5FileName(), "w") + f.write(self.binmd5key) + f.close() + try: + self.PluginsRootInstance.logger.write( + _("Binary is %s bytes long\n")% + str(os.path.getsize( + os.path.join(self.buildpath, "ArmPLC_rom.bin")))) + except Exception, e: + pass return res diff -r ef60d7e188e6 -r bb340874f09e targets/toolchain_makefile.py --- a/targets/toolchain_makefile.py Thu Feb 16 15:13:05 2012 +0100 +++ b/targets/toolchain_makefile.py Thu Feb 16 22:52:28 2012 +0100 @@ -98,7 +98,8 @@ status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, command).spin() if status : - self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n")) + self.md5key = None + self.PluginsRootInstance.logger.write_error(_("C compilation failed.\n")) return False return True else :