--- a/LPCManager.py Mon Jul 18 11:15:51 2016 +0200
+++ b/LPCManager.py Mon Jul 18 15:01:36 2016 +0200
@@ -15,33 +15,29 @@
sys.path.append(_beremiz_folder)
- return os.path.join(CWD, *args)
+ return os.path.join(CWD,*args) if __name__ == '__main__':
print "\nUsage of LPCManager.py :"
- print "\n %s Projectpath Buildpath port [arch]\n" % sys.argv[0]
+ print "\n %s Projectpath Buildpath port [arch]\n"%sys.argv[0] opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.GetoptError:
# print help information and exit:
if o in ("-h", "--help"):
if len(args) < 3 or len(args) > 4:
@@ -57,8 +53,8 @@
- PLC_module = {'MC9', 'GOT'}
__builtin__.__dict__["BMZ_DBG"] = os.path.exists("LPC_DEBUG")
app = wx.PySimpleApp(redirect=BMZ_DBG)
@@ -66,97 +62,87 @@
wx.InitAllImageHandlers()
from util.misc import InstallLocalRessources
InstallLocalRessources(_beremiz_folder)
_lpcmanager_path = os.path.split(__file__)[0]
from POULibrary import POULibrary
-class PLCLibraryLPC(POULibrary):
+class PLCLibrary(POULibrary): def GetLibraryPath(self):
- return os.path.join(_lpcmanager_path + '/Pous/', "pousLPC.xml")
-class PLCLibraryGOT(POULibrary):
- def GetLibraryPath(self):
- return os.path.join(_lpcmanager_path + '/Pous/', "pousGOT.xml")
+ return os.path.join(_lpcmanager_path, "pous.xml") ('Native', 'NativeLib.NativeLibrary'),
- ('LPC', lambda: PLCLibraryLPC)]
-features.libraries += [('GOT', lambda: PLCLibraryGOT),('Python', 'py_ext.PythonLibrary')]
+ ('LPC', lambda: PLCLibrary), + ('Python', 'py_ext.PythonLibrary')] -features.catalog.pop([i for i, x in enumerate(features.catalog) if x[0].startswith('svg')][0])
+features.catalog.pop([i for i,x in enumerate(features.catalog) if x[0].startswith('svg')][0]) from LPCconnector import LPC_connector_factory
-connectors.connectors["LPC"] = lambda: LPC_connector_factory
+connectors.connectors["LPC"]=lambda:LPC_connector_factory -from LPCtarget import LPC_target
+from LPCtarget import LPC_target targets.targets["LPC"] = {"xsd": os.path.join(_lpcmanager_path, "LPCtarget", "XSD"),
"class": lambda: LPC_target,
- "code": {os.path.join(_lpcmanager_path, "LPCtarget", "plc_LPC_main.c")}}
+ "code": {os.path.join(_lpcmanager_path,"LPCtarget","plc_LPC_main.c")}} targets.toolchains["makefile"] = os.path.join(_lpcmanager_path, "LPCtarget", "XSD_toolchain_makefile")
targets.targets["MC9"] = {"xsd": os.path.join(_lpcmanager_path, "MC9target", "XSD"),
"class": targets.targets["Xenomai"]["class"],
- "code": {"plc_MC9_main.c": targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"],
- "plc_MC9_main_retain.c": os.path.join(_lpcmanager_path,
- "MC9target", "plc_MC9_main_retain.c")}}
+ "code": {"plc_MC9_main.c":targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"], + "plc_MC9_main_retain.c":os.path.join(_lpcmanager_path, + "MC9target", "plc_MC9_main_retain.c")}} from ProjectController import ProjectController
from ConfigTreeNode import ConfigTreeNode
from editors.ProjectNodeEditor import ProjectNodeEditor
-from PLCControler import PLCControler, LOCATION_MODULE, LOCATION_GROUP, \
- LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
+from PLCControler import PLCControler, LOCATION_MODULE, LOCATION_GROUP,\ + LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY from IDEFrame import IDEFrame
from dialogs import ProjectDialog
from controls import TextCtrlAutoComplete
from canfestival import RootClass as CanOpenRootClass
from canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
from canfestival.NetworkEditor import NetworkEditor
from canfestival.SlaveEditor import SlaveEditor
# havecanfestival = False
-WINDOW_COLOUR = wx.Colour(240, 240, 240)
-TITLE_COLOUR = wx.Colour(200, 200, 220)
-CHANGED_TITLE_COLOUR = wx.Colour(220, 200, 220)
-CHANGED_WINDOW_COLOUR = wx.Colour(255, 240, 240)
+WINDOW_COLOUR = wx.Colour(240,240,240) +TITLE_COLOUR = wx.Colour(200,200,220) +CHANGED_TITLE_COLOUR = wx.Colour(220,200,220) +CHANGED_WINDOW_COLOUR = wx.Colour(255,240,240) if wx.Platform == '__WXMSW__':
- faces = {'times': 'Times New Roman',
- 'other': 'Comic Sans MS',
+ faces = { 'times': 'Times New Roman', + 'mono' : 'Courier New', + 'other': 'Comic Sans MS', - faces = {'times': 'Times',
- 'other': 'new century schoolbook',
+ faces = { 'times': 'Times', + 'other': 'new century schoolbook', from editors.ConfTreeNodeEditor import GenBitmapTextButton
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
-# ConfTreeNodeEditor.SHOW_BASE_PARAMS = False
+#ConfTreeNodeEditor.SHOW_BASE_PARAMS = False -# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- # CANFESTIVAL CONFNODE HACK
-# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- # from canfestival import canfestival
# class LPC_canfestival_config:
# def getCFLAGS(self, *args):
@@ -168,33 +154,27 @@
# canfestival.local_canfestival_config = LPC_canfestival_config()
import LPCBus as LPCBus_mod
- LPCBus_mod.LPCarch = "MC9"
- LPCBus_mod.LPCarch = arch
+LPCBus_mod.LPCarch = arch -# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- # LPC CanFestival ConfNode Class
-# -------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
-class LPCSlaveEditor(SlaveEditor):
- # SHOW_BASE_PARAMS = False
-class LPCCanOpenSlave(_SlaveCTN):
- XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
+ class LPCSlaveEditor(SlaveEditor): + #SHOW_BASE_PARAMS = False + class LPCCanOpenSlave(_SlaveCTN): + XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CanFestivalSlaveNode">
@@ -213,44 +193,42 @@
- EditorType = LPCSlaveEditor
- # TODO change netname when name change
- NodeManager.__init__(self)
- odfilepath = self.GetSlaveODPath()
- if (os.path.isfile(odfilepath)):
- self.OpenFileInCurrent(odfilepath)
- self.CreateNewNode("SlaveNode", # Name - will be changed at build time
- 0x00, # NodeID - will be changed at build time
- def GetCanDevice(self):
- return str(self.BaseParams.getIEC_Channel())
- {"bitmap": "NetworkEdit",
- "name": _("Edit slave"),
- "tooltip": _("Edit CanOpen slave with ObjdictEdit"),
- "method": "_OpenView"},
- ] + _SlaveCTN.ConfNodeMethods
-class LPCNetworkEditor(NetworkEditor):
- # SHOW_BASE_PARAMS = False
-class LPCCanOpenMaster(_NodeListCTN):
- XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
+ EditorType = LPCSlaveEditor + # TODO change netname when name change + NodeManager.__init__(self) + odfilepath = self.GetSlaveODPath() + if(os.path.isfile(odfilepath)): + self.OpenFileInCurrent(odfilepath) + self.CreateNewNode("SlaveNode", # Name - will be changed at build time + 0x00, # NodeID - will be changed at build time + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) + {"bitmap" : "NetworkEdit", + "name" : _("Edit slave"), + "tooltip" : _("Edit CanOpen slave with ObjdictEdit"), + "method" : "_OpenView"}, + ] + _SlaveCTN.ConfNodeMethods + class LPCNetworkEditor(NetworkEditor): + #SHOW_BASE_PARAMS = False + class LPCCanOpenMaster(_NodeListCTN): + XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CanFestivalNode">
@@ -261,45 +239,43 @@
- EditorType = LPCNetworkEditor
- def GetCanDevice(self):
- return str(self.BaseParams.getIEC_Channel())
- {"bitmap": "NetworkEdit",
- "name": _("Edit network"),
- "tooltip": _("Edit CanOpen Network with NetworkEdit"),
- "method": "_OpenView"},
- ] + _NodeListCTN.ConfNodeMethods
-class LPCCanOpen(CanOpenRootClass):
- CTNChildrenTypes = [("CanOpenNode", LPCCanOpenMaster, "CanOpen Master"),
- ("CanOpenSlave", LPCCanOpenSlave, "CanOpen Slave")]
+ EditorType = LPCNetworkEditor + def GetCanDevice(self): + return str(self.BaseParams.getIEC_Channel()) + {"bitmap" : "NetworkEdit", + "name" : _("Edit network"), + "tooltip" : _("Edit CanOpen Network with NetworkEdit"), + "method" : "_OpenView"}, + ] + _NodeListCTN.ConfNodeMethods + class LPCCanOpen(CanOpenRootClass): + CTNChildrenTypes = [("CanOpenNode", LPCCanOpenMaster, "CanOpen Master"), + ("CanOpenSlave", LPCCanOpenSlave, "CanOpen Slave")] + def GetCanDriver(self): + def LoadChildren(self): + ConfigTreeNode.LoadChildren(self) + if self.GetChildByName("Master") is None: + master = self.CTNAddChild("Master", "CanOpenNode", 0) + #master.BaseParams.setEnabled(False) + master.CTNRequestSave() + if self.GetChildByName("Slave") is None: + slave = self.CTNAddChild("Slave", "CanOpenSlave", 1) + #slave.BaseParams.setEnabled(False) - def GetCanDriver(self):
- def LoadChildren(self):
- ConfigTreeNode.LoadChildren(self)
- if self.GetChildByName("Master") is None:
- master = self.CTNAddChild("Master", "CanOpenNode", 0)
- # master.BaseParams.setEnabled(False)
- master.CTNRequestSave()
- if self.GetChildByName("Slave") is None:
- slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
- # slave.BaseParams.setEnabled(False)
-# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- # LPCProjectController Class
-# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- def mycopytree(src, dst):
@@ -309,8 +285,8 @@
for i in os.listdir(src):
if not i.startswith('.'):
- srcpath = os.path.join(src, i)
- dstpath = os.path.join(dst, i)
+ srcpath = os.path.join(src,i) + dstpath = os.path.join(dst,i) if os.path.isdir(srcpath):
if os.path.exists(dstpath):
@@ -319,10 +295,9 @@
elif os.path.isfile(srcpath):
shutil.copy2(srcpath, dstpath)
[SIMULATION_MODE, TRANSFER_MODE] = range(2)
class LPCProjectNodeEditor(ProjectNodeEditor):
@@ -330,76 +305,77 @@
- "tooltip": _("Simulate PLC"),
- "method": "_Simulate"},
- "tooltip": _("Start PLC"),
- "tooltip": _("Stop Running PLC"),
- "tooltip": _("Build project into build folder"),
- "tooltip": _("Clean project build folder"),
- "tooltip": _("Transfer PLC"),
- "method": "_Transfer"},
+ "name" : _("Simulate"), + "tooltip" : _("Simulate PLC"), + "method" : "_Simulate"}, + "tooltip" : _("Start PLC"), + "tooltip" : _("Stop Running PLC"), + "tooltip" : _("Build project into build folder"), + "tooltip" : _("Clean project build folder"), + {"bitmap" : "Transfer", + "name" : _("Transfer"), + "tooltip" : _("Transfer PLC"), + "method" : "_Transfer"}, - "Started": [("_Simulate", False),
- "Stopped": [("_Simulate", False),
- "Connected": [("_Simulate", "not simulating"),
- ("_Stop", True if arch in PLC_module else "simulating"),
- "Disconnected": [("_Simulate", "not simulating"),
- ("_Stop", True if arch in PLC_module else "simulating"),
+ "Started" : [("_Simulate", False), + "Stopped" : [("_Simulate", False), + "Connected" : [("_Simulate", "not simulating"), + ("_Stop", True if arch=="MC9" else "simulating"), + "Disconnected" :[("_Simulate", "not simulating"), + ("_Stop", True if arch=="MC9" else "simulating"),
- "tooltip": _("Connect to the target PLC"),
- {"bitmap": "Disconnect",
- "name": _("Disconnect"),
- "tooltip": _("Disconnect from PLC"),
- "method": "_Disconnect"},
- "tooltip": _("Update the PLC firmware"),
- "method": "_UpdateFw"},
+ "tooltip" : _("Connect to the target PLC"), + "method" : "_Connect"}, + {"bitmap" : "Disconnect", + "name" : _("Disconnect"), + "tooltip" : _("Disconnect from PLC"), + "method" : "_Disconnect"}, + {"bitmap" : "UpdateFw", + "name" : _("UpdateFw"), + "tooltip" : _("Update the PLC firmware"), + "method" : "_UpdateFw"}, _MethodFromPLCState["Disconnected"] += [("_Connect", True),
@@ -407,38 +383,37 @@
_MethodFromPLCState["Connected"] += [("_Connect", False),
class LPCProjectController(ProjectController):
StatusMethods = _StatusMethods
EditorType = LPCProjectNodeEditor
def __init__(self, frame, logger, buildpath):
self.OrigBuildPath = buildpath
ProjectController.__init__(self, frame, logger)
self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
- self.OnlineMode = "NORMAL" if arch in PLC_module else "OFF"
+ self.OnlineMode = "NORMAL" if arch=="MC9" else "OFF" self.ConnectorPath = None
self.previous_mode = None
self.SimulationBuildPath = None
self.AbortTransferTimer = None
# Firmware update running status
self.firmawreUpadateIsRunning = False
def GetProjectName(self):
return self.Project.getname()
@@ -450,10 +425,10 @@
target = ProjectController.GetTarget(self)
- if self.CurrentMode != SIMULATION_MODE and arch not in PLC_module:
+ if self.CurrentMode != SIMULATION_MODE and arch != "MC9": target.getcontent().setBuildPath(self.BuildPath)
if self.CurrentMode == SIMULATION_MODE:
if self.SimulationBuildPath is None:
@@ -472,7 +447,7 @@
ProjectController._Build(self)
wx.CallAfter(self.AppFrame.RefreshAll)
def SetProjectName(self, name):
return self.Project.setname(name)
@@ -482,77 +457,77 @@
if mode not in ["OFF", ""]:
self.ConnectorPath = path
- uri = "LPC://%s/%s" % (self.OnlineMode, path)
+ uri = "LPC://%s/%s" % (self.OnlineMode,path) self.LPCConnector = connectors.ConnectorFactory(uri, self)
- self.logger.write_error(_("Exception while connecting %s!\n") % uri)
+ self.logger.write_error(_("Exception while connecting %s!\n")%uri) self.logger.write_error(traceback.format_exc())
# Did connection success ?
if self.LPCConnector is None:
- self.logger.write_error(_("Connection failed to %s!\n") % uri)
+ self.logger.write_error(_("Connection failed to %s!\n")%uri) self.ConnectorPath = None
- SetOnlineMode = lambda *x: None if arch in PLC_module else _SetOnlineMode
+ SetOnlineMode = lambda *x:None if arch=="MC9" else _SetOnlineMode def ApplyOnlineMode(self):
if self.CurrentMode != SIMULATION_MODE:
self._SetConnector(self.LPCConnector)
# Init with actual PLC status and print it
self.UpdateMethodsFromPLCStatus()
if self.LPCConnector is not None and self.OnlineMode == "APPLICATION":
self.CompareLocalAndRemotePLC()
if self.previous_plcstate is not None:
status = _(self.previous_plcstate)
- self.logger.write(_("PLC is %s\n") % status)
- # if self.StatusTimer and not self.StatusTimer.IsRunning():
+ self.logger.write(_("PLC is %s\n")%status) + #if self.StatusTimer and not self.StatusTimer.IsRunning(): # # Start the status Timer
# self.StatusTimer.Start(milliseconds=2000, oneShot=False)
- if self.previous_plcstate == "Started":
+ if self.previous_plcstate=="Started": if self.DebugAvailable() and self.GetIECProgramsAndVariables():
self.logger.write(_("Debug connect matching running PLC\n"))
self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n"))
elif self.StatusTimer and self.StatusTimer.IsRunning():
if self.CurrentMode == TRANSFER_MODE:
if self.OnlineMode == "BOOTLOADER":
elif self.OnlineMode == "APPLICATION":
self.AbortTransferTimer.Stop()
self.AbortTransferTimer = None
self.logger.write(_("PLC transferred successfully\n"))
# Update a PLCOpenEditor Pou variable location
def UpdateProjectVariableLocation(self, old_leading, new_leading):
self.Project.updateElementAddress(old_leading, new_leading)
# Update a PLCOpenEditor Pou variable name
def UpdateProjectVariableName(self, old_name, new_name):
self.Project.updateElementName(old_name, new_name)
@@ -568,15 +543,15 @@
def AddProjectDefaultConfiguration(self, config_name="config", res_name="resource1"):
ProjectController.AddProjectDefaultConfiguration(self, config_name, res_name)
self.SetEditedResourceInfos(
- self.ComputeConfigurationResourceName(config_name, res_name),
- "Triggering": "Cyclic",
+ self.ComputeConfigurationResourceName(config_name, res_name), + "Triggering": "Cyclic", def LoadProject(self, ProjectPath, BuildPath=None):
Load a project contained in a folder
@@ -584,7 +559,7 @@
if os.path.basename(ProjectPath) == "":
ProjectPath = os.path.dirname(ProjectPath)
# Verify that project contains a PLCOpen program
plc_file = os.path.join(ProjectPath, "plc.xml")
if os.path.isfile(plc_file):
@@ -601,63 +576,60 @@
if len(self.GetProjectConfigNames()) == 0:
self.AddProjectDefaultConfiguration()
# Change XSD into class members
# Keep track of the root confnode (i.e. project path)
self.ProjectPath = ProjectPath
self.BuildPath = self._getBuildPath()
if self.OrigBuildPath is not None:
mycopytree(self.OrigBuildPath, self.BuildPath)
# If dir have already be made, and file exist
if os.path.isdir(self.CTNPath()) and os.path.isfile(self.ConfNodeXmlFilePath()):
- # Load the confnode.xml file into parameters members
+ #Load the confnode.xml file into parameters members result = self.LoadXMLParams()
- # Load and init all the children
+ #Load and init all the children
canopen_child = self.GetChildByName("CanOpen")
if havecanfestival and canopen_child is None:
canopen = self.CTNAddChild("CanOpen", "CanOpen", 0)
elif not havecanfestival and canopen_child is not None:
canopen_child.CTNRemove()
if self.CTNTestModified():
self.RefreshConfNodesBlockLists()
wx.CallAfter(self.RefreshConfNodesBlockLists)
- self.SetParamsAttribute('BeremizRoot.TargetType', 'MC9')
return self.previous_plcstate == "Started" or self.previous_mode == SIMULATION_MODE
def ShowMethod(self, name, val):
simulating = self.CurrentMode == SIMULATION_MODE
if val.endswith("simulating"):
if val.startswith("not"):
ProjectController.ShowMethod(self, name, val)
def UpdateMethodsFromPLCStatus(self):
simulating = self.CurrentMode == SIMULATION_MODE
if self.OnlineMode == "OFF":
@@ -677,7 +649,7 @@
if self.previous_plcstate != status or self.previous_mode != self.CurrentMode:
- for args in _MethodFromPLCState.get(status, []):
+ for args in _MethodFromPLCState.get(status,[]): self.previous_plcstate = status
self.previous_mode = self.CurrentMode
@@ -805,28 +777,28 @@
self._SetConnector(connectors.ConnectorFactory(uri, self))
- self.logger.write_error(_("Exception while connecting %s!\n") % uri)
+ self.logger.write_error(_("Exception while connecting %s!\n")%uri) self.logger.write_error(traceback.format_exc())
# Did connection success ?
if self._connector is None:
- self.logger.write_error(_("Connection failed to %s!\n") % uri)
+ self.logger.write_error(_("Connection failed to %s!\n")%uri)
self.CurrentMode = SIMULATION_MODE
buildpath = self._getBuildPath()
# Eventually create build dir
if not os.path.exists(buildpath):
# Generate SoftPLC IEC code
IECGenRes = self._Generate_SoftPLC()
- # If IEC code gen fail, bail out.
+ # If IEC code gen fail, bail out. self.logger.write_error(_("IEC-61131-3 code generation failed !\n"))
@@ -835,7 +807,7 @@
# Reset variable and program list that are parsed from
# CSV file generated by IEC2C compiler.
self.ResetIECProgramsAndVariables()
gen_result = self.CTNGenerate_C(buildpath, self.PLCGeneratedLocatedVars)
CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
# if some files have been generated put them in the list with their location
@@ -847,43 +819,43 @@
# confnode asks for some LDFLAGS
# LDFLAGS can be either string
- if type(CTNLDFLAGS) == type(str()):
- self.LDFLAGS = [CTNLDFLAGS]
- elif type(CTNLDFLAGS) == type(list()):
- self.LDFLAGS = CTNLDFLAGS[:]
+ if type(CTNLDFLAGS)==type(str()): + self.LDFLAGS=[CTNLDFLAGS] + elif type(CTNLDFLAGS)==type(list()): + self.LDFLAGS=CTNLDFLAGS[:]
# Header file for extensions
- open(os.path.join(buildpath, "beremiz.h"), "w").write(targets.GetHeader())
+ open(os.path.join(buildpath,"beremiz.h"), "w").write(targets.GetHeader()) # Template based part of C code generation
# files are stacked at the beginning, as files of confnode tree root
for generator, filename, name in [
- (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
- # init/cleanup/retrieve/publish, run and align code
- (self.Generate_plc_main, "plc_main.c", "Common runtime"),
- # declare located variables for simulate in a black box
- (self.Generate_plc_declare_locations, "plc_declare_locations.c", "Declare Locations"),
- # declare located variables for simulate in a black box
- (self.Generate_lpc_retain_array_sim, "lpc_retain_array_sim.c", "Retain Array for Simulation")]:
+ (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"), + # init/cleanup/retrieve/publish, run and align code + (self.Generate_plc_main,"plc_main.c","Common runtime"), + # declare located variables for simulate in a black box + (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations"), + # declare located variables for simulate in a black box + (self.Generate_lpc_retain_array_sim,"lpc_retain_array_sim.c","Retain Array for Simulation")]:
- code_path = os.path.join(buildpath, filename)
+ code_path = os.path.join(buildpath,filename) open(code_path, "w").write(code)
# Insert this file as first file to be compiled at root confnode
- self.LocationCFilesAndCFLAGS[0][1].insert(0, (code_path, self.plcCFLAGS))
+ self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS)) - self.logger.write_error(name + _(" generation failed !\n"))
+ self.logger.write_error(name+_(" generation failed !\n")) self.logger.write_error(traceback.format_exc())
builder = self.GetBuilder()
@@ -893,7 +865,7 @@
- if not builder.build():
+ if not builder.build() : self.logger.write_error(_("C Build failed.\n"))
@@ -904,7 +876,7 @@
data = builder.GetBinaryCode()
if self._connector.NewPLC(builder.GetBinaryCodeMD5(), data, []):
self.UnsubscribeAllDebugIECVariable()
self.ProgramTransferred()
@@ -916,21 +888,21 @@
self.logger.write_error(_("Transfer failed\n"))
if not self.StatusTimer.IsRunning():
self.StatusTimer.Start(milliseconds=500, oneShot=False)
def StopSimulation(self):
self._SetConnector(None, False)
ProjectController._Stop(self)
if self.CurrentMode == SIMULATION_MODE:
@@ -945,24 +917,22 @@
self.ProgramTransferred()
- builder = self.GetBuilder()
+ builder=self.GetBuilder() - builder.ResetBinaryCodeMD5(*([] if arch in PLC_module else [self.OnlineMode]))
+ builder.ResetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode])) def GetLastBuildMD5(self):
- builder = self.GetBuilder()
+ builder=self.GetBuilder() - return builder.GetBinaryCodeMD5(*([] if arch in PLC_module else [self.OnlineMode]))
+ return builder.GetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode])) self._CloseView(self._IECCodeView)
- if os.path.isdir(os.path.join(self._getBuildPath())) and os.path.isfile(
- os.path.join(self._getBuildPath(), "hmi.py")) and os.path.isfile(
- os.path.join(self._getBuildPath(), "runtime_2.py")):
+ if os.path.isdir(os.path.join(self._getBuildPath())) and os.path.isfile(os.path.join(self._getBuildPath(), "hmi.py")) and os.path.isfile(os.path.join(self._getBuildPath(), "runtime_2.py")): self.logger.write(_("Cleaning the build directory\n"))
- # self.logger.write(_(str(os.path.join(self._getBuildPath(), "hmi.py"))))
+ #self.logger.write(_(str(os.path.join(self._getBuildPath(), "hmi.py")))) os.remove(os.path.join(self._getBuildPath(), "hmi.py"))
os.remove(os.path.join(self._getBuildPath(), "runtime_2.py"))
@@ -976,38 +946,38 @@
if self.OnlineMode == "NORMAL":
ProjectController._Transfer(self)
if self.CurrentMode is None and self.OnlineMode != "OFF":
self.CurrentMode = TRANSFER_MODE
if ProjectController._Build(self):
ID_ABORTTRANSFERTIMER = wx.NewId()
self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
- self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)
+ self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer) if self.OnlineMode == "BOOTLOADER":
self.logger.write(_("Resetting PLC\n"))
- # self.StatusTimer.Stop()
+ #self.StatusTimer.Stop() self.LPCConnector.ResetPLC()
self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
self.logger.write(_("Start PLC transfer\n"))
self.AbortTransferTimer.Stop()
ProjectController._Transfer(self)
self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
def AbortTransfer(self, event):
self.logger.write_warning(_("Timeout waiting PLC to recover\n"))
self.AbortTransferTimer.Stop()
self.AbortTransferTimer = None
@@ -1060,7 +1030,7 @@
self.firmawreUpadateIsRunning = False
- self.logger.write(_("Firmware image file: %s\n") % imageFilePath)
+ self.logger.write(_("Firmware image file: %s\n")%imageFilePath) self.logger.write(_("Firmware update type: Linux kernel image\n"))
@@ -1074,20 +1044,20 @@
self.firmawreUpadateIsRunning = False
- if chunksSize < 1024 or chunksSize > 1024 * 1024:
- self.logger.write_error(_("Bad chunks size : %d KiB!\n") % chunksSize)
+ if chunksSize < 1024 or chunksSize > 1024*1024: + self.logger.write_error(_("Bad chunks size : %d KiB!\n")%chunksSize) self.logger.write_error(_("Firmware update canceled!\n"))
self.firmawreUpadateIsRunning = False
- self.logger.write(_("Chunks size : %d KiB\n") % chunksSize)
+ self.logger.write(_("Chunks size : %d KiB\n")%chunksSize) - self.logger.write(_("Reboot after update : %s\n") % ("Yes" if reboot else "No"))
+ self.logger.write(_("Reboot after update : %s\n")%("Yes" if reboot else "No")) # Check if an uri is already configured in the Beremiz project
uri = self.BeremizRoot.getURI_location()
if uri is not None and uri != "":
- self.logger.write(_("PLC URI configured in the Beremiz project will be used: %s\n") % uri)
+ self.logger.write(_("PLC URI configured in the Beremiz project will be used: %s\n")%uri) # PLC URI is not configured in the Beremiz project
# Launch Service Discovery dialog
@@ -1109,7 +1079,7 @@
self._SetConnector(connectors.ConnectorFactory(uri, self))
- self.logger.write_error(_("Exception while connecting %s!\n") % uri)
+ self.logger.write_error(_("Exception while connecting %s!\n")%uri) self.logger.write_error(traceback.format_exc())
self.logger.write_error(_("Firmware update canceled!\n"))
self.firmawreUpadateIsRunning = False
@@ -1118,7 +1088,7 @@
# Did connection success ?
if self._connector is None:
- self.logger.write_error(_("Connection failed to %s!\n") % uri)
+ self.logger.write_error(_("Connection failed to %s!\n")%uri) self.logger.write_error(_("Firmware update canceled!\n"))
self.firmawreUpadateIsRunning = False
@@ -1126,9 +1096,9 @@
self.logger.write(_("Connected.\n"))
# Last confirmation before firmware update
- answer = wx.MessageBox(_('Are you sure to launch the firmware update for the selected PLC?'),
- _('Firmware Update'), wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT,
+ answer = wx.MessageBox(_('Are you sure to launch the firmware update for the selected PLC?'), + _('Firmware Update'), wx.YES_NO | wx.CENTRE |wx.NO_DEFAULT, self.logger.write_error(_("Firmware update canceled!\n"))
self.firmawreUpadateIsRunning = False
@@ -1151,92 +1121,91 @@
self.firmawreUpadateIsRunning = False
-# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- -# -------------------------------------------------------------------------------
+#------------------------------------------------------------------------------- class LPCBeremiz(Beremiz):
def _init_coll_FileMenu_Items(self, parent):
AppendMenu(parent, help='', id=wx.ID_SAVE,
- kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
+ kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) AppendMenu(parent, help='', id=wx.ID_CLOSE,
- kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
+ kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W')) AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
- kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
+ kind=wx.ITEM_NORMAL, text=_(u'Page Setup')) AppendMenu(parent, help='', id=wx.ID_PREVIEW,
- kind=wx.ITEM_NORMAL, text=_(u'Preview'))
+ kind=wx.ITEM_NORMAL, text=_(u'Preview')) AppendMenu(parent, help='', id=wx.ID_PRINT,
- kind=wx.ITEM_NORMAL, text=_(u'Print'))
+ kind=wx.ITEM_NORMAL, text=_(u'Print')) AppendMenu(parent, help='', id=wx.ID_EXIT,
- kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
+ kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
self.AddToMenuToolBar([(wx.ID_SAVE, "save", _(u'Save'), None),
(wx.ID_PRINT, "print", _(u'Print'), None)])
def _init_ctrls(self, prnt):
Beremiz._init_ctrls(self, prnt)
self.PLCConfig = wx.ScrolledWindow(
- name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
- size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER | wx.HSCROLL | wx.VSCROLL)
+ name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0), + size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) self.PLCConfig.SetBackgroundColour(wx.WHITE)
self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
self.MainTabs["PLCConfig"] = (self.PLCConfig, _("Topology"))
self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2)
self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL)
self.ConfNodeTreeSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=0, vgap=2)
self.ConfNodeTreeSizer.AddGrowableCol(0)
- self.PLCConfigMainSizer.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)
- self.PLCConfigMainSizer.AddSizer(self.ConfNodeTreeSizer, 0, border=10, flag=wx.BOTTOM | wx.LEFT | wx.RIGHT)
+ self.PLCConfigMainSizer.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) + self.PLCConfigMainSizer.AddSizer(self.ConfNodeTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) self.PLCConfigMainSizer.AddGrowableCol(0)
self.PLCConfigMainSizer.AddGrowableRow(1)
self.PLCConfig.SetSizer(self.PLCConfigMainSizer)
def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True):
Beremiz.__init__(self, parent, projectOpen, buildpath, ctr, debug)
def OnCloseFrame(self, event):
if self.CheckSaveBeforeClosing(_("Close Application")):
self.CTR.ResetAppFrame(lpcberemiz_cmd.Log)
if self.CTR.OnlineMode == 0:
self.CTR._SetConnector(None, False)
self.CTR.KillDebugThread()
lpcberemiz_cmd.Log.write("Closed\n")
def OnMoveWindow(self, event):
@@ -1285,7 +1254,7 @@
MenuToolBar.EnableTool(wx.ID_PRINT, False)
self.FileMenu.Enable(wx.ID_SAVE, False)
MenuToolBar.EnableTool(wx.ID_SAVE, False)
def RefreshScrollBars(self):
xstart, ystart = self.PLCConfig.GetViewStart()
window_size = self.PLCConfig.GetClientSize()
@@ -1295,76 +1264,70 @@
posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
self.PLCConfig.Scroll(posx, posy)
- self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
- maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
+ self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, + maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) def RefreshPLCParams(self):
self.ClearSizer(self.PLCParamsSizer)
- if self.CTR is not None:
+ if self.CTR is not None: plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
if self.CTR.CTNTestModified():
bkgdclr = CHANGED_TITLE_COLOUR
plcwindow.SetBackgroundColour(TITLE_COLOUR)
plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
plcwindow.SetSizer(plcwindowsizer)
st = wx.StaticText(plcwindow, -1)
- st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName=faces["helv"]))
+ st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) st.SetLabel(self.CTR.GetProjectName())
- plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL | wx.ALIGN_CENTER)
+ plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow)
plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
self.PLCConfigMainSizer.Layout()
def GenerateMethodButtonSizer(self, confnode, parent):
- normal_bt_font = wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName=faces["helv"])
- mouseover_bt_font = wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True,
- faceName=faces["helv"])
+ normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) + mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) msizer = wx.FlexGridSizer(cols=len(confnode.ConfNodeMethods))
for confnode_method in confnode.ConfNodeMethods:
- if "method" in confnode_method and confnode_method.get("shown", True):
+ if "method" in confnode_method and confnode_method.get("shown",True): label = confnode_method["name"]
button = GenBitmapTextButton(id=id, parent=parent,
- Bpath("images", "%s.png" % confnode_method.get("bitmap", "Unknown"))),
- name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
+ bitmap=wx.Bitmap(Bpath("images", "%s.png"%confnode_method.get("bitmap", "Unknown"))), label=label, + name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) button.SetFont(normal_bt_font)
button.SetToolTipString(confnode_method["tooltip"])
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode, confnode_method["method"]), id=id)
# a fancy underline on mouseover
button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font))
button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font))
- # hack to force size to mini
- if not confnode_method.get("enabled", True):
+ #hack to force size to mini + if not confnode_method.get("enabled",True): msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER)
@@ -1373,23 +1336,18 @@
enabled = confnode.CTNEnabled()
enablebutton_id = wx.NewId()
- enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id,
- bitmap=wx.Bitmap(Bpath('images', 'Disabled.png')),
- name='EnableButton', parent=parent,
- size=wx.Size(16, 16), pos=wx.Point(0, 0),
- style=0) # wx.NO_BORDER)
+ enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')), + name='EnableButton', parent=parent, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER) enablebutton.SetToolTipString(_("Enable/Disable this confnode"))
make_genbitmaptogglebutton_flat(enablebutton)
- enablebutton.SetBitmapSelected(wx.Bitmap(Bpath('images', 'Enabled.png')))
+ enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png'))) enablebutton.SetToggle(enabled)
def toggleenablebutton(event):
res = self.SetConfNodeParamsAttribute(confnode, "BaseParams.Enabled", enablebutton.GetToggle())
enablebutton.SetToggle(res)
enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id)
- sizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ sizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) sizer.AddSpacer(wx.Size(16, 16))
@@ -1408,54 +1366,52 @@
def GenerateTreeBranch(self, confnode):
nodewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
if confnode.CTNTestModified():
- bkgdclr = CHANGED_WINDOW_COLOUR
+ bkgdclr=CHANGED_WINDOW_COLOUR - bkgdclr = WINDOW_COLOUR
nodewindow.SetBackgroundColour(bkgdclr)
if confnode not in self.ConfNodeInfos:
- self.ConfNodeInfos[confnode] = {"expanded": False, "visible": False}
+ self.ConfNodeInfos[confnode] = {"expanded" : False, "visible" : False} self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren()
confnode_infos = confnode.GetVariableLocationTree()
if len(self.ConfNodeInfos[confnode]["children"]) == 0:
confnode_locations = confnode_infos["children"]
if not self.ConfNodeInfos[confnode].has_key("locations_infos"):
- self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded": False}}
+ self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded" : False}} self.ConfNodeInfos[confnode]["locations_infos"]["root"]["window"] = None
self.ConfNodeInfos[confnode]["locations_infos"]["root"]["children"] = []
self.ConfNodeTreeSizer.AddWindow(nodewindow, 0, border=0, flag=wx.GROW)
nodewindowvsizer = wx.BoxSizer(wx.VERTICAL)
nodewindow.SetSizer(nodewindowvsizer)
nodewindowsizer = wx.BoxSizer(wx.HORIZONTAL)
nodewindowvsizer.AddSizer(nodewindowsizer, 0, border=0, flag=0)
- # self.GenerateEnableButton(nodewindow, nodewindowsizer, confnode)
+ #self.GenerateEnableButton(nodewindow, nodewindowsizer, confnode) st = wx.StaticText(nodewindow, -1)
- st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName=faces["helv"]))
+ st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) st.SetLabel(confnode.GetFullIEC_Channel())
- nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) expandbutton_id = wx.NewId()
- expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id,
- bitmap=wx.Bitmap(Bpath('images', 'plus.png')),
- name='ExpandButton', parent=nodewindow, pos=wx.Point(0, 0),
- size=wx.Size(13, 13), style=wx.NO_BORDER)
+ expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), + name='ExpandButton', parent=nodewindow, pos=wx.Point(0, 0), + size=wx.Size(13, 13), style=wx.NO_BORDER) expandbutton.labelDelta = 0
expandbutton.SetBezelWidth(0)
expandbutton.SetUseFocusIndicator(False)
- expandbutton.SetBitmapSelected(wx.Bitmap(Bpath('images', 'minus.png')))
+ expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png'))) if len(self.ConfNodeInfos[confnode]["children"]) > 0:
expandbutton.SetToggle(self.ConfNodeInfos[confnode]["expanded"])
if expandbutton.GetToggle():
self.ExpandConfNode(confnode)
@@ -1465,12 +1421,10 @@
self.PLCConfigMainSizer.Layout()
expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
elif len(confnode_locations) > 0:
locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
expandbutton.SetToggle(locations_infos["root"]["expanded"])
if expandbutton.GetToggle():
self.ExpandLocation(locations_infos, "root")
@@ -1481,49 +1435,47 @@
self.PLCConfigMainSizer.Layout()
expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
expandbutton.Enable(False)
- nodewindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ nodewindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) sb = wx.StaticBitmap(nodewindow, -1)
icon = confnode_infos.get("icon", None)
icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[confnode_infos["type"]])
icon_bitmap = wx.Bitmap(icon)
sb.SetBitmap(icon_bitmap)
- nodewindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ nodewindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) st = wx.StaticText(nodewindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
- st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName=faces["helv"]))
+ st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) st.SetLabel(confnode.MandatoryParams[1].getName())
- nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
+ nodewindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) buttons_sizer = self.GenerateMethodButtonSizer(confnode, nodewindow)
nodewindowsizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER_VERTICAL)
self.ConfNodeInfos[confnode]["window"] = nodewindow
for child in self.ConfNodeInfos[confnode]["children"]:
self.GenerateTreeBranch(child)
if not self.ConfNodeInfos[child]["expanded"]:
self.CollapseConfNode(child)
if len(confnode_locations) > 0:
locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
- treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize,
- style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.NO_BORDER | wx.TR_HIDE_ROOT | wx.TR_NO_LINES | wx.TR_LINES_AT_ROOT)
+ treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, + style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) treectrl.SetImageList(self.LocationImageList)
treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos))
treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True))
- treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED,
- self.GenerateLocationExpandCollapseFunction(locations_infos, False))
+ treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0)
locations_infos["root"]["window"] = treectrl
for location in confnode_locations:
locations_infos["root"]["children"].append("root.%s" % location["name"])
@@ -1531,7 +1483,7 @@
if locations_infos["root"]["expanded"]:
self.ExpandLocation(locations_infos, "root")
- def ExpandConfNode(self, confnode, force=False):
+ def ExpandConfNode(self, confnode, force = False): for child in self.ConfNodeInfos[confnode]["children"]:
self.ConfNodeInfos[child]["window"].Show()
if force or self.ConfNodeInfos[child]["expanded"]:
@@ -1544,8 +1496,8 @@
self.ExpandLocation(locations_infos, "root", force)
locations_infos["root"]["expanded"] = True
- def CollapseConfNode(self, confnode, force=False):
+ def CollapseConfNode(self, confnode, force = False): for child in self.ConfNodeInfos[confnode]["children"]:
self.ConfNodeInfos[child]["window"].Hide()
self.CollapseConfNode(child, force)
@@ -1557,7 +1509,7 @@
locations_infos["root"]["expanded"] = False
- def ExpandLocation(self, locations_infos, group, force=False, refresh_size=True):
+ def ExpandLocation(self, locations_infos, group, force = False, refresh_size=True): locations_infos[group]["expanded"] = True
if locations_infos[group]["window"] is not None:
@@ -1569,8 +1521,8 @@
self.ExpandLocation(locations_infos, child, force, False)
if locations_infos["root"]["window"] is not None and refresh_size:
self.RefreshTreeCtrlSize(locations_infos["root"]["window"])
- def CollapseLocation(self, locations_infos, group, force=False, refresh_size=True):
+ def CollapseLocation(self, locations_infos, group, force = False, refresh_size=True): locations_infos[group]["expanded"] = False
if locations_infos[group]["window"] is not None:
@@ -1586,8 +1538,8 @@
def GenerateLocationTreeBranch(self, treectrl, root, locations_infos, parent, location):
location_name = "%s.%s" % (parent, location["name"])
if not locations_infos.has_key(location_name):
- locations_infos[location_name] = {"expanded": False}
+ locations_infos[location_name] = {"expanded" : False} if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
label = "%(name)s (%(location)s)" % location
elif location["location"] != "":
@@ -1597,7 +1549,7 @@
item = treectrl.AppendItem(root, label)
treectrl.SetPyData(item, location_name)
treectrl.SetItemImage(item, self.LocationImageDict[location["type"]])
locations_infos[location_name]["item"] = item
locations_infos[location_name]["children"] = []
@@ -1609,7 +1561,7 @@
self.GenerateLocationTreeBranch(treectrl, item, locations_infos, location_name, child)
if locations_infos[location_name]["expanded"]:
self.ExpandLocation(locations_infos, location_name)
def GenerateLocationBeginDragFunction(self, locations_infos):
def OnLocationBeginDragFunction(event):
@@ -1617,14 +1569,12 @@
if location_name is not None:
infos = locations_infos[location_name]["infos"]
if infos["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
- data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["var_name"],
- infos["description"])))
+ data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["var_name"], infos["description"]))) dragSource = wx.DropSource(self)
return OnLocationBeginDragFunction
def RefreshTreeCtrlSize(self, treectrl):
rect = self.GetTreeCtrlItemRect(treectrl, treectrl.GetRootItem())
treectrl.SetMinSize(wx.Size(max(rect.width, rect.x + rect.width) + 20, max(rect.height, rect.y + rect.height)))
@@ -1639,7 +1589,7 @@
maxx, maxy = item_rect.x + item_rect.width, item_rect.y + item_rect.height
minx = miny = maxx = maxy = 0
if treectrl.ItemHasChildren(item) and (item == treectrl.GetRootItem() or treectrl.IsExpanded(item)):
if wx.VERSION >= (2, 6, 0):
child, item_cookie = treectrl.GetFirstChild(item)
@@ -1652,9 +1602,9 @@
maxx = max(maxx, child_rect.x + child_rect.width)
maxy = max(maxy, child_rect.y + child_rect.height)
child, item_cookie = treectrl.GetNextChild(item, item_cookie)
return wx.Rect(minx, miny, maxx - minx, maxy - miny)
def GenerateLocationExpandCollapseFunction(self, locations_infos, expand):
def OnLocationExpandedFunction(event):
@@ -1663,25 +1613,22 @@
locations_infos[location_name]["expanded"] = expand
self.RefreshTreeCtrlSize(locations_infos["root"]["window"])
return OnLocationExpandedFunction
def GetButtonCallBackFunction(self, confnode, method):
""" Generate the callbackfunc for a given confnode method"""
def OnButtonClick(event):
# Disable button to prevent re-entrant call
event.GetEventObject().Disable()
- getattr(confnode, method)()
+ getattr(confnode,method)() event.GetEventObject().Enable()
# Trigger refresh on Idle
wx.CallAfter(self.RefreshAll)
def ClearSizer(self, sizer):
for item in sizer.GetChildren():
@@ -1693,26 +1640,26 @@
for staticbox in staticboxes:
self.RefreshConfNodeTree()
# Remove taskbar icon when simulating
- def StartLocalRuntime(self, taskbaricon=True):
- return Beremiz.StartLocalRuntime(self, taskbaricon=False)
+ def StartLocalRuntime(self, taskbaricon = True): + return Beremiz.StartLocalRuntime(self, taskbaricon = False) def __init__(self, port):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(('localhost', port))
idx = self.Buffer.find("\n")
@@ -1722,19 +1669,18 @@
idx = self.Buffer.find("\n")
- line = self.Buffer[:idx + 1]
- self.Buffer = self.Buffer[idx + 1:]
+ line = self.Buffer[:idx+1] + self.Buffer = self.Buffer[idx+1:] - print "command >" + line
""" Base class for file like objects to facilitate StdOut for the Shell."""
- def write(self, s, style=None):
+ def write(self, s, style = None): self.socket.send(s.encode('utf8'))
@@ -1746,68 +1692,62 @@
if __name__ == '__main__':
from threading import Thread, Timer, Semaphore
wx_eval_lock = Semaphore(0)
def wx_evaluator(callable, *args, **kwargs):
- eval_res = callable(*args, **kwargs)
+ eval_res=callable(*args,**kwargs)
def evaluator(callable, *args, **kwargs):
- wx.CallAfter(wx_evaluator, callable, *args, **kwargs)
+ wx.CallAfter(wx_evaluator,callable,*args,**kwargs)
# Command log for debug, for viewing from wxInspector
class LPCBeremiz_Cmd(cmd.Cmd):
def __init__(self, CTR, Log):
cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
self.use_rawinput = False
self.restore_last_state = False
if self.RefreshTimer is not None:
self.RefreshTimer.cancel()
- self.RefreshTimer = Timer(0.1, wx.CallAfter, args=[self.Refresh])
+ self.RefreshTimer = Timer(0.1, wx.CallAfter, args = [self.Refresh]) self.RefreshTimer.start()
@@ -1817,7 +1757,7 @@
self.restore_last_state = True
@@ -1828,17 +1768,17 @@
frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
self.CTR.ResetAppFrame(self.Log)
def SetProjectProperties(self, projectname, productname, productversion, companyname):
"projectName": projectname,
@@ -1847,11 +1787,11 @@
"companyName": companyname}
self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
def SetOnlineMode(self, mode, path=None):
self.CTR.SetOnlineMode(mode, path)
def AddBus(self, iec_channel, name, icon=None):
for child in self.CTR.IterChildren():
if child.BaseParams.getName() == name:
@@ -1863,7 +1803,7 @@
return "Error: Unable to create bus\n"
def RenameBus(self, iec_channel, name):
bus = self.CTR.GetChildByIECLocation((iec_channel,))
@@ -1873,7 +1813,7 @@
return "Error: A bus named %s already exists\n" % name
bus.BaseParams.setName(name)
def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
@@ -1882,15 +1822,15 @@
if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
- self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
+ self.CTR.UpdateProjectVariableLocation(str(old_iec_channel), self.CTR.UpdateProjectVariableLocation(
bus.BaseParams.setIEC_Channel(new_iec_channel)
def RemoveBus(self, iec_channel):
bus = self.CTR.GetChildByIECLocation((iec_channel,))
@@ -1898,7 +1838,7 @@
self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
self.CTR.Children["LPCBus"].remove(bus)
def AddModule(self, parent, iec_channel, name, icode, icon=None):
module = self.CTR.GetChildByIECLocation(parent)
@@ -1907,15 +1847,15 @@
if child["name"] == name:
return "Error: A module named %s already exists\n" % name
elif child["IEC_Channel"] == iec_channel:
- return "Error: A module with IEC_channel %d already exists\n" % iec_channel
- GetLastModuleGroup(module).append({"name": name,
- "type": LOCATION_MODULE,
- "IEC_Channel": iec_channel,
+ return "Error: A module with IEC_channel %d already exists\n" % iec_channel + GetLastModuleGroup(module).append({"name": name, + "type": LOCATION_MODULE, + "IEC_Channel": iec_channel,
def RenameModule(self, iec_location, name):
module = self.CTR.GetChildByIECLocation(iec_location)
@@ -1929,7 +1869,7 @@
return "Error: A module named %s already exists\n" % name
def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
module = self.CTR.GetChildByIECLocation(old_iec_location)
@@ -1941,17 +1881,16 @@
for child in GetModuleChildren(parent):
if child["IEC_Channel"] == new_iec_channel:
return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
- self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)),
- ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
+ self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) module["IEC_Channel"] = new_iec_channel
def ChangeModuleInitCode(self, iec_location, icode):
module = self.CTR.GetChildByIECLocation(iec_location)
return "Error: No module found\n"
def RemoveModule(self, parent, iec_channel):
module = self.CTR.GetChildByIECLocation(parent)
@@ -1962,7 +1901,7 @@
self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
RemoveModuleChild(module, child)
def StartGroup(self, parent, name, icon=None):
module = self.CTR.GetChildByIECLocation(parent)
@@ -1970,12 +1909,12 @@
for child in module["children"]:
if child["type"] == LOCATION_GROUP and child["name"] == name:
return "Error: A group named %s already exists\n" % name
- module["children"].append({"name": name,
- "type": LOCATION_GROUP,
+ module["children"].append({"name": name, + "type": LOCATION_GROUP,
def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
module = self.CTR.GetChildByIECLocation(parent)
@@ -1985,17 +1924,16 @@
return "Error: A variable named %s already exists\n" % name
if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
- GetLastModuleGroup(module).append({"name": name,
- "type": LOCATION_TYPES[direction],
- "description": description,
+ GetLastModuleGroup(module).append({"name": name, + "type": LOCATION_TYPES[direction], + "description": description, - def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode,
+ def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None): module = self.CTR.GetChildByIECLocation(parent)
return "Error: No parent found\n"
@@ -2017,7 +1955,7 @@
if new_description is not None:
variable["description"] = new_description
def RemoveVariable(self, parent, location, direction):
module = self.CTR.GetChildByIECLocation(parent)
@@ -2030,15 +1968,12 @@
self.CTR.RemoveProjectVariableByAddress(address)
RemoveModuleChild(module, child)
return tuple(map(int, loc.split(".")))
def GetCmdFunction(function, arg_types, opt=0):
arg_number = len(arg_types)
def CmdFunction(self, line):
args_toks = line.split('"')
if len(args_toks) % 2 == 0:
@@ -2081,22 +2016,20 @@
func = getattr(self, function)
- res = evaluator(func, *args)
+ res = evaluator(func,*args) - cmdlog.append((function, line, res))
- if len(cmdlog) > 100: # prevent debug log to grow too much
+ cmdlog.append((function,line,res)) + if len(cmdlog) > 100: #prevent debug log to grow too much if isinstance(res, (StringType, UnicodeType)):
def CmdThreadProc(CTR, Log):
for function, (arg_types, opt) in {"Exit": ([], 0),
@@ -2110,26 +2043,25 @@
"RenameBus": ([int, str], 0),
"ChangeBusIECChannel": ([int, int], 0),
- "AddModule": ([location, int, str, str, str], 1),
+ "AddModule": ([location, int, str, str, str], 1), "RenameModule": ([location, str], 0),
"ChangeModuleIECChannel": ([location, int], 0),
"ChangeModuleInitCode": ([location, str], 0),
"RemoveModule": ([location, int], 0),
"StartGroup": ([location, str, str], 1),
"AddVariable": ([location, location, str, str, str, str, str, str], 1),
- "ChangeVariableParams": (
- [location, location, str, str, str, str, str, str], 1),
+ "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1), "RemoveVariable": ([location, location], 0)}.iteritems():
setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
Log = StdoutPseudoFile(port)
if projectOpen is not None:
projectOpen = DecodeFileSystemPath(projectOpen, False)
CTR = LPCProjectController(None, Log, buildpath)
if projectOpen is not None and os.path.isdir(projectOpen):
result = CTR.LoadProject(projectOpen)
@@ -2137,13 +2069,14 @@
Log.write("Error: Invalid project directory", result)
Log.write("Error: No such file or directory")
- cmd_thread = Thread(target=CmdThreadProc, args=[CTR, Log])
+ cmd_thread=Thread(target=CmdThreadProc, args=[CTR, Log]) # Install a exception handle for bug reports
- AddExceptHook(os.getcwd(), __version__)
+ AddExceptHook(os.getcwd(),__version__) frame = LPCBeremiz(None, ctr=CTR, debug=True)