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 @@
-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 @@
-from __future__ import absolute_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')) 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')) 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
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()]) -for size, types in LOCATIONDATATYPES.iteritems():
+for size, types in LOCATIONDATATYPES.items(): LOCATION_SIZES[_type] = size
@@ -86,7 +86,7 @@
def __getitem__(self, key):
return self.VariableLocationTree
- raise KeyError, "Only 'children' key is available"
+ raise KeyError("Only 'children' key is available") @@ -151,7 +151,7 @@
def _AddUsedLocation(self, parent, location):
- if not parent.has_key(num):
parent[num] = {"used": False, "children": {}}
self._AddUsedLocation(parent[num]["children"], location)
@@ -164,7 +164,7 @@
def _CheckLocationConflicts(self, parent, location):
- if not parent.has_key(num):
@@ -220,7 +220,7 @@
# 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)) 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 @@
-from __future__ import absolute_import
--- 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 @@
-from __future__ import absolute_import
from threading import Thread, Semaphore, Lock, Timer
-from types import StringType, UnicodeType
@@ -126,7 +125,7 @@
# if len(cmdlog) > 100: # prevent debug log to grow too much
- if isinstance(res, (StringType, UnicodeType)):
--- 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 @@
-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 @@
-from __future__ import absolute_import
from threading import Thread
@@ -96,6 +96,7 @@
# 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 @@
-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 @@
-from __future__ import absolute_import
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) @@ -155,12 +158,12 @@
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.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
-from LPCAppProto 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)] 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 @@
LPC_STATUS={0xaa : "Started",
@@ -15,7 +15,7 @@
res = transaction.ExchangeData()
raise LPCProtoError("controller did not answer as expected")
raise LPCProtoError("application mode transaction error : "+str(e))
return LPC_STATUS.get(current_plc_status,"Broken"), res
@@ -34,7 +34,7 @@
res = self.pseudofile.read(2)
- comm_status, current_plc_status = map(ord, res)
+ comm_status, current_plc_status = list(map(ord, res)) 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 .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 @@
class LPCBootProto(LPCProto):
def HandleTransaction(self, transaction):
@@ -20,7 +20,7 @@
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):
@@ -63,6 +63,6 @@
TestConnection = LPCBootProto(2,115200,1200)
mystr=file("fw.bin").read()
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
def __init__(self, confnodesroot, comportstr):
@@ -33,7 +33,7 @@
self.confnodesroot.logger.write_error(str(e)+"\n")
self.SerialConnection = None
self.PLCStatus = "Disconnected"
@@ -47,13 +47,13 @@
self.SerialConnection.HandleTransaction(transaction)
- except LPCProtoError,e:
+ except LPCProtoError as e: if self.SerialConnection is not None:
self.SerialConnection.close()
self.SerialConnection = None
self.PLCStatus = "Disconnected"
self.TransactionLock.release()
--- 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 @@
res = self._serialPort.readline()
- print 'Recv :"', res, '"'
+ print('Recv :"', res, '"') res = self._serialPort.read(cnt)
- print "Recv :", map(hex,map(ord,res[:16])), "[...]"
+ print("Recv :", list(map(hex,list(map(ord,res[:16])))), "[...]") - print "Recv :", map(hex,map(ord,res))
+ print("Recv :", list(map(hex,list(map(ord,res))))) def write(self_, string):
- print "Send :", map(hex,map(ord,string[:16])), "[...]"
+ print("Send :", list(map(hex,list(map(ord,string[:16])))), "[...]") - print "Send :", map(hex,map(ord,string))
+ print("Send :", list(map(hex,list(map(ord,string))))) return self._serialPort.write(string)
# 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('/')
- from LPCAppObject import LPCAppObject
+ from .LPCAppObject import LPCAppObject return LPCAppObject(confnodesroot,comportstr)
- 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 @@
from subprocess import Popen,PIPE
-from toolchain_makefile import toolchain_makefile
+from .toolchain_makefile import toolchain_makefile 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()
def _get_cached_md5_header(self):
@@ -38,7 +38,7 @@
return open(self._GetBinMD5FileName(), "r").read()
def ResetBinaryCodeMD5(self, mode):
@@ -46,7 +46,7 @@
os.remove(self._GetBinMD5FileName())
return toolchain_makefile.ResetBinaryCodeMD5(self)
@@ -69,7 +69,7 @@
_("Binary is %s bytes long\n")%
os.path.join(self.buildpath, "ArmPLC_rom.bin"))))
--- 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 @@
+from functools import reduce includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
@@ -28,7 +29,7 @@
os.remove(self._GetMD5FileName())
def GetBinaryCodeMD5(self):
@@ -37,7 +38,7 @@
return open(self._GetMD5FileName(), "r").read()
def concat_deps(self, bn):
@@ -54,7 +55,7 @@
# 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) --- 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')
self.logger.write(_("Export file is successfully created on location: %s\n") % path_export_file)
self.logger.write(_("Export file is not created because eror: %s\n") % e)
@@ -232,7 +232,7 @@
uri = "LPC://%s/%s" % (self.OnlineMode, path)
self.LPCConnector = connectors.ConnectorFactory(uri, self)
+ 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 @@
self._SetConnector(connectors.ConnectorFactory(uri, self))
+ 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 as exc: self.logger.write_error(name + _(" generation failed !\n"))
self.logger.write_error(traceback.format_exc())
@@ -640,7 +640,7 @@
self.logger.write_error(_("C Build failed.\n"))
+ except Exception as exc: self.logger.write_error(_("C Build crashed !\n"))
self.logger.write_error(traceback.format_exc())
--- 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 @@
-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 @@
-from __future__ import absolute_import
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:]
- print "command >" + line
+ print("command >" + line) --- 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):
- 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
@@ -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)]) 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