feat: New XML-RPC function 'set_plcprogram'

With the new XML-RPC function, a new PLC program can be passed, which
is loaded directly and saved in the configuration file.

Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
2023-10-26 12:30:34 +02:00
parent 5b4c799c98
commit 16102a2aa3

View File

@@ -477,6 +477,8 @@ class RevPiPyLoad:
# XML Modus 4 Einstellungen ändern
self.xsrv.register_function(
4, self.xml_setconfig, "set_config")
self.xsrv.register_function(
4, self.xml_setplcprogram, "set_plcprogram")
self.xsrv.register_function(
4, self.xml_setpictoryrsc, "set_pictoryrsc")
@@ -1365,6 +1367,33 @@ class RevPiPyLoad:
return True
def xml_setplcprogram(self, plcprogram: str) -> int:
"""
Set new plc program, without restart services.
:returns: 0 Erfolgreich
-1 Programm lauft noch
-2 Datei nicht gefunden
"""
if type(plcprogram) is not str:
raise TypeError("The given plc program must be <class 'str'>")
if not plcprogram:
raise ValueError("Empty string not allowed for plc program")
stop_code = self.xml_plcstop()
# Set the new plc program setting to activ configuration
self.plcprogram = plcprogram
# Save the new value to config file without reload
self.xml_setconfig({"plcprogram": plcprogram}, False)
# Start the program, if it was running before change
if stop_code > -1:
return self.xml_plcstart()
return 0
def xml_setpictoryrsc(self, filebytes, reset=False):
"""Schreibt die config.rsc Datei von piCotry.