lpcmanager

Parents ff7e861ce271
Children 968105d8cb36
Port to python3: used 2to3 ver 3.10 + some manual fixes until IDE shows up. Pairs with new windows installer, lpcdistro 25eb179471d7.
--- a/LPCBACnet.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCBACnet.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
from bacnet import bacnet as BacnetModule
from bacnet.bacnet import RootClass
--- a/LPCBeremiz.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCBeremiz.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import wx
from BeremizIDE import *
@@ -16,19 +16,19 @@
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=_('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=_('Close Tab\tCTRL+W'))
parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
- kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
+ kind=wx.ITEM_NORMAL, text=_('Page Setup'))
AppendMenu(parent, help='', id=wx.ID_PREVIEW,
- kind=wx.ITEM_NORMAL, text=_(u'Preview'))
+ kind=wx.ITEM_NORMAL, text=_('Preview'))
AppendMenu(parent, help='', id=wx.ID_PRINT,
- kind=wx.ITEM_NORMAL, text=_(u'Print'))
+ kind=wx.ITEM_NORMAL, text=_('Print'))
parent.AppendSeparator()
AppendMenu(parent, help='', id=wx.ID_EXIT,
- kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
+ kind=wx.ITEM_NORMAL, text=_('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)
@@ -37,8 +37,8 @@
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)])
+ self.AddToMenuToolBar([(wx.ID_SAVE, "save", _('Save'), None),
+ (wx.ID_PRINT, "print", _('Print'), None)])
--- a/LPCBus.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCBus.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,4 +1,4 @@
-from __future__ import absolute_import
+
import os
from LPCArch import GetLPCArch, GetLPCProduct, SOM28_modules, GetLPCProductDesc
@@ -22,10 +22,10 @@
"Q": LOCATION_VAR_OUTPUT,
"M": LOCATION_VAR_MEMORY}
-LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
+LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.items()])
LOCATION_SIZES = {}
-for size, types in LOCATIONDATATYPES.iteritems():
+for size, types in LOCATIONDATATYPES.items():
for _type in types:
LOCATION_SIZES[_type] = size
@@ -86,7 +86,7 @@
def __getitem__(self, key):
if key == "children":
return self.VariableLocationTree
- raise KeyError, "Only 'children' key is available"
+ raise KeyError("Only 'children' key is available")
def CTNEnabled(self):
return None
@@ -151,7 +151,7 @@
def _AddUsedLocation(self, parent, location):
num = location.pop(0)
- if not parent.has_key(num):
+ if num not in parent:
parent[num] = {"used": False, "children": {}}
if len(location) > 0:
self._AddUsedLocation(parent[num]["children"], location)
@@ -164,7 +164,7 @@
def _CheckLocationConflicts(self, parent, location):
num = location.pop(0)
- if not parent.has_key(num):
+ if num not in parent:
return False
if len(location) > 0:
if parent[num]["used"]:
@@ -220,7 +220,7 @@
if bus_code is None:
# Silently ignored, for example MC9 has no Left Bus, but composer always adds one.
- print("No LPCBus named "+BusName+" for "+product)
+ print(("No LPCBus named "+BusName+" for "+product))
return [], "", False
for module in GetModuleChildren(self):
@@ -248,7 +248,7 @@
# raise Exception, "Type conflict in variable definition"
if location["DIR"] == "Q":
if self.CheckLocationConflicts(location["LOC"]):
- raise Exception, "BYTE and BIT from the same BYTE can't be used together"
+ raise Exception("BYTE and BIT from the same BYTE can't be used together")
self.AddUsedLocation(location["LOC"])
vars.append({"location": location["NAME"],
"Type": variable["IEC_type"],
--- a/LPCCanFestival.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCCanFestival.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import os
--- a/LPCCommand.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCCommand.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,10 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import sys
import cmd
from threading import Thread, Semaphore, Lock, Timer
-from types import StringType, UnicodeType
import wx
from LPCBus import *
@@ -126,7 +125,7 @@
# if len(cmdlog) > 100: # prevent debug log to grow too much
# cmdlog.pop(0)
- if isinstance(res, (StringType, UnicodeType)):
+ if type(res) == str:
self.Log.write(res)
return False
else:
--- a/LPCExtension.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCExtension.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
#
# --------- Libraries Extension ------------
@@ -38,7 +38,7 @@
# --------- Configuration Tree Nodes (CTN) catalog extension ------------
#
_oldcatalog = features.catalog
-catalog_index = dict(zip(zip(*_oldcatalog)[0],_oldcatalog))
+catalog_index = dict(list(zip(list(zip(*_oldcatalog))[0],_oldcatalog)))
wanted_beremiz_features = [catalog_index[feature]
for feature in wanted_features_names]
features.catalog = wanted_beremiz_features + [
--- a/LPCManager.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCManager.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import sys
import os
import getopt
-import __builtin__
+import builtins
import time
from threading import Thread
@@ -96,6 +96,7 @@
cmd_thread.start()
# TODO: join() when exiting
+
self.frame = self.LPCBeremiz.LPCBeremiz(None, ctr=CTR, pipe=CMDpipe)
def CreateApplication(self):
--- a/LPCModbus.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCModbus.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
from modbus.modbus import _ModbusRTUclientPlug, _ModbusRTUslavePlug, RootClass
from LPCArch import GetLPCArch
--- a/LPCProjectController.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCProjectController.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,11 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import os
import zipfile
import wx
from ProjectController import ProjectController
+from PLCControler import PLCControler
from FirmwareUpdateDialog import FirmwareUpdateDialog
from HostFirmwareUpdater import HostFirmwareUpdater
@@ -56,7 +57,9 @@
In LPCManager, project name is given as PLCOpen project name
and is passed at startup by SetProjectProperties command
"""
- return self.Project.getname()
+ # calls PLCControler method, since it uses name stored
+ # in plcopen XML rather than directory name
+ return PLCControler.GetProjectName(self)
def xEyeExport(self):
"""
@@ -155,12 +158,12 @@
else :
ProjectController.LoadProject(self, ProjectPath, BuildPath)
- if GetLPCProductDesc().get("CAN", True):
- canopen_child = self.GetChildByName("CanOpen")
- if canopen_child is None:
- canopen = self.CTNAddChild("CanOpen", "CanOpen", 0)
- canopen.LoadChildren()
- canopen.CTNRequestSave()
+# if GetLPCProductDesc().get("CAN", True):
+# canopen_child = self.GetChildByName("CanOpen")
+# if canopen_child is None:
+# canopen = self.CTNAddChild("CanOpen", "CanOpen", 0)
+# canopen.LoadChildren()
+# canopen.CTNRequestSave()
self.SetParamsAttribute('BeremizRoot.TargetType', self.arch)
--- a/LPCconnector/LPCAppObject.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCAppObject.py Fri Jan 26 11:24:41 2024 +0100
@@ -23,8 +23,8 @@
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import ctypes
-from LPCAppProto import *
-from LPCObject import *
+from .LPCAppProto import *
+from .LPCObject import *
from targets.typemapping import LogLevelsCount, TypeTranslator, UnpackDebugBuffer
class LPCAppObject(LPCObject):
@@ -49,7 +49,7 @@
if strcounts is not None and len(strcounts) == LogLevelsCount * 4:
cstrcounts = ctypes.create_string_buffer(strcounts)
ccounts = ctypes.cast(cstrcounts, ctypes.POINTER(ctypes.c_uint32))
- counts = [int(ccounts[idx]) for idx in xrange(LogLevelsCount)]
+ counts = [int(ccounts[idx]) for idx in range(LogLevelsCount)]
else :
counts = [0]*LogLevelsCount
return self.PLCStatus, counts
--- a/LPCconnector/LPCAppProto.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCAppProto.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,5 +1,5 @@
import ctypes
-from LPCProto import *
+from .LPCProto import *
LPC_STATUS={0xaa : "Started",
0x55 : "Stopped"}
@@ -15,7 +15,7 @@
res = transaction.ExchangeData()
else:
raise LPCProtoError("controller did not answer as expected")
- except Exception, e:
+ except Exception as e:
raise LPCProtoError("application mode transaction error : "+str(e))
return LPC_STATUS.get(current_plc_status,"Broken"), res
@@ -34,7 +34,7 @@
def GetCommandAck(self):
res = self.pseudofile.read(2)
if len(res) == 2:
- comm_status, current_plc_status = map(ord, res)
+ comm_status, current_plc_status = list(map(ord, res))
else:
raise LPCProtoError("LPC transaction error - controller did not ack order")
# LPC returns command itself as an ack for command
--- a/LPCconnector/LPCBootObject.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCBootObject.py Fri Jan 26 11:24:41 2024 +0100
@@ -22,8 +22,8 @@
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from LPCBootProto import *
-from LPCObject import *
+from .LPCBootProto import *
+from .LPCObject import *
class LPCBootObject(LPCObject):
def __init__(self, confnodesroot, comportstr):
--- a/LPCconnector/LPCBootProto.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCBootProto.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,4 +1,4 @@
-from LPCProto import *
+from .LPCProto import *
class LPCBootProto(LPCProto):
def HandleTransaction(self, transaction):
@@ -20,7 +20,7 @@
def ExchangeData(self):
self.pseudofile.write(self.OptData)
- return map(lambda x:self.pseudofile.readline(), xrange(self.expectedlines))
+ return [self.pseudofile.readline() for x in range(self.expectedlines)]
class KEEPBOOTINGTransaction(LPCBootTransaction):
def __init__(self):
@@ -63,6 +63,6 @@
TestConnection = LPCBootProto(2,115200,1200)
mystr=file("fw.bin").read()
def mylog(blah):
- print blah,
+ print(blah, end=' ')
TestConnection.HandleTransaction(LOADTransaction(mystr, mylog))
--- a/LPCconnector/LPCObject.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCObject.py Fri Jan 26 11:24:41 2024 +0100
@@ -22,7 +22,7 @@
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from LPCProto import *
+from .LPCProto import *
class LPCObject():
def __init__(self, confnodesroot, comportstr):
@@ -33,7 +33,7 @@
self._Idxs = []
try:
self.connect(comportstr)
- except Exception,e:
+ except Exception as e:
self.confnodesroot.logger.write_error(str(e)+"\n")
self.SerialConnection = None
self.PLCStatus = "Disconnected"
@@ -47,13 +47,13 @@
try:
self.PLCStatus, res = \
self.SerialConnection.HandleTransaction(transaction)
- except LPCProtoError,e:
+ except LPCProtoError as e:
disconnected=True
if self.SerialConnection is not None:
self.SerialConnection.close()
self.SerialConnection = None
self.PLCStatus = "Disconnected"
- except Exception,e:
+ except Exception as e:
failure = str(e)
self.TransactionLock.release()
if disconnected:
--- a/LPCconnector/LPCProto.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/LPCProto.py Fri Jan 26 11:24:41 2024 +0100
@@ -20,23 +20,23 @@
class myser:
def readline(self_):
res = self._serialPort.readline()
- print 'Recv :"', res, '"'
+ print('Recv :"', res, '"')
return res
def read(self_,cnt):
res = self._serialPort.read(cnt)
if len(res) > 16:
- print "Recv :", map(hex,map(ord,res[:16])), "[...]"
+ print("Recv :", list(map(hex,list(map(ord,res[:16])))), "[...]")
else:
- print "Recv :", map(hex,map(ord,res))
+ print("Recv :", list(map(hex,list(map(ord,res)))))
return res
def write(self_, string):
lstr=len(string)
if lstr > 16:
- print "Send :", map(hex,map(ord,string[:16])), "[...]"
+ print("Send :", list(map(hex,list(map(ord,string[:16])))), "[...]")
else:
- print "Send :", map(hex,map(ord,string))
+ print("Send :", list(map(hex,list(map(ord,string)))))
return self._serialPort.write(string)
# while len(string)>0:
# i = self._serialPort.write(string[:4096])
--- a/LPCconnector/__init__.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCconnector/__init__.py Fri Jan 26 11:24:41 2024 +0100
@@ -27,10 +27,10 @@
servicetype, location = uri.split("://")
mode,comportstr = location.split('/')
if mode=="APPLICATION":
- from LPCAppObject import LPCAppObject
+ from .LPCAppObject import LPCAppObject
return LPCAppObject(confnodesroot,comportstr)
elif mode=="BOOTLOADER":
- from LPCBootObject import LPCBootObject
+ from .LPCBootObject import LPCBootObject
return LPCBootObject(confnodesroot,comportstr)
--- a/LPCtarget/__init__.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCtarget/__init__.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
import os, sys
from subprocess import Popen,PIPE
-from toolchain_makefile import toolchain_makefile
+from .toolchain_makefile import toolchain_makefile
import hashlib
class LPC_target(toolchain_makefile):
@@ -29,7 +29,7 @@
res = self._get_md5_header() +\
open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read()
return res
- except Exception, e:
+ except Exception as e:
return None
def _get_cached_md5_header(self):
@@ -38,7 +38,7 @@
else:
try:
return open(self._GetBinMD5FileName(), "r").read()
- except IOError, e:
+ except IOError as e:
return None
def ResetBinaryCodeMD5(self, mode):
@@ -46,7 +46,7 @@
self.binmd5key = None
try:
os.remove(self._GetBinMD5FileName())
- except Exception, e:
+ except Exception as e:
pass
else:
return toolchain_makefile.ResetBinaryCodeMD5(self)
@@ -69,7 +69,7 @@
_("Binary is %s bytes long\n")%
str(os.path.getsize(
os.path.join(self.buildpath, "ArmPLC_rom.bin"))))
- except Exception, e:
+ except Exception as e:
pass
return res
--- a/LPCtarget/toolchain_makefile.py Wed Nov 29 12:01:37 2023 +0100
+++ b/LPCtarget/toolchain_makefile.py Fri Jan 26 11:24:41 2024 +0100
@@ -3,6 +3,7 @@
import hashlib
import time
+from functools import reduce
includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
@@ -28,7 +29,7 @@
self.md5key = None
try:
os.remove(self._GetMD5FileName())
- except Exception, e:
+ except Exception as e:
pass
def GetBinaryCodeMD5(self):
@@ -37,7 +38,7 @@
else:
try:
return open(self._GetMD5FileName(), "r").read()
- except IOError, e:
+ except IOError as e:
return None
def concat_deps(self, bn):
@@ -54,7 +55,7 @@
deps.append(depfn)
# recurse through deps
# TODO detect cicular deps.
- return reduce(operator.concat, map(self.concat_deps, deps), src)
+ return reduce(operator.concat, list(map(self.concat_deps, deps)), src)
def build(self):
srcfiles= []
--- a/MC8ProjectController.py Wed Nov 29 12:01:37 2023 +0100
+++ b/MC8ProjectController.py Fri Jan 26 11:24:41 2024 +0100
@@ -34,7 +34,7 @@
shutil.copy2(srcpath, dstpath)
-[SIMULATION_MODE, TRANSFER_MODE] = range(2)
+[SIMULATION_MODE, TRANSFER_MODE] = list(range(2))
# TODO : re-consider customization for MC8
# from editors.ProjectNodeEditor import ProjectNodeEditor
@@ -200,7 +200,7 @@
zf.write(self.BuildPath + '\\lastbuildPLC.md5', 'lastbuildPLC.md5')
zf.close()
self.logger.write(_("Export file is successfully created on location: %s\n") % path_export_file)
- except Exception, e:
+ except Exception as e:
self.logger.write(_("Export file is not created because eror: %s\n") % e)
def _Build(self):
@@ -232,7 +232,7 @@
uri = "LPC://%s/%s" % (self.OnlineMode, path)
try:
self.LPCConnector = connectors.ConnectorFactory(uri, self)
- except Exception, msg:
+ except Exception as msg:
self.logger.write_error(_("Exception while connecting %s!\n") % uri)
self.logger.write_error(traceback.format_exc())
@@ -547,7 +547,7 @@
uri = "LOCAL://"
try:
self._SetConnector(connectors.ConnectorFactory(uri, self))
- except Exception, msg:
+ except Exception as msg:
self.logger.write_error(_("Exception while connecting %s!\n") % uri)
self.logger.write_error(traceback.format_exc())
@@ -621,7 +621,7 @@
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))
- except Exception, exc:
+ except Exception as exc:
self.logger.write_error(name + _(" generation failed !\n"))
self.logger.write_error(traceback.format_exc())
self.StopSimulation()
@@ -640,7 +640,7 @@
self.logger.write_error(_("C Build failed.\n"))
self.StopSimulation()
return False
- except Exception, exc:
+ except Exception as exc:
self.logger.write_error(_("C Build crashed !\n"))
self.logger.write_error(traceback.format_exc())
self.StopSimulation()
--- a/OnChangeFromOptions.py Wed Nov 29 12:01:37 2023 +0100
+++ b/OnChangeFromOptions.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
from OptionsParsing import ParseOptions, GenOptions
--- a/OptionsParsing.py Wed Nov 29 12:01:37 2023 +0100
+++ b/OptionsParsing.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from __future__ import absolute_import
+
import re
VARIABLETYPE = ["None", "Static", "Session", "Alarm"]
--- a/StdoutPseudoFile.py Wed Nov 29 12:01:37 2023 +0100
+++ b/StdoutPseudoFile.py Fri Jan 26 11:24:41 2024 +0100
@@ -24,7 +24,7 @@
line = self.Buffer[:idx + 1]
self.Buffer = self.Buffer[idx + 1:]
if self.debug:
- print "command >" + line
+ print("command >" + line)
return line
return ""
--- a/WampAuthentication.py Wed Nov 29 12:01:37 2023 +0100
+++ b/WampAuthentication.py Fri Jan 26 11:24:41 2024 +0100
@@ -8,7 +8,7 @@
class WampSession(WAMP.WampSession):
def onConnect(self):
- self.join(u"Automation", [u"wampcra"], u"smarteh")
+ self.join("Automation", ["wampcra"], "smarteh")
print("CRA checking ...")
def onChallenge(self, challenge):
--- a/WampOptionsEditor.py Wed Nov 29 12:01:37 2023 +0100
+++ b/WampOptionsEditor.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,4 +1,4 @@
-from __future__ import absolute_import
+
import re
import wx
import wx.grid
@@ -11,7 +11,7 @@
excluded_chars = [ord(i) for i in '\n"']
-sanitizer = "".join([chr(i if i not in excluded_chars else ord(' ')) for i in xrange(256)])
+sanitizer = "".join([chr(i if i not in excluded_chars else ord(' ')) for i in range(256)])
eraser = '\r'
class WampOptionsEditor(wx.Dialog):
--- a/WxGladeEditor.py Wed Nov 29 12:01:37 2023 +0100
+++ b/WxGladeEditor.py Fri Jan 26 11:24:41 2024 +0100
@@ -1,4 +1,4 @@
-from __future__ import absolute_import
+
from editors.CodeFileEditor import CodeFileEditor
from py_ext.PythonEditor import PythonCodeEditor