--- a/connectors/ConnectorBase.py Sat Nov 25 00:18:05 2023 +0100
+++ b/connectors/ConnectorBase.py Thu Dec 07 22:41:32 2023 +0100
@@ -5,12 +5,21 @@
+from runtime import PlcStatus class ConnectorBase(object):
+ "GetTraceVariables": (PlcStatus.Broken, None), + "GetPLCstatus": (PlcStatus.Broken, None), + "RemoteExec": (-1, "RemoteExec script failed!"), + "GetVersions": "*** Unknown ***" def BlobFromFile(self, filepath, seed):
--- a/connectors/PYRO/__init__.py Sat Nov 25 00:18:05 2023 +0100
+++ b/connectors/PYRO/__init__.py Thu Dec 07 22:41:32 2023 +0100
@@ -34,7 +34,6 @@
-from runtime import PlcStatus
@@ -64,6 +63,9 @@
RemotePLCObjectProxy._pyroTimeout = 60
+ class MissingCallException(Exception): def PyroCatcher(func, default=None):
A function that catch a Pyro exceptions, write error to logger
@@ -77,6 +79,8 @@
confnodesroot.logger.write_error(_("Connection lost!\n"))
except Pyro5.errors.ProtocolError as e:
confnodesroot.logger.write_error(_("Pyro exception: %s\n") % e)
+ except MissingCallException as e: + confnodesroot.logger.write_warning(_("Remote call not supported: %s\n") % e.message) errmess = ''.join(Pyro5.errors.get_pyro_traceback())
confnodesroot.logger.write_error(errmess + "\n")
@@ -94,13 +98,6 @@
PSK.UpdateID(confnodesroot.ProjectPath, ID, secret, uri)
- _special_return_funcs = {
- "GetTraceVariables": (PlcStatus.Broken, None),
- "GetPLCstatus": (PlcStatus.Broken, None),
- "RemoteExec": (-1, "RemoteExec script failed!")
class PyroProxyProxy(object):
A proxy proxy class to handle Beremiz Pyro interface specific behavior.
@@ -110,8 +107,12 @@
member = self.__dict__.get(attrName, None)
def my_local_func(*args, **kwargs):
- return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs)
- member = PyroCatcher(my_local_func, _special_return_funcs.get(attrName, None))
+ call = RemotePLCObjectProxy.__getattr__(attrName) + raise MissingCallException(attrName) + return call(*args, **kwargs) + member = PyroCatcher(my_local_func, self.PLCObjDefaults.get(attrName, None)) self.__dict__[attrName] = member
--- a/connectors/WAMP/__init__.py Sat Nov 25 00:18:05 2023 +0100
+++ b/connectors/WAMP/__init__.py Thu Dec 07 22:41:32 2023 +0100
@@ -35,7 +35,6 @@
from autobahn.wamp.exception import TransportLost
from autobahn.wamp.serializer import MsgPackSerializer
-from runtime import PlcStatus
@@ -56,14 +55,6 @@
print('WAMP session left')
- "GetTraceVariables": ("Broken", None),
- "GetPLCstatus": (PlcStatus.Broken, None),
- "RemoteExec": (-1, "RemoteExec script failed!")
def _WAMP_connector_factory(cls, uri, confnodesroot):
WAMP://127.0.0.1:12345/path#realm#ID
@@ -107,26 +98,6 @@
AddToDoBeforeQuit(reactor.stop)
reactor.run(installSignalHandlers=False)
- def WampSessionProcMapper(funcname):
- wampfuncname = str('.'.join((ID, funcname)))
- def catcher_func(*args, **kwargs):
- if _WampSession is not None:
- return threads.blockingCallFromThread(
- reactor, _WampSession.call, wampfuncname,
- confnodesroot.logger.write_error(_("Connection lost!\n"))
- confnodesroot._SetConnector(None)
- errmess = traceback.format_exc()
- confnodesroot.logger.write_error(errmess+"\n")
- # confnodesroot._SetConnector(None)
- return PLCObjDefaults.get(funcname)
class WampPLCObjectProxy(object):
@@ -144,10 +115,30 @@
+ def WampSessionProcMapper(self, funcname): + wampfuncname = str('.'.join((ID, funcname))) + def catcher_func(*args, **kwargs): + if _WampSession is not None: + return threads.blockingCallFromThread( + reactor, _WampSession.call, wampfuncname, + confnodesroot.logger.write_error(_("Connection lost!\n")) + confnodesroot._SetConnector(None) + errmess = traceback.format_exc() + confnodesroot.logger.write_error(errmess+"\n") + # confnodesroot._SetConnector(None) + return self.PLCObjDefaults.get(funcname) def __getattr__(self, attrName):
member = self.__dict__.get(attrName, None)
- member = WampSessionProcMapper(attrName)
+ member = self.WampSessionProcMapper(attrName) self.__dict__[attrName] = member
--- a/modbus/mb_runtime.c Sat Nov 25 00:18:05 2023 +0100
+++ b/modbus/mb_runtime.c Thu Dec 07 22:41:32 2023 +0100
@@ -690,7 +690,7 @@
res |= pthread_attr_init(&attr);
res |= pthread_create(&(client_nodes[index].timer_thread_id), &attr, &__mb_client_timer_thread, (void *)((char *)NULL + index));
- fprintf(stderr, "Modbus plugin: Error starting timer thread for modbus client node %%s\n", client_nodes[index].location);
+ fprintf(stderr, "Modbus plugin: Error (%%d) starting timer thread for modbus client node %%s\n", res, client_nodes[index].location); @@ -703,7 +703,7 @@
res |= pthread_attr_init(&attr);
res |= pthread_create(&(client_nodes[index].thread_id), &attr, &__mb_client_thread, (void *)((char *)NULL + index));
- fprintf(stderr, "Modbus plugin: Error starting thread for modbus client node %%s\n", client_nodes[index].location);
+ fprintf(stderr, "Modbus plugin: Error (%%d) starting thread for modbus client node %%s\n", res, client_nodes[index].location); @@ -730,7 +730,7 @@
res |= pthread_attr_init(&attr);
res |= pthread_create(&(server_nodes[index].thread_id), &attr, &__mb_server_thread, (void *)&(server_nodes[index]));
- fprintf(stderr, "Modbus plugin: Error starting modbus server thread for node %%s\n", server_nodes[index].location);
+ fprintf(stderr, "Modbus plugin: Error (%%d) starting modbus server thread for node %%s\n", res, server_nodes[index].location); --- a/runtime/NevowServer.py Sat Nov 25 00:18:05 2023 +0100
+++ b/runtime/NevowServer.py Thu Dec 07 22:41:32 2023 +0100
@@ -28,7 +28,6 @@
-import platform as platform_module
from zope.interface import implementer
from nevow import appserver, inevow, tags, loaders, athena, url, rend
from nevow.page import renderer
@@ -99,6 +98,17 @@
self.bindingsNames.append(name)
+ customSettingsURLs = {} + def addCustomURL(self, segment, func): + self.customSettingsURLs[segment] = func + def removeCustomURL(self, segment): + del self.customSettingsURLs[segment] + def customLocateChild(self, ctx, segments): + if segment in self.customSettingsURLs: + return self.customSettingsURLs[segment](ctx, segments) ConfigurableSettings = ConfigurableBindings()
@@ -112,13 +122,12 @@
global extensions_settings_od
extensions_settings_od.pop(token)
class ISettings(annotate.TypedInterface):
platform = annotate.String(label=_("Platform"),
- default=platform_module.system() +
- " " + platform_module.release(),
+ default=lambda *a,**k:GetPLCObjectSingleton().GetVersions(),
# pylint: disable=no-self-argument
@@ -159,30 +168,26 @@
"Upload a file to PLC working directory"),
extensions_settings_od = collections.OrderedDict()
+CSS_tags = [tags.link(rel='stylesheet', + href=url.here.child("webform_css")), + tags.link(rel='stylesheet', + href=url.here.child("webinterface_css"))] -class SettingsPage(rend.Page):
+class StyledSettingsPage(rend.Page): # This makes webform_css url answer some default CSS
child_webform_css = webform.defaultCSS
child_webinterface_css = File(paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css')
+class SettingsPage(StyledSettingsPage): - def __getattr__(self, name):
- global extensions_settings_od
- if name.startswith('configurable_'):
- def configurable_something(ctx):
- settings, _display = extensions_settings_od[token]
- return configurable_something
def extensions_settings(self, context, data):
""" Project extensions settings
Extensions added to Configuration Tree in IDE have their setting rendered here
@@ -191,25 +196,22 @@
for token in extensions_settings_od:
_settings, display = extensions_settings_od[token]
- res += [tags.h2[display], webform.renderForms(token)]
+ res += [tags.p[tags.a(href=token)[display]]] docFactory = loaders.stan([tags.html[
tags.title[_("Beremiz Runtime Settings")],
- tags.link(rel='stylesheet',
- href=url.here.child("webform_css")),
- tags.link(rel='stylesheet',
- href=url.here.child("webinterface_css"))
tags.a(href='/')['Back'],
- tags.h1["Runtime settings:"],
+ tags.h2["Runtime service"], webform.renderForms('staticSettings'),
- tags.h1["Extensions settings:"],
+ tags.h2["Target specific"], webform.renderForms('dynamicSettings'),
@@ -242,10 +244,47 @@
shutil.copyfileobj(fobj,destfd)
def locateChild(self, ctx, segments):
- if segments[0] in customSettingsURLs:
- return customSettingsURLs[segments[0]](ctx, segments)
+ if segment in extensions_settings_od: + settings, display = extensions_settings_od[segment] + return ExtensionSettingsPage(settings, display), segments[1:] + res = ConfigurableSettings.customLocateChild(ctx, segments) return super(SettingsPage, self).locateChild(ctx, segments)
+class ExtensionSettingsPage(StyledSettingsPage): + docFactory = loaders.stan([ + tags.title[tags.directive("title")], + tags.h1[tags.directive("title")], + tags.a(href='/settings')['Back'], + webform.renderForms('settings') + def render_title(self, ctx, data): + return self._display_name + def configurable_settings(self, ctx): + def __init__(self, settings, display): + self._settings = settings + self._display_name = display + def locateChild(self, ctx, segments): + res = self._settings.customLocateChild(ctx, segments) + return super(ExtensionSettingsPage, self).locateChild(ctx, segments) def RegisterWebsite(iface, port):
site = appserver.NevowSite(website)
--- a/runtime/PLCObject.py Sat Nov 25 00:18:05 2023 +0100
+++ b/runtime/PLCObject.py Thu Dec 07 22:41:32 2023 +0100
@@ -28,6 +28,7 @@
+import platform as platform_module from tempfile import mkstemp
@@ -811,3 +812,7 @@
return (-1, "RemoteExec script failed!\n\nLine %d: %s\n\t%s" %
(line_no, e_value, script.splitlines()[line_no - 1]))
return (0, kwargs.get("returnVal", None))
+ return platform_module.system() + " " + platform_module.release() --- a/runtime/spawn_subprocess.py Sat Nov 25 00:18:05 2023 +0100
+++ b/runtime/spawn_subprocess.py Thu Dec 07 22:41:32 2023 +0100
@@ -15,17 +15,24 @@
fsencoding = sys.getfilesystemencoding()
- def __init__(self, args, stdin=None, stdout=None):
+ def __init__(self, args, stdin=None, stdout=None, stderr=None):
file_actions = posix_spawn.FileActions()
# child's stdout, child 2 parent pipe
+ c1pread, c1pwrite = os.pipe() + # attach child's stdout to writing en of c1p pipe + file_actions.add_dup2(c1pwrite, 1) + file_actions.add_close(c1pread) + # child's stderr, child 2 parent pipe c2pread, c2pwrite = os.pipe()
- # attach child's stdout to writing en of c2p pipe
- file_actions.add_dup2(c2pwrite, 1)
+ # attach child's stderr to writing en of c2p pipe + file_actions.add_dup2(c2pwrite, 2) file_actions.add_close(c2pread)
@@ -38,7 +45,10 @@
args = [s.encode(fsencoding) for s in args if type(s)==str]
self.pid = posix_spawn.posix_spawnp(args[0], args, file_actions=file_actions)
- self.stdout = os.fdopen(c2pread)
+ self.stdout = os.fdopen(c1pread) + self.stderr = os.fdopen(c2pread) self.stdin = os.fdopen(p2cwrite, 'w')
@@ -52,29 +62,44 @@
if self.stdin is not None:
if self.stdout is not None:
stdoutdata = self.stdout.read()
+ if self.stderr is not None: + stderrdata = self.stderr.read() if self.stdout is not None:
+ if self.stderr is not None: return (stdoutdata, stderrdata)
if self.stdin is not None:
if self.stdout is not None:
+ if self.stderr is not None: @@ -86,10 +111,15 @@
if self.stdin is not None:
if self.stdout is not None:
+ if self.stderr is not None: @@ -98,10 +128,15 @@
if self.stdin is not None:
if self.stdout is not None:
+ if self.stderr is not None: