--- a/Beremiz_service.py Mon Oct 01 15:53:34 2018 +0300
+++ b/Beremiz_service.py Tue Oct 02 16:53:14 2018 +0300
@@ -38,6 +38,7 @@
from runtime import PLCObject, ServicePublisher, MainWorker
from runtime.xenomai import TryPreloadXenomai
+from runtime import PlcStatus import util.paths as paths
@@ -311,14 +312,14 @@
def OnTaskBarStartPLC(self, evt):
if self.pyroserver.plcobj is not None:
plcstatus = self.pyroserver.plcobj.GetPLCstatus()[0]
- if plcstatus is "Stopped":
+ if plcstatus is PlcStatus.Stopped: self.pyroserver.plcobj.StartPLC()
print(_("PLC is empty or already started."))
def OnTaskBarStopPLC(self, evt):
if self.pyroserver.plcobj is not None:
- if self.pyroserver.plcobj.GetPLCstatus()[0] == "Started":
+ if self.pyroserver.plcobj.GetPLCstatus()[0] == PlcStatus.Started: Thread(target=self.pyroserver.plcobj.StopPLC).start()
print(_("PLC is not started."))
@@ -383,9 +384,9 @@
wx.CallAfter(wx.GetApp().ExitMainLoop)
def UpdateIcon(self, plcstatus):
- if plcstatus is "Started":
+ if plcstatus is PlcStatus.Started: currenticon = self.MakeIcon(starticon)
- elif plcstatus is "Stopped":
+ elif plcstatus is PlcStatus.Stopped: currenticon = self.MakeIcon(stopicon)
currenticon = self.MakeIcon(defaulticon)
@@ -481,7 +482,7 @@
- if self.plcobj.GetPLCstatus()[0] == "Stopped":
+ if self.plcobj.GetPLCstatus()[0] == PlcStatus.Stopped: self.plcobj.StatusChange()
--- a/ProjectController.py Mon Oct 01 15:53:34 2018 +0300
+++ b/ProjectController.py Tue Oct 02 16:53:14 2018 +0300
@@ -61,6 +61,7 @@
from plcopen.types_enums import ComputeConfigurationResourceName, ITEM_CONFNODE
from runtime.typemapping import DebugTypesSize, UnpackDebugBuffer
+from runtime import PlcStatus from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage
base_folder = paths.AbsParentDir(__file__)
@@ -1422,20 +1423,20 @@
- "Started": {"_Stop": True,
- "Stopped": {"_Run": True,
- "Empty": {"_Transfer": True,
- "Broken": {"_Connect": False,
+ PlcStatus.Started: {"_Stop": True, + PlcStatus.Stopped: {"_Run": True, + PlcStatus.Empty: {"_Transfer": True, + PlcStatus.Broken: {"_Connect": False, + PlcStatus.Disconnected: {}, def UpdateMethodsFromPLCStatus(self):
@@ -1448,7 +1449,7 @@
self.UpdatePLCLog(log_count)
self._SetConnector(None, False)
- status = "Disconnected"
+ status = PlcStatus.Disconnected if self.previous_plcstate != status:
allmethods = self.DefaultMethods.copy()
@@ -1459,31 +1460,21 @@
if self.AppFrame is not None:
self.AppFrame.RefreshStatusToolBar()
- if status == "Disconnected":
+ if status == PlcStatus.Disconnected: self.AppFrame.ConnectionStatusBar.SetStatusText(
- self.GetTextStatus(status), 1)
self.AppFrame.ConnectionStatusBar.SetStatusText('', 2)
self.AppFrame.ConnectionStatusBar.SetStatusText(
_("Connected to URI: %s") % self.BeremizRoot.getURI_location().strip(), 1)
self.AppFrame.ConnectionStatusBar.SetStatusText(
- self.GetTextStatus(status), 2)
- def GetTextStatus(self, status):
- "Started": _("Started"),
- "Stopped": _("Stopped"),
- "Disconnected": _("Disconnected")
- return msgs.get(status, status)
def ShowPLCProgress(self, status="", progress=0):
self.AppFrame.ProgressStatusBar.Show()
self.AppFrame.ConnectionStatusBar.SetStatusText(
- self.GetTextStatus(status), 1)
self.AppFrame.ProgressStatusBar.SetValue(progress)
def HidePLCProgress(self):
@@ -1501,7 +1492,7 @@
plc_status, Traces = self._connector.GetTraceVariables()
# print [dict.keys() for IECPath, (dict, log, status, fvalue) in
# self.IECdebug_datas.items()]
- if plc_status == "Started":
+ if plc_status == PlcStatus.Started: for debug_tick, debug_buff in Traces:
debug_vars = UnpackDebugBuffer(
@@ -1570,7 +1561,7 @@
self.SnapshotAndResetDebugValuesBuffers()
- return self.previous_plcstate == "Started"
+ return self.previous_plcstate == PlcStatus.Started def ReArmDebugRegisterTimer(self):
if self.DebugTimer is not None:
@@ -1809,7 +1800,7 @@
# Init with actual PLC status and print it
self.UpdateMethodsFromPLCStatus()
- if self.previous_plcstate in ["Started", "Stopped"]:
+ if self.previous_plcstate in [PlcStatus.Started, PlcStatus.Stopped]: if self.DebugAvailable() and self.GetIECProgramsAndVariables():
self.logger.write(_("Debugger ready\n"))
--- a/connectors/PYRO/__init__.py Mon Oct 01 15:53:34 2018 +0300
+++ b/connectors/PYRO/__init__.py Tue Oct 02 16:53:14 2018 +0300
@@ -36,6 +36,7 @@
from Pyro.errors import PyroError
+from runtime import PlcStatus service_type = '_PYRO._tcp.local.'
# this module attribute contains a list of DNS-SD (Zeroconf) service types
@@ -142,7 +143,7 @@
_special_return_funcs = {
"GetTraceVariables": ("Broken", None),
- "GetPLCstatus": ("Broken", None),
+ "GetPLCstatus": (PlcStatus.Broken, None), "RemoteExec": (-1, "RemoteExec script failed!")
--- a/connectors/WAMP/__init__.py Mon Oct 01 15:53:34 2018 +0300
+++ b/connectors/WAMP/__init__.py Tue Oct 02 16:53:14 2018 +0300
@@ -36,6 +36,7 @@
from autobahn.wamp.exception import TransportLost
from autobahn.wamp.serializer import MsgPackSerializer
+from runtime import PlcStatus @@ -59,7 +60,7 @@
"GetTraceVariables": ("Broken", None),
- "GetPLCstatus": ("Broken", None),
+ "GetPLCstatus": (PlcStatus.Broken, None), "RemoteExec": (-1, "RemoteExec script failed!")
--- a/etherlab/EtherCATManagementEditor.py Mon Oct 01 15:53:34 2018 +0300
+++ b/etherlab/EtherCATManagementEditor.py Tue Oct 02 16:53:14 2018 +0300
@@ -19,6 +19,7 @@
# --------------------------------------------------------------------
from controls import CustomGrid, CustomTable
+from runtime import PlcStatus # --------------------------------------------------------------------
# ------------ for register management ---------------
@@ -242,7 +243,7 @@
# (2) Otherwise, show error message and return
status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
- if status == "Started":
+ if status == PlcStatus.Started: self.Controler.CommonMethod.RequestSlaveState("OP")
self.TextCtrlDic["TargetState"].SetValue("OP")
@@ -906,7 +907,7 @@
check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
- if status is not "Started":
+ if status is not PlcStatus.Started: dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "", _("bin files (*.bin)|*.bin"), wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
@@ -1275,7 +1276,7 @@
check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
- if status is not "Started":
+ if status is not PlcStatus.Started: self.Controler.CommonMethod.SiiWrite(self.SiiBinary)
self.Controler.CommonMethod.Rescan()
--- a/runtime/PLCObject.py Mon Oct 01 15:53:34 2018 +0300
+++ b/runtime/PLCObject.py Tue Oct 02 16:53:14 2018 +0300
@@ -35,6 +35,7 @@
from runtime.typemapping import TypeTranslator
from runtime.loglevels import LogLevelsDefault, LogLevelsCount
+from runtime import PlcStatus if os.name in ("nt", "ce"):
dlopen = _ctypes.LoadLibrary
@@ -175,7 +176,7 @@
self.evaluator = server.evaluator
self.argv = [server.workdir] + server.argv # force argv[0] to be "path" to exec...
self.workingdir = server.workdir
- self.PLCStatus = "Empty"
+ self.PLCStatus = PlcStatus.Empty self.PLClibraryHandle = None
self.PLClibraryLock = Lock()
self.DummyIteratorLock = None
@@ -199,9 +200,9 @@
"r").read().strip() + lib_ext
- self.PLCStatus = "Stopped"
+ self.PLCStatus = PlcStatus.Stopped - self.PLCStatus = "Empty"
+ self.PLCStatus = PlcStatus.Empty self.CurrentPLCFilename = None
@@ -502,11 +503,11 @@
- if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped":
+ if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped: c_argv = ctypes.c_char_p * len(self.argv)
res = self._startPLC(len(self.argv), c_argv(*self.argv))
- self.PLCStatus = "Started"
+ self.PLCStatus = PlcStatus.Started self.PythonRuntimeCall("start")
self.StartSem = Semaphore(0)
@@ -516,16 +517,16 @@
self.LogMessage("PLC started")
self.LogMessage(0, _("Problem starting PLC : error %d" % res))
- self.PLCStatus = "Broken"
+ self.PLCStatus = PlcStatus.Broken - if self.PLCStatus == "Started":
+ if self.PLCStatus == PlcStatus.Started: self.LogMessage("PLC stopped")
- self.PLCStatus = "Stopped"
+ self.PLCStatus = PlcStatus.Stopped self.PythonRuntimeCall("stop")
if self.TraceThread is not None:
@@ -540,7 +541,7 @@
def NewPLC(self, md5sum, data, extrafiles):
- if self.PLCStatus in ["Stopped", "Empty", "Broken"]:
+ if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]: NewFileName = md5sum + lib_ext
extra_files_log = os.path.join(self.workingdir, "extra_files.txt")
@@ -556,7 +557,7 @@
self.LogMessage("NewPLC (%s)" % md5sum)
- self.PLCStatus = "Empty"
+ self.PLCStatus = PlcStatus.Empty if replace_PLC_shared_object:
@@ -587,20 +588,20 @@
self.CurrentPLCFilename = NewFileName
- self.PLCStatus = "Broken"
+ self.PLCStatus = PlcStatus.Broken PLCprint(traceback.format_exc())
if not replace_PLC_shared_object:
- self.PLCStatus = "Stopped"
+ self.PLCStatus = PlcStatus.Stopped - self.PLCStatus = "Stopped"
+ self.PLCStatus = PlcStatus.Stopped - self.PLCStatus = "Broken"
+ self.PLCStatus = PlcStatus.Broken - return self.PLCStatus == "Stopped"
+ return self.PLCStatus == PlcStatus.Stopped @@ -635,7 +636,7 @@
self.LastSwapTrace = time()
- if self.TraceThread is None and self.PLCStatus == "Started":
+ if self.TraceThread is None and self.PLCStatus == PlcStatus.Started: self.TraceThread = Thread(target=self.TraceThreadProc)
@@ -653,7 +654,7 @@
Return a list of traces, corresponding to the list of required idx
self._resumeDebug() # Re-enable debugger
- while self.PLCStatus == "Started":
+ while self.PLCStatus == PlcStatus.Started: