modbus/web_settings.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 12 Mar 2023 00:51:53 +0100
branchwxPython4
changeset 3746 41be039fbb8c
parent 3743 5450dd9e9370
child 3869 b722c800b6c7
permissions -rw-r--r--
IDE: fix again ruberband with gtk3.

DC logical functions are now disabled when using GTK3.
Apparently using XOR was still having an effect.
Use regular black pen with no logical funciton instead.
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
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
    45
import runtime.NevowServer as NS
2654
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
# 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
    48
# Should be a directory that does not get wiped on reboot!
2673
80e7eb44cab4 BACnet and Modbus : fix configuration storage directory
Edouard Tisserant
parents: 2672
diff changeset
    49
_ModbusConfFiledir = WorkingDir
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    50
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    51
# 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
    52
# One WebNode each for:
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    53
#   - Modbus TCP client 
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    54
#   - Modbus TCP server
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    55
#   - Modbus RTU client
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    56
#   - Modbus RTU slave
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    57
# 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
    58
# 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
    59
# 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
    60
_WebNodeList = []
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    61
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    62
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
    63
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
    64
5f48d5e60a81 Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2665
diff changeset
    65
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
    66
    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
    67
        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
    68
5f48d5e60a81 Modbus plugin, web interface: strip leading and trailing spaces from string parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2665
diff changeset
    69
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
    70
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
    71
    _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
    72
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
    73
    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
    74
        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
    75
    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
    76
        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
    77
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
    78
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
    79
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
    80
    _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
    81
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
    82
    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
    83
        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
    84
    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
    85
        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
    86
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
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
class MB_Parity(annotate.Choice):
2660
ddbf029f5682 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2658
diff changeset
    89
    # For more info on what this class really does, have a look at the code in
ddbf029f5682 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2658
diff changeset
    90
    # file twisted/nevow/annotate.py
ddbf029f5682 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2658
diff changeset
    91
    # grab this code from $git clone https://github.com/twisted/nevow/
ddbf029f5682 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2658
diff changeset
    92
    # 
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
    93
    # 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
    94
    # 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
    95
    _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
    96
    _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
    97
    
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
    def choice_to_label(self, key):
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
    99
        #PLCObject.LogMessage("Modbus web server extension::choice_to_label()  " + str(key))
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
   100
        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
   101
    
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
   102
    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
   103
        """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
   104
        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
   105
        """
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
        # 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
   107
        # 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
   108
        # (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
   109
        #
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
        # 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
   111
        # 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
   112
        # 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
   113
        # 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
   114
        # 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
   115
        # 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
   116
        #
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   117
        #PLCObject.LogMessage("Modbus web server extension::coerce  " + val )
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
   118
        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
   119
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
    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
   121
        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
   122
                                 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
   123
                                 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
   124
                                 *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
   125
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
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   127
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   128
# The parameter coerce functions referenced in the TCPclient_parameters etc. lists.
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   129
# These functions check wether the parameter has a legal value (i.e. they validate the parameter),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   130
# and if not changes it to the closest legal value (i.e. coerces the parameter value to a legal value)
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   131
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   132
def _coerce_comm_period(value):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   133
    # Period may not be negative value
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   134
    if (value < 0):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   135
        value = 0
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   136
    return value
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   137
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   138
def _coerce_req_delay(value):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   139
    # Request delay may not be negative value
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   140
    # (i.e. delay between any two consecutive requests sent by a Beremiz RTU master or TCP client)
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   141
    if (value < 0):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   142
        value = 0
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   143
    return value
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   144
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   145
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   146
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   147
# 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
   148
# 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
   149
#
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   150
# The annotate type entry is used to tell the web server the type of data entry widget to use.
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   151
# (see the file twisted/nevow/formless/annotate.py for list of options)
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   152
# Unfortunately an unsigned integer option does not exist.
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   153
General_parameters = [
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   154
    #    param. name       label                        ctype type         annotate type            Coerce
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   155
    # (C code var name)   (used on web interface)      (C data type)       (web data type)          function
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   156
    #                                                                      (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
   157
    #                                                                       annotate.Integer, ...)
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   158
    ("config_name"      , _("")                      , ctypes.c_char_p,    annotate.String,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   159
    ("addr_type"        , _("")                      , ctypes.c_char_p,    annotate.String,         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
   160
    ]                                                                      
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   161
                                                                           
2661
9d08e3bba629 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2660
diff changeset
   162
# Parameters we will need to get from the C code, and that _will_ be shown
9d08e3bba629 add comment
Mario de Sousa <msousa@fe.up.pt>
parents: 2660
diff changeset
   163
# 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
   164
TCPclient_parameters = [                                                   
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   165
    #    param. name       label                        ctype type         annotate type            Coerce
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   166
    # (C code var name)   (used on web interface)      (C data type)       (web data type)          function
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   167
    #                                                                      (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
   168
    #                                                                       annotate.Integer, ...)
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   169
    ("host"             , _("Remote IP Address")     , ctypes.c_char_p,    MB_StrippedString,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   170
    ("port"             , _("Remote Port Number")    , ctypes.c_char_p,    MB_StrippedString,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   171
    ("comm_period"      , _("Invocation Rate (ms)")  , ctypes.c_ulonglong, annotate.Integer ,         _coerce_comm_period),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   172
    ("req_delay"        , _("Request Delay (ms)")    , ctypes.c_ulonglong, annotate.Integer ,         _coerce_req_delay)
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   173
    ]
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   175
RTUclient_parameters = [                                                   
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   176
    #    param. name       label                        ctype type         annotate type            Coerce
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   177
    # (C code var name)   (used on web interface)      (C data type)       (web data type)          function
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   178
    #                                                                      (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
   179
    #                                                                       annotate.Integer, ...)
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   180
    ("device"           , _("Serial Port")           , ctypes.c_char_p,    MB_StrippedString,        None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   181
    ("baud"             , _("Baud Rate")             , ctypes.c_int,       MB_Baud         ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   182
    ("parity"           , _("Parity")                , ctypes.c_int,       MB_Parity       ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   183
    ("stop_bits"        , _("Stop Bits")             , ctypes.c_int,       MB_StopBits     ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   184
    ("comm_period"      , _("Invocation Rate (ms)")  , ctypes.c_ulonglong, annotate.Integer,         _coerce_comm_period),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   185
    ("req_delay"        , _("Request Delay (ms)")    , ctypes.c_ulonglong, annotate.Integer,         _coerce_req_delay)
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   186
    ]
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   187
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   188
TCPserver_parameters = [                                                   
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   189
    #    param. name       label                        ctype type         annotate type            Coerce
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   190
    # (C code var name)   (used on web interface)      (C data type)       (web data type)          function
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   191
    #                                                                      (annotate.String,
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   192
    #                                                                       annotate.Integer, ...)
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   193
    ("host"             , _("Local IP Address")      , ctypes.c_char_p,    MB_StrippedString,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   194
    ("port"             , _("Local Port Number")     , ctypes.c_char_p,    MB_StrippedString,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   195
    ("slave_id"         , _("Slave ID")              , ctypes.c_ubyte,     annotate.Integer ,         None)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   196
    ]
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   197
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   198
RTUslave_parameters = [                                                   
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   199
    #    param. name       label                        ctype type         annotate type            Coerce
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   200
    # (C code var name)   (used on web interface)      (C data type)       (web data type)          function
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   201
    #                                                                      (annotate.String,
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   202
    #                                                                       annotate.Integer, ...)
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   203
    ("device"           , _("Serial Port")           , ctypes.c_char_p,    MB_StrippedString,        None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   204
    ("baud"             , _("Baud Rate")             , ctypes.c_int,       MB_Baud         ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   205
    ("parity"           , _("Parity")                , ctypes.c_int,       MB_Parity       ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   206
    ("stop_bits"        , _("Stop Bits")             , ctypes.c_int,       MB_StopBits     ,         None),
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   207
    ("slave_id"         , _("Slave ID")              , ctypes.c_ubyte,     annotate.Integer,         None)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   208
    ]
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   209
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   210
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
   211
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
   212
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   213
# 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
   214
# 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
   215
# __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
   216
# __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
   217
# 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
   218
_client_WebParamListDict = {}
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   219
_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
   220
_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
   221
_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
   222
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   223
_server_WebParamListDict = {}
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   224
_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
   225
_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
   226
_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
   227
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
   228
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
   229
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
   230
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
   231
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   232
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
   233
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
   234
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   235
def _SetModbusSavedConfiguration(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
   236
    """ Stores a dictionary in a persistant file containing the Modbus parameter configuration """
2675
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   237
    WebNode_entry = _WebNodeList[WebNode_id]
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   238
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   239
    if WebNode_entry["DefaultConfiguration"] == newConfig:
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   240
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   241
        _DelModbusSavedConfiguration(WebNode_id)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   242
        WebNode_entry["ModbusSavedConfiguration"] = None
2675
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   243
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   244
    else:
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   245
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   246
        # Add the addr_type and node_type to the data that will be saved to file
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   247
        # This allows us to confirm the saved data contains the correct addr_type
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   248
        # when loading from file
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   249
        save_info = {}
2690
4de6a587f7f9 MODBUS: Fix saving of websettings.
Edouard Tisserant
parents: 2686
diff changeset
   250
        save_info["addr_type"] = WebNode_entry["addr_type"]
2675
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   251
        save_info["node_type"] = WebNode_entry["node_type"]
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   252
        save_info["config"   ] = 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
   253
        
2675
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   254
        filename = WebNode_entry["filename"]
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   255
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   256
        with open(os.path.realpath(filename), 'w') as f:
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   257
            json.dump(save_info, f, sort_keys=True, indent=4)
3ca5611d6308 Modbus: Delete stored configuration when identical to default configuration.
Edouard Tisserant
parents: 2673
diff changeset
   258
            
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   259
        WebNode_entry["ModbusSavedConfiguration"] = newConfig
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   260
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   261
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   262
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   263
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   264
def _DelModbusSavedConfiguration(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
   265
    """ 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
   266
    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
   267
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   268
    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
   269
        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
   270
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   271
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   272
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   273
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   274
def _GetModbusSavedConfiguration(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
   275
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   276
    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
   277
    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
   278
    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
   279
    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
   280
    """
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   281
    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
   282
    try:
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 os.path.isfile(filename):
2690
4de6a587f7f9 MODBUS: Fix saving of websettings.
Edouard Tisserant
parents: 2686
diff changeset
   284
        save_info = json.load(open(os.path.realpath(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
   285
    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
   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
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
   288
    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
   289
        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
   290
    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
   291
        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
   292
    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
   293
        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
   294
    
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
   295
    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
   296
    
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   297
    #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
   298
    #    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
   299
    #else:
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   300
    #    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
   301
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   302
    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
   303
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   304
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   305
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   306
def _GetModbusPLCConfiguration(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
   307
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   308
    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
   309
    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
   310
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   311
    current_config = {}
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   312
    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
   313
    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
   314
    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
   315
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   316
    for WebParamListEntry in WebParamList:
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   317
        par_name = WebParamListEntry[0]
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   318
        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
   319
        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
   320
            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
   321
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   322
    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
   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
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   326
def _SetModbusPLCConfiguration(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
   327
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   328
    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
   329
    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
   330
    """
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   331
    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
   332
    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
   333
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
    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
   335
        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
   336
        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
   337
            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
   338
            
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   339
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
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   342
def _GetModbusWebviewConfigurationValue(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
   343
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   344
    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
   345
    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
   346
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   347
    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
   348
    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
   349
    as a parameter.
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   350
    """    
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   351
    try:
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   352
        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
   353
    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
   354
        return ""
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   355
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   356
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   357
def _CoerceConfigurationValues(WebNode_id, config):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   358
    """
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   359
    Coerces any incorrect value in the passed configuration
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   360
    to the nearest correct value.
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   361
    For example, negative times in delay paramater are changed to 0, etc...
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   362
    """
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   363
    CoerceParamFuncs  = _WebNodeList[WebNode_id]["CoerceParamFuncs"]
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   364
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   365
    for par_name in config:
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   366
        CoerceFunction = CoerceParamFuncs[par_name]
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   367
        if (config[par_name] is not None) and (CoerceFunction is not None):
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   368
            config[par_name] = CoerceFunction(config[par_name])
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   369
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   370
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   371
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   372
def OnModbusButtonSave(**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
   373
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   374
    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
   375
    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
   376
    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
   377
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   378
    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
   379
    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
   380
    "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
   381
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   382
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   383
    #PLCObject.LogMessage("Modbus web server extension::OnModbusButtonSave()  Called")
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   384
    
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   385
    newConfig    = {}
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   386
    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
   387
    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
   388
    
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   389
    for WebParamListEntry in WebParamList:
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   390
        par_name = WebParamListEntry[0]
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   391
        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
   392
        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
   393
            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
   394
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   395
    # First check if configuration is OK.
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   396
    # Note that this is currently not really required for most of the parameters,
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   397
    # as we use drop down choice menus for baud, parity and sop bits
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   398
    # (so these values should always be correct!).
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   399
    # The timing properties (period in ms, delays in ms, etc.)
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   400
    # do however need to be validated as the web interface does not
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   401
    # enforce any limits on the values (e.g., they must be positive values).
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   402
    # NOTE: It would be confusing for the user if we simply refuse to make the
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   403
    # requested changes without giving any feedback that the changes were not applied,
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   404
    # and why they were refused (i.e. at the moment the web page does not have
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   405
    # any pop-up windows or special messages for that).
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   406
    # That is why instead of returning without making the changes in case of error,
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   407
    # we instead opt to change the requested configuration to the closest valid values
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   408
    # and apply that instead. The user gets feedback on the applied values as these get
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   409
    # shown on the web interface.
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   410
    #
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   411
    # TODO: Check IP address, Port number, etc...
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   412
    _CoerceConfigurationValues(WebNode_id, newConfig)
2658
fdca999c0c1a Modbus plugin web configuration: fix comments, and delete un-used code
Mario de Sousa <msousa@fe.up.pt>
parents: 2657
diff changeset
   413
    
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   414
    # 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
   415
    # 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
   416
    # has a cold start (i.e. when Beremiz_service.py is retarted)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   417
    _SetModbusSavedConfiguration(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
   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
    # Configure PLC with the current Modbus parameters
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   420
    _SetModbusPLCConfiguration(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
   421
2665
978cf239c689 Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents: 2661
diff changeset
   422
    # Update the viewable configuration
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   423
    # The PLC may have coerced the values on calling _SetModbusPLCConfiguration()
2665
978cf239c689 Modbus plugin web interface: show the keyword "#ANY#" on TCP servers
Mario de Sousa <msousa@fe.up.pt>
parents: 2661
diff changeset
   424
    # so we do not set it directly to newConfig
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   425
    _WebNodeList[WebNode_id]["WebviewConfiguration"] = _GetModbusPLCConfiguration(WebNode_id)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   426
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   427
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   428
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   429
def OnModbusButtonReset(**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
   430
    """
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   431
    Function called when user clicks 'Reset' button in 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
   432
    The function will delete the file containing the persistent
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   433
    Modbus configution. More specifically, reset to the configuration
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   434
    hardcoded in the source code (<=> configuration specified
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   435
    in Beremiz IDE).
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   436
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   437
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   438
    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
   439
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   440
    # Delete the file
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   441
    _DelModbusSavedConfiguration(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
   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
    # 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
   444
    new_config = _WebNodeList[WebNode_id]["DefaultConfiguration"]
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   445
    _SetModbusPLCConfiguration(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
   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
    #Update the webviewconfiguration
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   448
    _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
   449
    
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   450
    # Reset ModbusSavedConfiguration
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   451
    _WebNodeList[WebNode_id]["ModbusSavedConfiguration"] = 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
   452
    
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   453
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   454
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
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   457
def _AddWebNode(C_node_id, node_type, GetParamFuncs, SetParamFuncs, CoerceParamFuncs):
2655
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
    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
   460
    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
   461
    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
   462
    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
   463
    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
   464
    """
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   465
    WebNode_entry = {}
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   466
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
   467
    # 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
   468
    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
   469
    # 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
   470
    # 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
   471
    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
   472
    # 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
   473
    # 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
   474
    # 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
   475
    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
   476
    
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   477
    #PLCObject.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
   478
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   479
    # 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
   480
    # 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
   481
    #       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
   482
    global _WebNodeList
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   483
    _WebNodeList.append(WebNode_entry)
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   484
    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
   485
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   486
    # 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
   487
    #
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   488
    # 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
   489
    #  - 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
   490
    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
   491
    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
   492
    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
   493
    WebNode_entry["filename"     ] = os.path.join(_ModbusConfFiledir, "Modbus_config_" + config_hash + ".json")
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
   494
    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
   495
    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
   496
    WebNode_entry["node_type"    ] = node_type  # 'client', 'server'
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   497
    WebNode_entry["GetParamFuncs"] = GetParamFuncs
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   498
    WebNode_entry["SetParamFuncs"] = SetParamFuncs
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   499
    WebNode_entry["CoerceParamFuncs"] = CoerceParamFuncs
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
        
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   501
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   502
    # 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
   503
    # 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
   504
    # 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
   505
    # 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
   506
    # 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
   507
    # 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
   508
    # 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
   509
    # 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
   510
    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
   511
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   512
    # 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
   513
    # 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
   514
    # (i.e. the configuration inserted in Beremiz IDE when project was compiled)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   515
    WebNode_entry["DefaultConfiguration"] = _GetModbusPLCConfiguration(WebNode_id)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   516
    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
   517
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   518
    # 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
   519
    # Currently only used to decide whether or not to show the "Delete" button on the
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   520
    # web interface (only shown if "ModbusSavedConfiguration" is not None)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   521
    SavedConfig = _GetModbusSavedConfiguration(WebNode_id)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   522
    WebNode_entry["ModbusSavedConfiguration"] = 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
   523
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   524
    if SavedConfig is not None:
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   525
        _SetModbusPLCConfiguration(WebNode_id, SavedConfig)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   526
        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
   527
        
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   528
    # 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
   529
    # 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
   530
    # 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
   531
    #       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
   532
    #           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
   533
    #       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
   534
    #           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
   535
    #       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
   536
    #           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
   537
    #           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
   538
    #           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
   539
    def __GetWebviewConfigurationValue(ctx, argument):
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   540
        return str(_GetModbusWebviewConfigurationValue(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
   541
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   542
    webFormInterface = [(name, web_dtype (label=web_label, default=__GetWebviewConfigurationValue)) 
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   543
                    for name, web_label, c_dtype, web_dtype, coerce_function 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
   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
    # 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
   546
    def __OnButtonSave(**kwargs):
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   547
        OnModbusButtonSave(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
   548
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   549
    WebSettings = NS.newExtensionSetting("Modbus #"+ str(WebNode_id), config_hash)
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   550
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   551
    WebSettings.addSettings(
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   552
        "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
   553
        _("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
   554
        webFormInterface,                              # fields
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   555
        _("Apply"), # button label
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   556
        __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
   557
    
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   558
    def __OnButtonReset(**kwargs):
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   559
        return OnModbusButtonReset(WebNode_id = WebNode_id, **kwargs)
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   560
            
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   561
    def getModbusConfigStatus():
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   562
        if WebNode_entry["WebviewConfiguration"] == WebNode_entry["DefaultConfiguration"]:
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   563
            return "Unchanged"
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   564
        return "Modified"
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   565
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   566
    WebSettings.addSettings(
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   567
        "ModbusConfigDelSaved"      + config_hash,  # name (internal, may not contain spaces, ...)
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   568
        _("Modbus Configuration: ") + config_name,  # description (user visible label)
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   569
        [ ("status",
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   570
           annotate.String(label=_("Current state"),
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   571
                           immutable=True,
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   572
                           default=lambda *k:getModbusConfigStatus())),
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   573
        ],                                       # fields  (empty, no parameters required!)
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   574
        _("Reset"), # button label
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   575
        __OnButtonReset)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   576
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   577
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
2703
32ffdb32b14e Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents: 2691
diff changeset
   580
def _runtime_%(location_str)s_modbus_websettings_init():
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   581
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   582
    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
   583
    (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
   584
    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
   585
    """
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   586
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   587
    #PLCObject.LogMessage("Modbus web server extension::OnLoadPLC() Called...")
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   588
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   589
    if PLCObject.PLClibraryHandle 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
   590
        # 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
   591
        # 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
   592
        return  
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   593
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   594
    # 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
   595
    # 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
   596
    # 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
   597
    # 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
   598
    # 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
   599
    # 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
   600
    try:
2676
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   601
        # XXX TODO : stop reading from PLC .so file. This code is template code
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   602
        #            that can use modbus extension build data, such as client node count.
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   603
        client_count = ctypes.c_int.in_dll(PLCObject.PLClibraryHandle, "__modbus_plugin_client_node_count").value
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   604
        server_count = ctypes.c_int.in_dll(PLCObject.PLClibraryHandle, "__modbus_plugin_server_node_count").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
   605
    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
   606
        # 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
   607
        #   (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
   608
        return
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   609
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   610
    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
   611
    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
   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
    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
   614
        # 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
   615
        #  => 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
   616
        return
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   617
    
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   618
    # 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
   619
    # 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
   620
    GetClientParamFuncs = {}
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   621
    GetServerParamFuncs = {}
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   622
    SetClientParamFuncs = {}
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   623
    SetServerParamFuncs = {}
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   624
    CoerceClientParamFuncs = {}
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   625
    CoerceServerParamFuncs = {}
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   626
2676
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   627
    # XXX TODO : stop reading from PLC .so file. This code is template code
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   628
    #            that can use modbus extension build data
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   629
    for name, web_label, c_dtype, web_dtype, coerce_function 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
   630
        ParamFuncName                      = "__modbus_get_ClientNode_" + name        
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   631
        GetClientParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   632
        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
   633
        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
   634
        
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   635
    for name, web_label, c_dtype, web_dtype, coerce_function 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
   636
        ParamFuncName                      = "__modbus_set_ClientNode_" + name
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   637
        SetClientParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   638
        SetClientParamFuncs[name].restype  = None
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   639
        SetClientParamFuncs[name].argtypes = [ctypes.c_int, c_dtype]
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   640
        CoerceClientParamFuncs[name]       = coerce_function
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   641
2676
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   642
    # XXX TODO : stop reading from PLC .so file. This code is template code
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2675
diff changeset
   643
    #            that can use modbus extension build data
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   644
    for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters + General_parameters:
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   645
        ParamFuncName                      = "__modbus_get_ServerNode_" + name        
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   646
        GetServerParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   647
        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
   648
        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
   649
        
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   650
    for name, web_label, c_dtype, web_dtype, coerce_function in TCPserver_parameters + RTUslave_parameters:
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   651
        ParamFuncName                      = "__modbus_set_ServerNode_" + name
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   652
        SetServerParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, ParamFuncName)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   653
        SetServerParamFuncs[name].restype  = None
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   654
        SetServerParamFuncs[name].argtypes = [ctypes.c_int, c_dtype]
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   655
        CoerceServerParamFuncs[name]       = coerce_function
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   656
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   657
    for node_id in range(client_count):
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   658
        _AddWebNode(node_id, "client" ,GetClientParamFuncs, SetClientParamFuncs, CoerceClientParamFuncs)
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   659
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   660
    for node_id in range(server_count):
3743
5450dd9e9370 Modbus web configuration: add check for valid delay and period parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 3733
diff changeset
   661
        _AddWebNode(node_id, "server", GetServerParamFuncs, SetServerParamFuncs, CoerceServerParamFuncs)
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   662
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   663
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   664
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   665
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   666
2703
32ffdb32b14e Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents: 2691
diff changeset
   667
def _runtime_%(location_str)s_modbus_websettings_cleanup():
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   668
    """
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   669
    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
   670
    """
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   671
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2666
diff changeset
   672
    #PLCObject.LogMessage("Modbus web server extension::OnUnLoadPLC() Called...")
2654
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
    # 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
   675
    # (Safe to ask to delete, even if it has not been added!)
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   676
    global _WebNodeList
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   677
    for index, WebNode_entry in enumerate(_WebNodeList):
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   678
        config_hash = WebNode_entry["config_hash"]
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   679
        NS.removeExtensionSetting(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
   680
        
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   681
    # Dele all entries...
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   682
    _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
   683