# HG changeset patch
# User laurent
# Date 1328195367 -3600
# Node ID 607731b33026c80543c9ea83945fe0d5b3d06e71
# Parent 04cd443cd18df868d6cdd75f33eead2914d4eed5
Fix 'Transfer" button state according to last build result
diff -r 04cd443cd18d -r 607731b33026 LPCBeremiz.py
--- a/LPCBeremiz.py Thu Feb 02 00:28:27 2012 +0100
+++ b/LPCBeremiz.py Thu Feb 02 16:09:27 2012 +0100
@@ -60,6 +60,8 @@
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
@@ -188,6 +190,9 @@
return self.VariableLocationTree
raise KeyError, "Only 'children' key is available"
+ def PlugEnabled(self):
+ return None
+
def SetIcon(self, icon):
self.Icon = icon
@@ -355,6 +360,90 @@
return [(Gen_Module_path, matiec_flags)],"",True
#-------------------------------------------------------------------------------
+# 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 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)
+
+
+#-------------------------------------------------------------------------------
# LPCPluginsRoot Class
#-------------------------------------------------------------------------------
@@ -411,7 +500,7 @@
PluginsRoot.__init__(self, frame, logger)
- self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
+ self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
self.PlugType = "LPC"
self.OnlineMode = "OFF"
@@ -590,6 +679,11 @@
#Load and init all the childs
self.LoadChilds()
+ if self.GetChildByName("CanOpen") is None:
+ canopen = self.PlugAddChild("CanOpen", "CanOpen", 0)
+ canopen.BaseParams.setEnabled(False)
+ canopen.LoadChilds()
+
if self.PlugTestModified():
self.SaveProject()
@@ -800,6 +894,11 @@
# warns controller that program match
self.ProgramTransferred()
+ def ResetBuildMD5(self):
+ builder=self.GetBuilder()
+ if builder is not None:
+ builder.ResetBinaryCodeMD5()
+
def GetLastBuildMD5(self):
builder=self.GetBuilder()
if builder is not None:
@@ -811,20 +910,20 @@
if self.CurrentMode is None and self.OnlineMode != "OFF":
self.CurrentMode = TRANSFER_MODE
- PluginsRoot._Build(self)
-
- ID_ABORTTRANSFERTIMER = wx.NewId()
- self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
- self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)
-
- if self.OnlineMode == "BOOTLOADER":
- self.BeginTransfer()
-
- else:
- self.logger.write(_("Resetting PLC\n"))
- #self.StatusTimer.Stop()
- self.LPCConnector.ResetPLC()
- self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
+ if PluginsRoot._Build(self):
+
+ ID_ABORTTRANSFERTIMER = wx.NewId()
+ self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
+ self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)
+
+ if self.OnlineMode == "BOOTLOADER":
+ self.BeginTransfer()
+
+ else:
+ self.logger.write(_("Resetting PLC\n"))
+ #self.StatusTimer.Stop()
+ self.LPCConnector.ResetPLC()
+ self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
def BeginTransfer(self):
self.logger.write(_("Start PLC transfer\n"))
@@ -1038,9 +1137,14 @@
self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
+ leftwindowvsizer = wx.BoxSizer(wx.VERTICAL)
+ leftwindow.SetSizer(leftwindowvsizer)
+
leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
- leftwindow.SetSizer(leftwindowsizer)
-
+ leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0)
+
+ self.GenerateEnableButton(leftwindow, leftwindowsizer, plugin)
+
st = wx.StaticText(leftwindow, -1)
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
st.SetLabel(plugin.GetFullIEC_Channel())
@@ -1100,9 +1204,7 @@
st.SetLabel(plugin.MandatoryParams[1].getName())
leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
- rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
- rightwindow.SetBackgroundColour(bkgdclr)
-
+ rightwindow = self.GenerateParamsPanel(plugin, bkgdclr)
self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
self.PluginInfos[plugin]["left"] = leftwindow
diff -r 04cd443cd18d -r 607731b33026 plugger.py
--- a/plugger.py Thu Feb 02 00:28:27 2012 +0100
+++ b/plugger.py Thu Feb 02 16:09:27 2012 +0100
@@ -1260,6 +1260,12 @@
self._builder = targetclass(self)
return self._builder
+ def ResetBuildMD5(self):
+ builder=self.GetBuilder()
+ if builder is not None:
+ builder.ResetBinaryCodeMD5()
+ self.EnableMethod("_Transfer", False)
+
def GetLastBuildMD5(self):
builder=self.GetBuilder()
if builder is not None:
@@ -1467,7 +1473,7 @@
# If IEC code gen fail, bail out.
if not IECGenRes:
self.logger.write_error(_("IEC-61131-3 code generation failed !\n"))
- self.EnableMethod("_Transfer", False)
+ self.ResetBuildMD5()
return False
# Reset variable and program list that are parsed from
@@ -1483,7 +1489,7 @@
except Exception, exc:
self.logger.write_error(_("Plugins code generation failed !\n"))
self.logger.write_error(traceback.format_exc())
- self.EnableMethod("_Transfer", False)
+ self.ResetBuildMD5()
return False
# Get temporary directory path
@@ -1519,7 +1525,7 @@
except Exception, exc:
self.logger.write_error(name+_(" generation failed !\n"))
self.logger.write_error(traceback.format_exc())
- self.EnableMethod("_Transfer", False)
+ self.ResetBuildMD5()
return False
self.logger.write(_("C code generated successfully.\n"))
@@ -1528,7 +1534,7 @@
builder = self.GetBuilder()
if builder is None:
self.logger.write_error(_("Fatal : cannot get builder.\n"))
- self.EnableMethod("_Transfer", False)
+ self.ResetBuildMD5()
return False
# Build
@@ -1539,7 +1545,7 @@
except Exception, exc:
self.logger.write_error(_("C Build crashed !\n"))
self.logger.write_error(traceback.format_exc())
- self.EnableMethod("_Transfer", False)
+ self.ResetBuildMD5()
return False
self.logger.write(_("Successfully built.\n"))
diff -r 04cd443cd18d -r 607731b33026 targets/toolchain_gcc.py
--- a/targets/toolchain_gcc.py Thu Feb 02 00:28:27 2012 +0100
+++ b/targets/toolchain_gcc.py Thu Feb 02 16:09:27 2012 +0100
@@ -37,6 +37,13 @@
def _GetMD5FileName(self):
return os.path.join(self.buildpath, "lastbuildPLC.md5")
+ def ResetBinaryCodeMD5(self):
+ self.md5key = None
+ try:
+ os.remove(self._GetMD5FileName())
+ except Exception, e:
+ pass
+
def GetBinaryCodeMD5(self):
if self.md5key is not None:
return self.md5key
@@ -150,18 +157,18 @@
if status :
return False
- else :
- # Calculate md5 key and get data for the new created PLC
- data=self.GetBinaryCode()
- self.md5key = hashlib.md5(data).hexdigest()
-
- # Store new PLC filename based on md5 key
- f = open(self._GetMD5FileName(), "w")
- f.write(self.md5key)
- f.close()
+
else:
self.PluginsRootInstance.logger.write(" [pass] " + ' '.join(obns)+" -> " + self.exe + "\n")
-
+
+ # Calculate md5 key and get data for the new created PLC
+ data=self.GetBinaryCode()
+ self.md5key = hashlib.md5(data).hexdigest()
+
+ # Store new PLC filename based on md5 key
+ f = open(self._GetMD5FileName(), "w")
+ f.write(self.md5key)
+ f.close()
return True
diff -r 04cd443cd18d -r 607731b33026 targets/toolchain_makefile.py
--- a/targets/toolchain_makefile.py Thu Feb 02 00:28:27 2012 +0100
+++ b/targets/toolchain_makefile.py Thu Feb 02 16:09:27 2012 +0100
@@ -24,6 +24,13 @@
def _GetMD5FileName(self):
return os.path.join(self.buildpath, "lastbuildPLC.md5")
+ def ResetBinaryCodeMD5(self):
+ self.md5key = None
+ try:
+ os.remove(self._GetMD5FileName())
+ except Exception, e:
+ pass
+
def GetBinaryCodeMD5(self):
if self.md5key is not None:
return self.md5key