connectors/PYRO/__init__.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 28 Mar 2017 19:48:51 +0300
changeset 1670 cd03b8432541
parent 1595 b3cc68dd037d
child 1731 6ebd9c40b2be
permissions -rwxr-xr-x
enable to write SFC transition in IL

This commit reverts previous commit 3f3d97be9a9f.
Because the fix for the matiec problem is already upstream
(https://bitbucket.org/mjsousa/matiec/commits/ce026aee03e00c0790948a18bd7b35805457da81)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     3
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     8
#
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
     9
# See COPYING file for copyrights details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    10
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    14
# of the License, or (at your option) any later version.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    15
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    16
# This program is distributed in the hope that it will be useful,
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    19
# GNU General Public License for more details.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    20
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1455
diff changeset
    24
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    25
import Pyro
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    26
import Pyro.core
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    27
import Pyro.util
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
from Pyro.errors import PyroError
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    29
import traceback
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
from time import sleep
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
    31
import copy
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    32
import socket
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    33
service_type = '_PYRO._tcp.local.'
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    34
import os.path
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    35
# this module attribute contains a list of DNS-SD (Zeroconf) service types
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
    36
# supported by this connector confnode.
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    37
#
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    38
# for connectors that do not support DNS-SD, this attribute can be omitted
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    39
# or set to an empty list.
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 361
diff changeset
    40
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
    41
def PYRO_connector_factory(uri, confnodesroot):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    42
    """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    43
    This returns the connector to Pyro style PLCobject
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    44
    """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    45
    confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    46
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    47
    servicetype, location = uri.split("://")
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    48
    if servicetype == "PYROS":
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    49
        schemename = "PYROLOCSSL"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    50
        # Protect against name->IP substitution in Pyro3
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    51
        Pyro.config.PYRO_DNS_URI = True
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    52
        # Beware Pyro lib need str path, not unicode
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    53
        # don't rely on PYRO_STORAGE ! see documentation
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    54
        Pyro.config.PYROSSL_CERTDIR = os.path.abspath(str(confnodesroot.ProjectPath) + '/certs')
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    55
        if not os.path.exists(Pyro.config.PYROSSL_CERTDIR):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    56
            confnodesroot.logger.write_error(
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    57
                'Error : the directory %s is missing for SSL certificates (certs_dir).'
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    58
                'Please fix it in your project.\n' % Pyro.config.PYROSSL_CERTDIR)
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    59
            return None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    60
        else:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    61
            confnodesroot.logger.write(_("PYRO using certificates in '%s' \n")
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    62
                                       % (Pyro.config.PYROSSL_CERTDIR))
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    63
        Pyro.config.PYROSSL_CERT = "client.crt"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    64
        Pyro.config.PYROSSL_KEY = "client.key"
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    65
        # Ugly Monkey Patching
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    66
        def _gettimeout(self):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    67
            return self.timeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    68
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    69
        def _settimeout(self, timeout):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    70
            self.timeout = timeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    71
        from M2Crypto.SSL import Connection
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    72
        Connection.timeout = None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    73
        Connection.gettimeout = _gettimeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    74
        Connection.settimeout = _settimeout
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    75
        # M2Crypto.SSL.Checker.WrongHost: Peer certificate commonName does not
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    76
        # match host, expected 127.0.0.1, got server
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    77
        Connection.clientPostConnectionCheck = None
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    78
    else:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    79
        schemename = "PYROLOC"
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    80
    if location.find(service_type) != -1:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    81
        try:
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    82
            from util.Zeroconf import Zeroconf
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    83
            r = Zeroconf()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    84
            i = r.getServiceInfo(service_type, location)
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    85
            if i is None:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    86
                raise Exception("'%s' not found" % location)
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    87
            ip = str(socket.inet_ntoa(i.getAddress()))
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    88
            port = str(i.getPort())
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    89
            newlocation = ip + ':' + port
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    90
            confnodesroot.logger.write(_("'{a1}' is located at {a2}\n").format(a1 = location, a2 = newlocation))
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    91
            location = newlocation
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    92
            r.close()
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    93
        except Exception, msg:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    94
            confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n") % location)
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    95
            confnodesroot.logger.write_error(traceback.format_exc())
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 733
diff changeset
    96
            return None
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
    97
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    98
    # Try to get the proxy object
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
    99
    try:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   100
        RemotePLCObjectProxy = Pyro.core.getAttrProxyForURI(schemename + "://" + location + "/PLCObject")
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   101
    except Exception, msg:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   102
        confnodesroot.logger.write_error(_("Connection to '%s' failed.\n") % location)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   103
        confnodesroot.logger.write_error(traceback.format_exc())
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   104
        return None
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   105
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   106
    def PyroCatcher(func, default=None):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   107
        """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   108
        A function that catch a Pyro exceptions, write error to logger
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   109
        and return default value when it happen
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   110
        """
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   111
        def catcher_func(*args, **kwargs):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   112
            try:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   113
                return func(*args, **kwargs)
1116
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   114
            except Pyro.errors.ConnectionClosedError, e:
1595
b3cc68dd037d add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
   115
                confnodesroot.logger.write_error(_("Connection lost!\n"))
1116
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   116
                confnodesroot._SetConnector(None)
493
015a803301b9 Catch ProtocolError exception when connection failed
laurent
parents: 486
diff changeset
   117
            except Pyro.errors.ProtocolError, e:
1595
b3cc68dd037d add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1581
diff changeset
   118
                confnodesroot.logger.write_error(_("Pyro exception: %s\n") % e)
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   119
            except Exception, e:
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   120
                # confnodesroot.logger.write_error(traceback.format_exc())
477
f66a092b6e74 Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 465
diff changeset
   121
                errmess = ''.join(Pyro.util.getPyroTraceback(e))
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   122
                confnodesroot.logger.write_error(errmess + "\n")
477
f66a092b6e74 Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 465
diff changeset
   123
                print errmess
1116
300f98a8d4c6 Fixed bug connector not resetted when connection is lost
Laurent Bessard
parents: 1070
diff changeset
   124
                confnodesroot._SetConnector(None)
1070
86ee833e33ef Added exception printing on Pyro connector, tracking random connection failure...
Edouard Tisserant
parents: 1035
diff changeset
   125
            return default
218
71fddab24be9 remove old code and fix typo
greg
parents: 203
diff changeset
   126
        return catcher_func
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   127
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   128
    # Check connection is effective.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   129
    # lambda is for getattr of GetPLCstatus to happen inside catcher
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   130
    if PyroCatcher(lambda: RemotePLCObjectProxy.GetPLCstatus())() is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   131
        confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n"))
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   132
        return None
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   133
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   134
    class PyroProxyProxy(object):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   135
        """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   136
        A proxy proxy class to handle Beremiz Pyro interface specific behavior.
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   137
        And to put Pyro exception catcher in between caller and Pyro proxy
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   138
        """
284
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   139
        def __init__(self):
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   140
            # for safe use in from debug thread, must create a copy
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   141
            self.RemotePLCObjectProxyCopy = None
3fecc96090c8 Fixed problem with re-use of Pyro connector proxy copy across debug sessions
etisserant
parents: 235
diff changeset
   142
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   143
        def GetPyroProxy(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   144
            """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   145
            This func returns the real Pyro Proxy.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   146
            Use this if you musn't keep reference to it.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   147
            """
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   148
            return RemotePLCObjectProxy
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   149
235
a66e150f2888 Improved debug data feedback.
etisserant
parents: 231
diff changeset
   150
        def _PyroStartPLC(self, *args, **kwargs):
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   151
            """
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   152
            confnodesroot._connector.GetPyroProxy() is used
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   153
            rather than RemotePLCObjectProxy because
1434
6e0cd0ceabb7 Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents: 1116
diff changeset
   154
            object is recreated meanwhile,
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   155
            so we must not keep ref to it here
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   156
            """
969
1950fe687dde Fix warning with LogMessage function
Laurent Bessard
parents: 923
diff changeset
   157
            current_status, log_count = confnodesroot._connector.GetPyroProxy().GetPLCstatus()
465
67d32a91d70b Fixes in debug + reconnect to running PLC
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 446
diff changeset
   158
            if current_status == "Dirty":
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   159
                """
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   160
                Some bad libs with static symbols may polute PLC
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   161
                ask runtime to suicide and come back again
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   162
                """
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   163
                confnodesroot.logger.write(_("Force runtime reload\n"))
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   164
                confnodesroot._connector.GetPyroProxy().ForceReload()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   165
                confnodesroot._Disconnect()
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   166
                # let remote PLC time to resurect.(freeze app)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   167
                sleep(0.5)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   168
                confnodesroot._Connect()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   169
            self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   170
            return confnodesroot._connector.GetPyroProxy().StartPLC(*args, **kwargs)
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   171
        StartPLC = PyroCatcher(_PyroStartPLC, False)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   172
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   173
        def _PyroGetTraceVariables(self):
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   174
            """
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   175
            for safe use in from debug thread, must use the copy
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   176
            """
465
67d32a91d70b Fixes in debug + reconnect to running PLC
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 446
diff changeset
   177
            if self.RemotePLCObjectProxyCopy is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 699
diff changeset
   178
                self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   179
            return self.RemotePLCObjectProxyCopy.GetTraceVariables()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   180
        GetTraceVariables = PyroCatcher(_PyroGetTraceVariables, ("Broken", None))
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   181
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   182
        def _PyroGetPLCstatus(self):
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   183
            return RemotePLCObjectProxy.GetPLCstatus()
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   184
        GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, ("Broken", None))
446
1edde533db19 Some cleanup in PLC status - removed that \"Starting\" state ...
ed
parents: 411
diff changeset
   185
699
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   186
        def _PyroRemoteExec(self, script, **kwargs):
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   187
            return RemotePLCObjectProxy.RemoteExec(script, **kwargs)
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   188
        RemoteExec = PyroCatcher(_PyroRemoteExec, (-1, "RemoteExec script failed!"))
6ff64cadb1ff Adding support for executing python scripts on remote runtime
laurent
parents: 493
diff changeset
   189
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   190
        def __getattr__(self, attrName):
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   191
            member = self.__dict__.get(attrName, None)
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   192
            if member is None:
1455
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   193
                def my_local_func(*args, **kwargs):
4ba27ed51e48 add pyrossl client side
Ronan Bignaux <r.bignaux@rbi.io>
parents: 1441
diff changeset
   194
                    return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs)
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   195
                member = PyroCatcher(my_local_func, None)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   196
                self.__dict__[attrName] = member
231
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   197
            return member
f1db3ce8f40a Re-organized pyro connector proxy members mascarading
etisserant
parents: 218
diff changeset
   198
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   199
    return PyroProxyProxy()