author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 10 Mar 2017 17:36:18 +0300 | |
changeset 1662 | 8816f7316d9c |
parent 1595 | b3cc68dd037d |
child 1732 | 94ffe74e6895 |
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 |
|
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
|
25 |
import sys, traceback, atexit |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
26 |
#from twisted.python import log |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
27 |
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
|
28 |
from autobahn.twisted import wamp |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
29 |
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
|
30 |
from autobahn.wamp import types |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
from threading import Thread, Event |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
34 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
35 |
_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
|
36 |
_WampConnection = None |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
37 |
_WampSessionEvent = Event() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
38 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
39 |
class WampSession(wamp.ApplicationSession): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
40 |
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
|
41 |
global _WampSession, _WampSessionEvent |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
42 |
_WampSession = self |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
43 |
_WampSessionEvent.set() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
44 |
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
|
45 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
46 |
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
|
47 |
global _WampSession, _WampSessionEvent |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
48 |
_WampSessionEvent.clear() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
49 |
_WampSession = None |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
50 |
print 'WAMP session left' |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
51 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
52 |
PLCObjDefaults = { "StartPLC": False, |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
53 |
"GetTraceVariables" : ("Broken",None), |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
54 |
"GetPLCstatus" : ("Broken",None), |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
55 |
"RemoteExec" : (-1, "RemoteExec script failed!")} |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
56 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
57 |
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
|
58 |
""" |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
""" |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
62 |
servicetype, location = uri.split("://") |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
63 |
urlpath, realm, ID = location.split('#') |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
64 |
urlprefix = {"WAMP":"ws", |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
65 |
"WAMPS":"wss"}[servicetype] |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
66 |
url = urlprefix+"://"+urlpath |
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 |
def RegisterWampClient(): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
69 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
70 |
## start logging to console |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
71 |
# log.startLogging(sys.stdout) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
72 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
73 |
# 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
|
74 |
component_config = types.ComponentConfig( |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
75 |
realm = realm, |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
76 |
extra = {"ID":ID}) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
77 |
session_factory = wamp.ApplicationSessionFactory( |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
78 |
config = component_config) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
79 |
session_factory.session = WampSession |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
80 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
81 |
# 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
|
82 |
transport_factory = WampWebSocketClientFactory( |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
83 |
session_factory, |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
84 |
url = url, |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
85 |
serializers = [MsgPackSerializer()], |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
86 |
debug = False, |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
87 |
debug_wamp = False) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
88 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
89 |
# 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
|
90 |
conn = connectWS(transport_factory) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
91 |
confnodesroot.logger.write(_("WAMP connecting to URL : %s\n")%url) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
92 |
return conn |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
93 |
|
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
|
94 |
AddToDoBeforeQuit = confnodesroot.AppFrame.AddToDoBeforeQuit |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
_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
|
98 |
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
|
99 |
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
|
100 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
101 |
def WampSessionProcMapper(funcname): |
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
|
102 |
wampfuncname = '.'.join((ID,funcname)) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
103 |
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
|
104 |
global _WampSession |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
105 |
if _WampSession is not None : |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
106 |
try: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
107 |
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
|
108 |
reactor, _WampSession.call, wampfuncname, |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
109 |
*args,**kwargs) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
110 |
except TransportLost, e: |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
111 |
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
|
112 |
confnodesroot._SetConnector(None) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
113 |
except Exception,e: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
114 |
errmess = traceback.format_exc() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
115 |
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
|
116 |
print errmess |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
117 |
#confnodesroot._SetConnector(None) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
118 |
return PLCObjDefaults.get(funcname) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
119 |
return catcher_func |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
120 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
121 |
class WampPLCObjectProxy(object): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
122 |
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
|
123 |
global _WampSessionEvent, _WampConnection |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
124 |
if not reactor.running: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
125 |
Thread(target=ThreadProc).start() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
126 |
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
|
127 |
_WampConnection = threads.blockingCallFromThread( |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
128 |
reactor, RegisterWampClient) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
129 |
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
|
130 |
_WampConnection = stopConnecting() |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
131 |
raise Exception, _("WAMP connection timeout") |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
132 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
_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
|
136 |
# |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
137 |
# reactor.stop() |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
138 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
139 |
def __getattr__(self, attrName): |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
140 |
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
|
141 |
if member is None: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
142 |
member = WampSessionProcMapper(attrName) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
143 |
self.__dict__[attrName] = member |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
144 |
return member |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
145 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
146 |
# Try to get the proxy object |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
147 |
try : |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
148 |
return WampPLCObjectProxy() |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
149 |
except Exception, msg: |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
150 |
confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n")%location) |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
151 |
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
|
152 |
return None |
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 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
155 |
|
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff
changeset
|
156 |