author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 22 Aug 2017 12:45:06 +0300 | |
changeset 1785 | 0ff2a45dcefa |
parent 1782 | 5b6ad7a7fd9d |
child 1826 | 91796f408540 |
permissions | -rw-r--r-- |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
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:
1443
diff
changeset
|
3 |
|
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
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:
1443
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
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:
1443
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:
1443
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:
1443
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
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:
1443
diff
changeset
|
19 |
# GNU General Public License for more details. |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1443
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:
1443
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:
1443
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
24 |
|
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
25 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
26 |
import traceback |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
27 |
import atexit |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
28 |
from twisted.internet import reactor, threads |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
29 |
from autobahn.twisted import wamp |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
30 |
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
31 |
from autobahn.wamp import types |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
32 |
from autobahn.wamp.exception import TransportLost |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
33 |
from autobahn.wamp.serializer import MsgPackSerializer |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
34 |
from threading import Thread, Event |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
35 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
36 |
_WampSession = None |
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
|
37 |
_WampConnection = None |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
38 |
_WampSessionEvent = Event() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
39 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
40 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
41 |
class WampSession(wamp.ApplicationSession): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
42 |
def onJoin(self, details): |
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
|
43 |
global _WampSession, _WampSessionEvent |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
44 |
_WampSession = self |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
45 |
_WampSessionEvent.set() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
46 |
print 'WAMP session joined for :', self.config.extra["ID"] |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
47 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
48 |
def onLeave(self, details): |
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
|
49 |
global _WampSession, _WampSessionEvent |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
50 |
_WampSessionEvent.clear() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
51 |
_WampSession = None |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
52 |
print 'WAMP session left' |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
53 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1748
diff
changeset
|
54 |
|
1747
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
55 |
PLCObjDefaults = { |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
56 |
"StartPLC": False, |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
57 |
"GetTraceVariables": ("Broken", None), |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
58 |
"GetPLCstatus": ("Broken", None), |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
59 |
"RemoteExec": (-1, "RemoteExec script failed!") |
6046ffa2280f
clean-up: fix PEP8 E201 whitespace after '{'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
60 |
} |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
61 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
62 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
63 |
def WAMP_connector_factory(uri, confnodesroot): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
64 |
""" |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
65 |
WAMP://127.0.0.1:12345/path#realm#ID |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
66 |
WAMPS://127.0.0.1:12345/path#realm#ID |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
67 |
""" |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
68 |
servicetype, location = uri.split("://") |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
69 |
urlpath, realm, ID = location.split('#') |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
70 |
urlprefix = {"WAMP": "ws", |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
71 |
"WAMPS": "wss"}[servicetype] |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
72 |
url = urlprefix+"://"+urlpath |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
73 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
74 |
def RegisterWampClient(): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
75 |
|
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
76 |
# start logging to console |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
77 |
# log.startLogging(sys.stdout) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
78 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
79 |
# create a WAMP application session factory |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
80 |
component_config = types.ComponentConfig( |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
81 |
realm=realm, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
82 |
extra={"ID": ID}) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
83 |
session_factory = wamp.ApplicationSessionFactory( |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
84 |
config=component_config) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
85 |
session_factory.session = WampSession |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
86 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
87 |
# create a WAMP-over-WebSocket transport client factory |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
88 |
transport_factory = WampWebSocketClientFactory( |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
89 |
session_factory, |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
90 |
url=url, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
91 |
serializers=[MsgPackSerializer()], |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
92 |
debug=False, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
93 |
debug_wamp=False) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
94 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
95 |
# start the client from a Twisted endpoint |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
96 |
conn = connectWS(transport_factory) |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
97 |
confnodesroot.logger.write(_("WAMP connecting to URL : %s\n") % url) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
98 |
return conn |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
99 |
|
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
|
100 |
AddToDoBeforeQuit = confnodesroot.AppFrame.AddToDoBeforeQuit |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
101 |
|
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
|
102 |
def ThreadProc(): |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
103 |
global _WampConnection |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
104 |
_WampConnection = RegisterWampClient() |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
105 |
AddToDoBeforeQuit(reactor.stop) |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
106 |
reactor.run(installSignalHandlers=False) |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
107 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
108 |
def WampSessionProcMapper(funcname): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
109 |
wampfuncname = '.'.join((ID, funcname)) |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
110 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
111 |
def catcher_func(*args, **kwargs): |
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
|
112 |
global _WampSession |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
113 |
if _WampSession is not None: |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
114 |
try: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
115 |
return threads.blockingCallFromThread( |
1443
ff8a22d45c44
WAMP : prefix callee names with given ID so that multiple PLC and IDE can join the same realm
Edouard Tisserant
parents:
1441
diff
changeset
|
116 |
reactor, _WampSession.call, wampfuncname, |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
117 |
*args, **kwargs) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
118 |
except TransportLost, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
119 |
confnodesroot.logger.write_error(_("Connection lost!\n")) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
120 |
confnodesroot._SetConnector(None) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
121 |
except Exception, e: |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
122 |
errmess = traceback.format_exc() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
123 |
confnodesroot.logger.write_error(errmess+"\n") |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
124 |
print errmess |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1765
diff
changeset
|
125 |
# confnodesroot._SetConnector(None) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
126 |
return PLCObjDefaults.get(funcname) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
127 |
return catcher_func |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
128 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
129 |
class WampPLCObjectProxy(object): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
130 |
def __init__(self): |
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
|
131 |
global _WampSessionEvent, _WampConnection |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
132 |
if not reactor.running: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
133 |
Thread(target=ThreadProc).start() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
134 |
else: |
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
|
135 |
_WampConnection = threads.blockingCallFromThread( |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
136 |
reactor, RegisterWampClient) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
137 |
if not _WampSessionEvent.wait(5): |
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
|
138 |
_WampConnection = stopConnecting() |
1765
ccf59c1f0b45
clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1753
diff
changeset
|
139 |
raise Exception(_("WAMP connection timeout")) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
140 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
141 |
def __del__(self): |
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
|
142 |
global _WampConnection |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
143 |
_WampConnection.disconnect() |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
144 |
# |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
145 |
# reactor.stop() |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
146 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
147 |
def __getattr__(self, attrName): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
148 |
member = self.__dict__.get(attrName, None) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
149 |
if member is None: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
150 |
member = WampSessionProcMapper(attrName) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
151 |
self.__dict__[attrName] = member |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
152 |
return member |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
153 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
154 |
# Try to get the proxy object |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
155 |
try: |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
156 |
return WampPLCObjectProxy() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
157 |
except Exception, msg: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
158 |
confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
159 |
confnodesroot.logger.write_error(traceback.format_exc()) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
160 |
return None |