author | Mario de Sousa <msousa@fe.up.pt> |
Mon, 21 Dec 2020 22:26:36 +0000 | |
changeset 2714 | 0b636dc947a2 |
parent 2666 | 5f48d5e60a81 |
permissions | -rw-r--r-- |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
3 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
4 |
# This file is part of Beremiz runtime. |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
5 |
# |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
6 |
# Copyright (C) 2020: Mario de Sousa |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
7 |
# |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
8 |
# See COPYING.Runtime file for copyrights details. |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
9 |
# |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
10 |
# This library is free software; you can redistribute it and/or |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
11 |
# modify it under the terms of the GNU Lesser General Public |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
12 |
# License as published by the Free Software Foundation; either |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
13 |
# version 2.1 of the License, or (at your option) any later version. |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
14 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
15 |
# This library is distributed in the hope that it will be useful, |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
18 |
# Lesser General Public License for more details. |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
19 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
20 |
# You should have received a copy of the GNU Lesser General Public |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
21 |
# License along with this library; if not, write to the Free Software |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
23 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
24 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
25 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
26 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
27 |
############################################################################################## |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
28 |
# This file implements an extension to the web server embedded in the Beremiz_service.py # |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
29 |
# runtime manager (webserver is in runtime/NevowServer.py). # |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
30 |
# # |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
31 |
# The extension implemented in this file allows for runtime configuration # |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
32 |
# of Modbus plugin parameters # |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
33 |
############################################################################################## |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
34 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
35 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
36 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
37 |
import json |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
38 |
import os |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
39 |
import ctypes |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
40 |
import string |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
41 |
import hashlib |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
42 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
43 |
from formless import annotate, webform |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
44 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
45 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
46 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
47 |
# reference to the PLCObject in runtime/PLCObject.py |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
48 |
# PLCObject is a singleton, created in runtime/__init__.py |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
49 |
_plcobj = None |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
50 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
51 |
# reference to the Nevow web server (a.k.a as NS in Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
52 |
# (Note that NS will reference the NevowServer.py _module_, and not an object/class) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
53 |
_NS = None |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
54 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
55 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
56 |
# WorkingDir: the directory on which Beremiz_service.py is running, and where |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
57 |
# all the files downloaded to the PLC get stored |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
58 |
_WorkingDir = None |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
59 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
60 |
# Directory in which to store the persistent configurations |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
61 |
# Should be a directory that does not get wiped on reboot! |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
62 |
_ModbusConfFiledir = "/tmp" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
63 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
64 |
# List of all Web Extension Setting nodes we are handling. |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
65 |
# One WebNode each for: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
66 |
# - Modbus TCP client |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
67 |
# - Modbus TCP server |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
68 |
# - Modbus RTU client |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
69 |
# - Modbus RTU slave |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
70 |
# configured in the loaded PLC (i.e. the .so file loaded into memory) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
71 |
# Each entry will be a dictionary. See _AddWebNode() for the details |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
72 |
# of the data structure in each entry. |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
73 |
_WebNodeList = [] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
74 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
75 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
76 |
|
2666
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
77 |
|
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
78 |
class MB_StrippedString(annotate.String): |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
79 |
def __init__(self, *args, **kwargs): |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
80 |
annotate.String.__init__(self, strip = True, *args, **kwargs) |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
81 |
|
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
82 |
|
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
83 |
class MB_StopBits(annotate.Choice): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
84 |
_choices = [0, 1, 2] |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
85 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
86 |
def coerce(self, val, configurable): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
87 |
return int(val) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
88 |
def __init__(self, *args, **kwargs): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
89 |
annotate.Choice.__init__(self, choices = self._choices, *args, **kwargs) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
90 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
91 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
92 |
class MB_Baud(annotate.Choice): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
93 |
_choices = [110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200] |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
94 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
95 |
def coerce(self, val, configurable): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
96 |
return int(val) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
97 |
def __init__(self, *args, **kwargs): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
98 |
annotate.Choice.__init__(self, choices = self._choices, *args, **kwargs) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
99 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
100 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
101 |
class MB_Parity(annotate.Choice): |
2660 | 102 |
# For more info on what this class really does, have a look at the code in |
103 |
# file twisted/nevow/annotate.py |
|
104 |
# grab this code from $git clone https://github.com/twisted/nevow/ |
|
105 |
# |
|
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
106 |
# Warning: do _not_ name this variable choice[] without underscore, as that name is |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
107 |
# already used for another similar variable by the underlying class annotate.Choice |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
108 |
_choices = [ 0, 1, 2 ] |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
109 |
_label = ["none", "odd", "even"] |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
110 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
111 |
def choice_to_label(self, key): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
112 |
#_plcobj.LogMessage("Modbus web server extension::choice_to_label() " + str(key)) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
113 |
return self._label[key] |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
114 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
115 |
def coerce(self, val, configurable): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
116 |
"""Coerce a value with the help of an object, which is the object |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
117 |
we are configuring. |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
118 |
""" |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
119 |
# Basically, make sure the value the user introduced is valid, and transform |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
120 |
# into something that is valid if necessary or mark it as an error |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
121 |
# (by raising an exception ??). |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
122 |
# |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
123 |
# We are simply using this functions to transform the input value (a string) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
124 |
# into an integer. Note that although the available options are all |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
125 |
# integers (0, 1 or 2), even though what is shown on the user interface |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
126 |
# are actually strings, i.e. the labels), these parameters are for some |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
127 |
# reason being parsed as strings, so we need to map them back to an |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
128 |
# integer. |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
129 |
# |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
130 |
#_plcobj.LogMessage("Modbus web server extension::coerce " + val ) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
131 |
return int(val) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
132 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
133 |
def __init__(self, *args, **kwargs): |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
134 |
annotate.Choice.__init__(self, |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
135 |
choices = self._choices, |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
136 |
stringify = self.choice_to_label, |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
137 |
*args, **kwargs) |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
138 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
139 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
140 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
141 |
# Parameters we will need to get from the C code, but that will not be shown |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
142 |
# on the web interface. Common to all modbus entry types (client/server, tcp/rtu/ascii) |
2658
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
143 |
# |
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
144 |
# The annotate type entry is basically useless and is completely ignored. |
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
145 |
# We kee that entry so that this list can later be correctly merged with the |
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
146 |
# following lists... |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
147 |
General_parameters = [ |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
148 |
# param. name label ctype type annotate type |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
149 |
# (C code var name) (used on web interface) (C data type) (web data type) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
150 |
# (annotate.String, |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
151 |
# annotate.Integer, ...) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
152 |
("config_name" , _("") , ctypes.c_char_p, annotate.String), |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
153 |
("addr_type" , _("") , ctypes.c_char_p, annotate.String) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
154 |
] |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
155 |
|
2661 | 156 |
# Parameters we will need to get from the C code, and that _will_ be shown |
157 |
# on the web interface. |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
158 |
TCPclient_parameters = [ |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
159 |
# param. name label ctype type annotate type |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
160 |
# (C code var name) (used on web interface) (C data type) (web data type) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
161 |
# (annotate.String, |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
162 |
# annotate.Integer, ...) |
2666
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
163 |
("host" , _("Remote IP Address") , ctypes.c_char_p, MB_StrippedString), |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
164 |
("port" , _("Remote Port Number") , ctypes.c_char_p, MB_StrippedString), |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
165 |
("comm_period" , _("Invocation Rate (ms)") , ctypes.c_ulonglong, annotate.Integer ) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
166 |
] |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
167 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
168 |
RTUclient_parameters = [ |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
169 |
# param. name label ctype type annotate type |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
170 |
# (C code var name) (used on web interface) (C data type) (web data type) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
171 |
# (annotate.String, |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
172 |
# annotate.Integer, ...) |
2666
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
173 |
("device" , _("Serial Port") , ctypes.c_char_p, MB_StrippedString), |
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
174 |
("baud" , _("Baud Rate") , ctypes.c_int, MB_Baud ), |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
175 |
("parity" , _("Parity") , ctypes.c_int, MB_Parity ), |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
176 |
("stop_bits" , _("Stop Bits") , ctypes.c_int, MB_StopBits ), |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
177 |
("comm_period" , _("Invocation Rate (ms)") , ctypes.c_ulonglong, annotate.Integer) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
178 |
] |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
179 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
180 |
TCPserver_parameters = [ |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
181 |
# param. name label ctype type annotate type |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
182 |
# (C code var name) (used on web interface) (C data type) (web data type) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
183 |
# (annotate.String, |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
184 |
# annotate.Integer, ...) |
2666
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
185 |
("host" , _("Local IP Address") , ctypes.c_char_p, MB_StrippedString), |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
186 |
("port" , _("Local Port Number") , ctypes.c_char_p, MB_StrippedString), |
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
187 |
("slave_id" , _("Slave ID") , ctypes.c_ubyte, annotate.Integer ) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
188 |
] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
189 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
190 |
RTUslave_parameters = [ |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
191 |
# param. name label ctype type annotate type |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
192 |
# (C code var name) (used on web interface) (C data type) (web data type) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
193 |
# (annotate.String, |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
194 |
# annotate.Integer, ...) |
2666
5f48d5e60a81
Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2665
diff
changeset
|
195 |
("device" , _("Serial Port") , ctypes.c_char_p, MB_StrippedString), |
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
196 |
("baud" , _("Baud Rate") , ctypes.c_int, MB_Baud ), |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
197 |
("parity" , _("Parity") , ctypes.c_int, MB_Parity ), |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
198 |
("stop_bits" , _("Stop Bits") , ctypes.c_int, MB_StopBits ), |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
199 |
("slave_id" , _("Slave ID") , ctypes.c_ulonglong, annotate.Integer) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
200 |
] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
201 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
202 |
|
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
203 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
204 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
205 |
# Dictionary containing List of Web viewable parameters |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
206 |
# Note: the dictionary key must be the same as the string returned by the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
207 |
# __modbus_get_ClientNode_addr_type() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
208 |
# __modbus_get_ServerNode_addr_type() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
209 |
# functions implemented in C (see modbus/mb_runtime.c) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
210 |
_client_WebParamListDict = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
211 |
_client_WebParamListDict["tcp" ] = TCPclient_parameters |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
212 |
_client_WebParamListDict["rtu" ] = RTUclient_parameters |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
213 |
_client_WebParamListDict["ascii"] = [] # (Note: ascii not yet implemented in Beremiz modbus plugin) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
214 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
215 |
_server_WebParamListDict = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
216 |
_server_WebParamListDict["tcp" ] = TCPserver_parameters |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
217 |
_server_WebParamListDict["rtu" ] = RTUslave_parameters |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
218 |
_server_WebParamListDict["ascii"] = [] # (Note: ascii not yet implemented in Beremiz modbus plugin) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
219 |
|
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
220 |
WebParamListDictDict = {} |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
221 |
WebParamListDictDict['client'] = _client_WebParamListDict |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
222 |
WebParamListDictDict['server'] = _server_WebParamListDict |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
223 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
224 |
|
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
225 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
226 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
227 |
|
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
228 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
229 |
def _SetSavedConfiguration(WebNode_id, newConfig): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
230 |
""" Stores a dictionary in a persistant file containing the Modbus parameter configuration """ |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
231 |
|
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
232 |
# Add the addr_type and node_type to the data that will be saved to file |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
233 |
# This allows us to confirm the saved data contains the correct addr_type |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
234 |
# when loading from file |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
235 |
save_info = {} |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
236 |
save_info["addr_type"] = _WebNodeList[WebNode_id]["addr_type"] |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
237 |
save_info["node_type"] = _WebNodeList[WebNode_id]["node_type"] |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
238 |
save_info["config" ] = newConfig |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
239 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
240 |
filename = _WebNodeList[WebNode_id]["filename"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
241 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
242 |
with open(os.path.realpath(filename), 'w') as f: |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
243 |
json.dump(save_info, f, sort_keys=True, indent=4) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
244 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
245 |
_WebNodeList[WebNode_id]["SavedConfiguration"] = newConfig |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
246 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
247 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
248 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
249 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
250 |
def _DelSavedConfiguration(WebNode_id): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
251 |
""" Deletes the file cotaining the persistent Modbus configuration """ |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
252 |
filename = _WebNodeList[WebNode_id]["filename"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
253 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
254 |
if os.path.exists(filename): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
255 |
os.remove(filename) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
256 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
257 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
258 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
259 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
260 |
def _GetSavedConfiguration(WebNode_id): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
261 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
262 |
Returns a dictionary containing the Modbus parameter configuration |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
263 |
that was last saved to file. If no file exists, or file contains |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
264 |
wrong addr_type (i.e. 'tcp', 'rtu' or 'ascii' -> does not match the |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
265 |
addr_type of the WebNode_id), then return None |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
266 |
""" |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
267 |
filename = _WebNodeList[WebNode_id]["filename"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
268 |
try: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
269 |
#if os.path.isfile(filename): |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
270 |
save_info = json.load(open(filename)) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
271 |
except Exception: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
272 |
return None |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
273 |
|
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
274 |
if save_info["addr_type"] != _WebNodeList[WebNode_id]["addr_type"]: |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
275 |
return None |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
276 |
if save_info["node_type"] != _WebNodeList[WebNode_id]["node_type"]: |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
277 |
return None |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
278 |
if "config" not in save_info: |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
279 |
return None |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
280 |
|
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
281 |
saved_config = save_info["config"] |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
282 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
283 |
#if _CheckConfiguration(saved_config): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
284 |
# return saved_config |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
285 |
#else: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
286 |
# return None |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
287 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
288 |
return saved_config |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
289 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
290 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
291 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
292 |
def _GetPLCConfiguration(WebNode_id): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
293 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
294 |
Returns a dictionary containing the current Modbus parameter configuration |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
295 |
stored in the C variables in the loaded PLC (.so file) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
296 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
297 |
current_config = {} |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
298 |
C_node_id = _WebNodeList[WebNode_id]["C_node_id"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
299 |
WebParamList = _WebNodeList[WebNode_id]["WebParamList"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
300 |
GetParamFuncs = _WebNodeList[WebNode_id]["GetParamFuncs"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
301 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
302 |
for par_name, x1, x2, x3 in WebParamList: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
303 |
value = GetParamFuncs[par_name](C_node_id) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
304 |
if value is not None: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
305 |
current_config[par_name] = value |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
306 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
307 |
return current_config |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
308 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
309 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
310 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
311 |
def _SetPLCConfiguration(WebNode_id, newconfig): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
312 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
313 |
Stores the Modbus parameter configuration into the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
314 |
the C variables in the loaded PLC (.so file) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
315 |
""" |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
316 |
C_node_id = _WebNodeList[WebNode_id]["C_node_id"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
317 |
SetParamFuncs = _WebNodeList[WebNode_id]["SetParamFuncs"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
318 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
319 |
for par_name in newconfig: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
320 |
value = newconfig[par_name] |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
321 |
if value is not None: |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
322 |
SetParamFuncs[par_name](C_node_id, value) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
323 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
324 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
325 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
326 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
327 |
def _GetWebviewConfigurationValue(ctx, WebNode_id, argument): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
328 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
329 |
Callback function, called by the web interface (NevowServer.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
330 |
to fill in the default value of each parameter of the web form |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
331 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
332 |
Note that the real callback function is a dynamically created function that |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
333 |
will simply call this function to do the work. It will also pass the WebNode_id |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
334 |
as a parameter. |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
335 |
""" |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
336 |
try: |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
337 |
return _WebNodeList[WebNode_id]["WebviewConfiguration"][argument.name] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
338 |
except Exception: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
339 |
return "" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
340 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
341 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
342 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
343 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
344 |
def _updateWebInterface(WebNode_id): |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
345 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
346 |
Add/Remove buttons to/from the web interface depending on the current state |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
347 |
- If there is a saved state => add a delete saved state button |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
348 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
349 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
350 |
config_hash = _WebNodeList[WebNode_id]["config_hash"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
351 |
config_name = _WebNodeList[WebNode_id]["config_name"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
352 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
353 |
# Add a "Delete Saved Configuration" button if there is a saved configuration! |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
354 |
if _WebNodeList[WebNode_id]["SavedConfiguration"] is None: |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
355 |
_NS.ConfigurableSettings.delSettings("ModbusConfigDelSaved" + config_hash) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
356 |
else: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
357 |
def __OnButtonDel(**kwargs): |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
358 |
return OnButtonDel(WebNode_id = WebNode_id, **kwargs) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
359 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
360 |
_NS.ConfigurableSettings.addSettings( |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
361 |
"ModbusConfigDelSaved" + config_hash, # name (internal, may not contain spaces, ...) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
362 |
_("Modbus Configuration: ") + config_name, # description (user visible label) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
363 |
[], # fields (empty, no parameters required!) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
364 |
_("Delete Configuration Stored in Persistent Storage"), # button label |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
365 |
__OnButtonDel, # callback |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
366 |
"ModbusConfigParm" + config_hash) # Add after entry xxxx |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
367 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
368 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
369 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
370 |
def OnButtonSave(**kwargs): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
371 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
372 |
Function called when user clicks 'Save' button in web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
373 |
The function will configure the Modbus plugin in the PLC with the values |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
374 |
specified in the web interface. However, values must be validated first! |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
375 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
376 |
Note that this function does not get called directly. The real callback |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
377 |
function is the dynamic __OnButtonSave() function, which will add the |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
378 |
"WebNode_id" argument, and call this function to do the work. |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
379 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
380 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
381 |
#_plcobj.LogMessage("Modbus web server extension::OnButtonSave() Called") |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
382 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
383 |
newConfig = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
384 |
WebNode_id = kwargs.get("WebNode_id", None) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
385 |
WebParamList = _WebNodeList[WebNode_id]["WebParamList"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
386 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
387 |
for par_name, x1, x2, x3 in WebParamList: |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
388 |
value = kwargs.get(par_name, None) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
389 |
if value is not None: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
390 |
newConfig[par_name] = value |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
391 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
392 |
# First check if configuration is OK. |
2658
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
393 |
# Note that this is not currently required, as we use drop down choice menus |
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
394 |
# for baud, parity and sop bits, so the values should always be correct! |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
395 |
#if not _CheckWebConfiguration(newConfig): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
396 |
# return |
2658
fdca999c0c1a
Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents:
2657
diff
changeset
|
397 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
398 |
# store to file the new configuration so that |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
399 |
# we can recoup the configuration the next time the PLC |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
400 |
# has a cold start (i.e. when Beremiz_service.py is retarted) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
401 |
_SetSavedConfiguration(WebNode_id, newConfig) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
402 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
403 |
# Configure PLC with the current Modbus parameters |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
404 |
_SetPLCConfiguration(WebNode_id, newConfig) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
405 |
|
2665
978cf239c689
Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents:
2661
diff
changeset
|
406 |
# Update the viewable configuration |
978cf239c689
Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents:
2661
diff
changeset
|
407 |
# The PLC may have coerced the values on calling _SetPLCConfiguration() |
978cf239c689
Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents:
2661
diff
changeset
|
408 |
# so we do not set it directly to newConfig |
978cf239c689
Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents:
2661
diff
changeset
|
409 |
_WebNodeList[WebNode_id]["WebviewConfiguration"] = _GetPLCConfiguration(WebNode_id) |
978cf239c689
Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents:
2661
diff
changeset
|
410 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
411 |
# File has just been created => Delete button must be shown on web interface! |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
412 |
_updateWebInterface(WebNode_id) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
413 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
414 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
415 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
416 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
417 |
def OnButtonDel(**kwargs): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
418 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
419 |
Function called when user clicks 'Delete' button in web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
420 |
The function will delete the file containing the persistent |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
421 |
Modbus configution |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
422 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
423 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
424 |
WebNode_id = kwargs.get("WebNode_id", None) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
425 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
426 |
# Delete the file |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
427 |
_DelSavedConfiguration(WebNode_id) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
428 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
429 |
# Set the current configuration to the default (hardcoded in C) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
430 |
new_config = _WebNodeList[WebNode_id]["DefaultConfiguration"] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
431 |
_SetPLCConfiguration(WebNode_id, new_config) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
432 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
433 |
#Update the webviewconfiguration |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
434 |
_WebNodeList[WebNode_id]["WebviewConfiguration"] = new_config |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
435 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
436 |
# Reset SavedConfiguration |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
437 |
_WebNodeList[WebNode_id]["SavedConfiguration"] = None |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
438 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
439 |
# File has just been deleted => Delete button on web interface no longer needed! |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
440 |
_updateWebInterface(WebNode_id) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
441 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
442 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
443 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
444 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
445 |
def OnButtonShowCur(**kwargs): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
446 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
447 |
Function called when user clicks 'Show Current PLC Configuration' button in web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
448 |
The function will load the current PLC configuration into the web form |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
449 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
450 |
Note that this function does not get called directly. The real callback |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
451 |
function is the dynamic __OnButtonShowCur() function, which will add the |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
452 |
"WebNode_id" argument, and call this function to do the work. |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
453 |
""" |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
454 |
WebNode_id = kwargs.get("WebNode_id", None) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
455 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
456 |
_WebNodeList[WebNode_id]["WebviewConfiguration"] = _GetPLCConfiguration(WebNode_id) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
457 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
458 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
459 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
460 |
|
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
461 |
def _AddWebNode(C_node_id, node_type, GetParamFuncs, SetParamFuncs): |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
462 |
""" |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
463 |
Load from the compiled code (.so file, aloready loaded into memmory) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
464 |
the configuration parameters of a specific Modbus plugin node. |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
465 |
This function works with both client and server nodes, depending on the |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
466 |
Get/SetParamFunc dictionaries passed to it (either the client or the server |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
467 |
node versions of the Get/Set functions) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
468 |
""" |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
469 |
WebNode_entry = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
470 |
|
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
471 |
# Get the config_name from the C code... |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
472 |
config_name = GetParamFuncs["config_name"](C_node_id) |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
473 |
# Get the addr_type from the C code... |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
474 |
# addr_type will be one of "tcp", "rtu" or "ascii" |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
475 |
addr_type = GetParamFuncs["addr_type" ](C_node_id) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
476 |
# For some operations we cannot use the config name (e.g. filename to store config) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
477 |
# because the user may be using characters that are invalid for that purpose ('/' for |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
478 |
# example), so we create a hash of the config_name, and use that instead. |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
479 |
config_hash = hashlib.md5(config_name).hexdigest() |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
480 |
|
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
481 |
#_plcobj.LogMessage("Modbus web server extension::_AddWebNode("+str(C_node_id)+") config_name="+config_name) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
482 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
483 |
# Add the new entry to the global list |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
484 |
# Note: it is OK, and actually necessary, to do this _before_ seting all the parameters in WebNode_entry |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
485 |
# WebNode_entry will be stored as a reference, so we can later insert parameters at will. |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
486 |
global _WebNodeList |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
487 |
_WebNodeList.append(WebNode_entry) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
488 |
WebNode_id = len(_WebNodeList) - 1 |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
489 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
490 |
# store all WebNode relevant data for future reference |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
491 |
# |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
492 |
# Note that "WebParamList" will reference one of: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
493 |
# - TCPclient_parameters, TCPserver_parameters, RTUclient_parameters, RTUslave_parameters |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
494 |
WebNode_entry["C_node_id" ] = C_node_id |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
495 |
WebNode_entry["config_name" ] = config_name |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
496 |
WebNode_entry["config_hash" ] = config_hash |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
497 |
WebNode_entry["filename" ] = os.path.join(_ModbusConfFiledir, "Modbus_config_" + config_hash + ".json") |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
498 |
WebNode_entry["GetParamFuncs"] = GetParamFuncs |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
499 |
WebNode_entry["SetParamFuncs"] = SetParamFuncs |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
500 |
WebNode_entry["WebParamList" ] = WebParamListDictDict[node_type][addr_type] |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
501 |
WebNode_entry["addr_type" ] = addr_type # 'tcp', 'rtu', or 'ascii' (as returned by C function) |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
502 |
WebNode_entry["node_type" ] = node_type # 'client', 'server' |
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
503 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
504 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
505 |
# Dictionary that contains the Modbus configuration currently being shown |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
506 |
# on the web interface |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
507 |
# This configuration will almost always be identical to the current |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
508 |
# configuration in the PLC (i.e., the current state stored in the |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
509 |
# C variables in the .so file). |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
510 |
# The configuration viewed on the web will only be different to the current |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
511 |
# configuration when the user edits the configuration, and when |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
512 |
# the user asks to save an edited configuration that contains an error. |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
513 |
WebNode_entry["WebviewConfiguration"] = None |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
514 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
515 |
# Upon PLC load, this Dictionary is initialised with the Modbus configuration |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
516 |
# hardcoded in the C file |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
517 |
# (i.e. the configuration inserted in Beremiz IDE when project was compiled) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
518 |
WebNode_entry["DefaultConfiguration"] = _GetPLCConfiguration(WebNode_id) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
519 |
WebNode_entry["WebviewConfiguration"] = WebNode_entry["DefaultConfiguration"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
520 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
521 |
# Dictionary that stores the Modbus configuration currently stored in a file |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
522 |
# Currently only used to decide whether or not to show the "Delete" button on the |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
523 |
# web interface (only shown if "SavedConfiguration" is not None) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
524 |
SavedConfig = _GetSavedConfiguration(WebNode_id) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
525 |
WebNode_entry["SavedConfiguration"] = SavedConfig |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
526 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
527 |
if SavedConfig is not None: |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
528 |
_SetPLCConfiguration(WebNode_id, SavedConfig) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
529 |
WebNode_entry["WebviewConfiguration"] = SavedConfig |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
530 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
531 |
# Define the format for the web form used to show/change the current parameters |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
532 |
# We first declare a dynamic function to work as callback to obtain the default values for each parameter |
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
533 |
# Note: We transform every parameter into a string |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
534 |
# This is not strictly required for parameters of type annotate.Integer that will correctly |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
535 |
# accept the default value as an Integer python object |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
536 |
# This is obviously also not required for parameters of type annotate.String, that are |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
537 |
# always handled as strings. |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
538 |
# However, the annotate.Choice parameters (and all parameters that derive from it, |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
539 |
# sucn as Parity, Baud, etc.) require the default value as a string |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
540 |
# even though we store it as an integer, which is the data type expected |
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
541 |
# by the set_***() C functions in mb_runtime.c |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
542 |
def __GetWebviewConfigurationValue(ctx, argument): |
2657
41c34e7d196d
Modbus plugin web configuration: use drop down choices for baud, parity and stop bits.
Mario de Sousa <msousa@fe.up.pt>
parents:
2656
diff
changeset
|
543 |
return str(_GetWebviewConfigurationValue(ctx, WebNode_id, argument)) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
544 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
545 |
webFormInterface = [(name, web_dtype (label=web_label, default=__GetWebviewConfigurationValue)) |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
546 |
for name, web_label, c_dtype, web_dtype in WebNode_entry["WebParamList"]] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
547 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
548 |
# Configure the web interface to include the Modbus config parameters |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
549 |
def __OnButtonSave(**kwargs): |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
550 |
OnButtonSave(WebNode_id=WebNode_id, **kwargs) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
551 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
552 |
_NS.ConfigurableSettings.addSettings( |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
553 |
"ModbusConfigParm" + config_hash, # name (internal, may not contain spaces, ...) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
554 |
_("Modbus Configuration: ") + config_name, # description (user visible label) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
555 |
webFormInterface, # fields |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
556 |
_("Save Configuration to Persistent Storage"), # button label |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
557 |
__OnButtonSave) # callback |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
558 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
559 |
# Add a "View Current Configuration" button |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
560 |
def __OnButtonShowCur(**kwargs): |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
561 |
OnButtonShowCur(WebNode_id=WebNode_id, **kwargs) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
562 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
563 |
_NS.ConfigurableSettings.addSettings( |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
564 |
"ModbusConfigViewCur" + config_hash, # name (internal, may not contain spaces, ...) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
565 |
_("Modbus Configuration: ") + config_name, # description (user visible label) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
566 |
[], # fields (empty, no parameters required!) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
567 |
_("Show Current PLC Configuration"), # button label |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
568 |
__OnButtonShowCur) # callback |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
569 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
570 |
# Add the Delete button to the web interface, if required |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
571 |
_updateWebInterface(WebNode_id) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
572 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
573 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
574 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
575 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
576 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
577 |
def OnLoadPLC(): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
578 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
579 |
Callback function, called (by PLCObject.py) when a new PLC program |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
580 |
(i.e. XXX.so file) is transfered to the PLC runtime |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
581 |
and loaded into memory |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
582 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
583 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
584 |
#_plcobj.LogMessage("Modbus web server extension::OnLoadPLC() Called...") |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
585 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
586 |
if _plcobj.PLClibraryHandle is None: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
587 |
# PLC was loaded but we don't have access to the library of compiled code (.so lib)? |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
588 |
# Hmm... This shold never occur!! |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
589 |
return |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
590 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
591 |
# Get the number of Modbus Client and Servers (Modbus plugin) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
592 |
# configured in the currently loaded PLC project (i.e., the .so file) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
593 |
# If the "__modbus_plugin_client_node_count" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
594 |
# or the "__modbus_plugin_server_node_count" C variables |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
595 |
# are not present in the .so file we conclude that the currently loaded |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
596 |
# PLC does not have the Modbus plugin included (situation (2b) described above init()) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
597 |
try: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
598 |
client_count = ctypes.c_int.in_dll(_plcobj.PLClibraryHandle, "__modbus_plugin_client_node_count").value |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
599 |
server_count = ctypes.c_int.in_dll(_plcobj.PLClibraryHandle, "__modbus_plugin_server_node_count").value |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
600 |
except Exception: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
601 |
# Loaded PLC does not have the Modbus plugin => nothing to do |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
602 |
# (i.e. do _not_ configure and make available the Modbus web interface) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
603 |
return |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
604 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
605 |
if client_count < 0: client_count = 0 |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
606 |
if server_count < 0: server_count = 0 |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
607 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
608 |
if (client_count == 0) and (server_count == 0): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
609 |
# The Modbus plugin in the loaded PLC does not have any client and servers configured |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
610 |
# => nothing to do (i.e. do _not_ configure and make available the Modbus web interface) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
611 |
return |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
612 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
613 |
# Map the get/set functions (written in C code) we will be using to get/set the configuration parameters |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
614 |
# Will contain references to the C functions (implemented in beremiz/modbus/mb_runtime.c) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
615 |
GetClientParamFuncs = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
616 |
SetClientParamFuncs = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
617 |
GetServerParamFuncs = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
618 |
SetServerParamFuncs = {} |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
619 |
|
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
620 |
for name, web_label, c_dtype, web_dtype in TCPclient_parameters + RTUclient_parameters + General_parameters: |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
621 |
ParamFuncName = "__modbus_get_ClientNode_" + name |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
622 |
GetClientParamFuncs[name] = getattr(_plcobj.PLClibraryHandle, ParamFuncName) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
623 |
GetClientParamFuncs[name].restype = c_dtype |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
624 |
GetClientParamFuncs[name].argtypes = [ctypes.c_int] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
625 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
626 |
for name, web_label, c_dtype, web_dtype in TCPclient_parameters + RTUclient_parameters: |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
627 |
ParamFuncName = "__modbus_set_ClientNode_" + name |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
628 |
SetClientParamFuncs[name] = getattr(_plcobj.PLClibraryHandle, ParamFuncName) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
629 |
SetClientParamFuncs[name].restype = None |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
630 |
SetClientParamFuncs[name].argtypes = [ctypes.c_int, c_dtype] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
631 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
632 |
for name, web_label, c_dtype, web_dtype in TCPserver_parameters + RTUslave_parameters + General_parameters: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
633 |
ParamFuncName = "__modbus_get_ServerNode_" + name |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
634 |
GetServerParamFuncs[name] = getattr(_plcobj.PLClibraryHandle, ParamFuncName) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
635 |
GetServerParamFuncs[name].restype = c_dtype |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
636 |
GetServerParamFuncs[name].argtypes = [ctypes.c_int] |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
637 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
638 |
for name, web_label, c_dtype, web_dtype in TCPserver_parameters + RTUslave_parameters: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
639 |
ParamFuncName = "__modbus_set_ServerNode_" + name |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
640 |
SetServerParamFuncs[name] = getattr(_plcobj.PLClibraryHandle, ParamFuncName) |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
641 |
SetServerParamFuncs[name].restype = None |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
642 |
SetServerParamFuncs[name].argtypes = [ctypes.c_int, c_dtype] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
643 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
644 |
for node_id in range(client_count): |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
645 |
_AddWebNode(node_id, "client" ,GetClientParamFuncs, SetClientParamFuncs) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
646 |
|
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
647 |
for node_id in range(server_count): |
2656
049b919b7505
Modbus plugin web configuration: save node type and addr type to persistant storage
Mario de Sousa <msousa@fe.up.pt>
parents:
2655
diff
changeset
|
648 |
_AddWebNode(node_id, "server", GetServerParamFuncs, SetServerParamFuncs) |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
649 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
650 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
651 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
652 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
653 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
654 |
def OnUnLoadPLC(): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
655 |
""" |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
656 |
Callback function, called (by PLCObject.py) when a PLC program is unloaded from memory |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
657 |
""" |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
658 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
659 |
#_plcobj.LogMessage("Modbus web server extension::OnUnLoadPLC() Called...") |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
660 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
661 |
# Delete the Modbus specific web interface extensions |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
662 |
# (Safe to ask to delete, even if it has not been added!) |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
663 |
global _WebNodeList |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
664 |
for WebNode_entry in _WebNodeList: |
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
665 |
config_hash = WebNode_entry["config_hash"] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
666 |
_NS.ConfigurableSettings.delSettings("ModbusConfigParm" + config_hash) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
667 |
_NS.ConfigurableSettings.delSettings("ModbusConfigViewCur" + config_hash) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
668 |
_NS.ConfigurableSettings.delSettings("ModbusConfigDelSaved" + config_hash) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
669 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
670 |
# Dele all entries... |
2655
d2b2ee04bfa1
Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents:
2654
diff
changeset
|
671 |
_WebNodeList = [] |
2654
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
672 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
673 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
674 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
675 |
# The Beremiz_service.py service, along with the integrated web server it launches |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
676 |
# (i.e. Nevow web server, in runtime/NevowServer.py), will go through several states |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
677 |
# once started: |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
678 |
# (1) Web server is started, but no PLC is loaded |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
679 |
# (2) PLC is loaded (i.e. the PLC compiled code is loaded) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
680 |
# (a) The loaded PLC includes the Modbus plugin |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
681 |
# (b) The loaded PLC does not have the Modbus plugin |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
682 |
# |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
683 |
# During (1) and (2a): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
684 |
# we configure the web server interface to not have the Modbus web configuration extension |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
685 |
# During (2b) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
686 |
# we configure the web server interface to include the Modbus web configuration extension |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
687 |
# |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
688 |
# PS: reference to the pyroserver (i.e., the server object of Beremiz_service.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
689 |
# (NOTE: PS.plcobj is a reference to PLCObject.py) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
690 |
# NS: reference to the web server (i.e. the NevowServer.py module) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
691 |
# WorkingDir: the directory on which Beremiz_service.py is running, and where |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
692 |
# all the files downloaded to the PLC get stored, including |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
693 |
# the .so file with the compiled C generated code |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
694 |
def init(plcobj, NS, WorkingDir): |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
695 |
#PS.plcobj.LogMessage("Modbus web server extension::init(PS, NS, " + WorkingDir + ") Called") |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
696 |
global _WorkingDir |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
697 |
_WorkingDir = WorkingDir |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
698 |
global _plcobj |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
699 |
_plcobj = plcobj |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
700 |
global _NS |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
701 |
_NS = NS |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
702 |
|
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
703 |
_plcobj.RegisterCallbackLoad ("Modbus_Settins_Extension", OnLoadPLC) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
704 |
_plcobj.RegisterCallbackUnLoad("Modbus_Settins_Extension", OnUnLoadPLC) |
7575050a80c5
Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff
changeset
|
705 |
OnUnLoadPLC() # init is called before the PLC gets loaded... so we make sure we have the correct state |