author | Edouard Tisserant |
Mon, 25 Mar 2019 14:59:54 +0100 | |
branch | wx.NewID_abuse_fix |
changeset 2554 | 45d4f9a84c60 |
parent 2546 | f5dae7b85906 |
child 2582 | 8f0d6c5fd55f |
permissions | -rw-r--r-- |
229 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
4 |
# This file is part of Beremiz runtime. |
229 | 5 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1570
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
229 | 7 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
8 |
# See COPYING.Runtime file for copyrights details. |
229 | 9 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
10 |
# This library is free software; you can redistribute it and/or |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
11 |
# modify it under the terms of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
12 |
# License as published by the Free Software Foundation; either |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
13 |
# version 2.1 of the License, or (at your option) any later version. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
14 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
15 |
# This library is distributed in the hope that it will be useful, |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1570
diff
changeset
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
18 |
# Lesser General Public License for more details. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
19 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
20 |
# You should have received a copy of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
21 |
# License along with this library; if not, write to the Free Software |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
229 | 23 |
|
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
24 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
25 |
from __future__ import absolute_import |
2309
d8fb90a2e11f
Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2270
diff
changeset
|
26 |
from threading import Thread, Lock, Semaphore, Event |
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
27 |
import ctypes |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
28 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import sys |
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
30 |
import traceback |
2537
eb4a4cc41914
Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
31 |
import shutil |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
32 |
from time import time |
2540
fca79ca84272
Replace md5 module with hashlib
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2537
diff
changeset
|
33 |
import hashlib |
2537
eb4a4cc41914
Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
34 |
from tempfile import mkstemp |
eb4a4cc41914
Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
35 |
from functools import wraps, partial |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
36 |
from six.moves import xrange |
2443
75a274023970
python3 support: pylint, W1606 # (execfile-builtin) execfile built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2442
diff
changeset
|
37 |
from past.builtins import execfile |
2537
eb4a4cc41914
Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2492
diff
changeset
|
38 |
import _ctypes |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
39 |
|
1902
2b7e2db31d81
Clarify licensing, and packaging of runtime only files :
Edouard Tisserant
parents:
1881
diff
changeset
|
40 |
from runtime.typemapping import TypeTranslator |
2b7e2db31d81
Clarify licensing, and packaging of runtime only files :
Edouard Tisserant
parents:
1881
diff
changeset
|
41 |
from runtime.loglevels import LogLevelsDefault, LogLevelsCount |
2324
1cf3768ebf85
Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents:
2309
diff
changeset
|
42 |
from runtime.Stunnel import getPSKID |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
43 |
from runtime import PlcStatus |
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
44 |
from runtime import MainWorker |
917 | 45 |
|
229 | 46 |
if os.name in ("nt", "ce"): |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1906
diff
changeset
|
47 |
dlopen = _ctypes.LoadLibrary |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1906
diff
changeset
|
48 |
dlclose = _ctypes.FreeLibrary |
229 | 49 |
elif os.name == "posix": |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1906
diff
changeset
|
50 |
dlopen = _ctypes.dlopen |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1906
diff
changeset
|
51 |
dlclose = _ctypes.dlclose |
229 | 52 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
53 |
|
699
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
54 |
def get_last_traceback(tb): |
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
55 |
while tb.tb_next: |
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
56 |
tb = tb.tb_next |
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
57 |
return tb |
229 | 58 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
59 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
60 |
lib_ext = { |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
61 |
"linux2": ".so", |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
62 |
"win32": ".dll", |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
63 |
}.get(sys.platform, "") |
229 | 64 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
65 |
|
291
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
66 |
def PLCprint(message): |
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
67 |
sys.stdout.write("PLCobject : "+message+"\n") |
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
68 |
sys.stdout.flush() |
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
69 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
70 |
|
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
71 |
def RunInMain(func): |
2486
44c2a4e2b84d
Fixed deadlock in runtime's Worker. Was discovered while using WAMP and PYRO simultaneously.
Edouard Tisserant
parents:
2485
diff
changeset
|
72 |
@wraps(func) |
1997 | 73 |
def func_wrapper(*args, **kwargs): |
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
74 |
return MainWorker.call(func, *args, **kwargs) |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
75 |
return func_wrapper |
1997 | 76 |
|
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
77 |
|
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
78 |
class PLCObject(object): |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
79 |
def __init__(self, WorkingDir, argv, statuschange, evaluator, pyruntimevars): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
80 |
self.workingdir = WorkingDir # must exits already |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
81 |
self.tmpdir = os.path.join(WorkingDir, 'tmp') |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
82 |
if os.path.exists(self.tmpdir): |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
83 |
shutil.rmtree(self.tmpdir) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
84 |
os.mkdir(self.tmpdir) |
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
85 |
# FIXME : is argv of any use nowadays ? |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
86 |
self.argv = [WorkingDir] + argv # force argv[0] to be "path" to exec... |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
87 |
self.statuschange = statuschange |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
88 |
self.evaluator = evaluator |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
89 |
self.pyruntimevars = pyruntimevars |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
90 |
self.PLCStatus = PlcStatus.Empty |
229 | 91 |
self.PLClibraryHandle = None |
352 | 92 |
self.PLClibraryLock = Lock() |
229 | 93 |
# Creates fake C funcs proxies |
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
94 |
self._InitPLCStubCalls() |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
95 |
self._loading_error = None |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
96 |
self.python_runtime_vars = 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:
1433
diff
changeset
|
97 |
self.TraceThread = None |
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:
1433
diff
changeset
|
98 |
self.TraceLock = Lock() |
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:
1433
diff
changeset
|
99 |
self.Traces = [] |
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
100 |
self.DebugToken = 0 |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
101 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
102 |
self._init_blobs() |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
103 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
104 |
# First task of worker -> no @RunInMain |
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
105 |
def AutoLoad(self, autostart): |
1997 | 106 |
# Get the last transfered PLC |
229 | 107 |
try: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
108 |
self.CurrentPLCFilename = open( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
109 |
self._GetMD5FileName(), |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
110 |
"r").read().strip() + lib_ext |
1570
0925da818853
fix PLC autostart option for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1463
diff
changeset
|
111 |
if self.LoadPLC(): |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
112 |
self.PLCStatus = PlcStatus.Stopped |
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
113 |
if autostart: |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
114 |
self.StartPLC() |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
115 |
return |
1846
14b40afccd69
remove unused variables found by pylint
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
116 |
except Exception: |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
117 |
self.PLCStatus = PlcStatus.Empty |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
118 |
self.CurrentPLCFilename = None |
229 | 119 |
|
2270
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
120 |
self.StatusChange() |
d9175daf6522
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
Edouard Tisserant
parents:
1997
diff
changeset
|
121 |
|
286
a2a8a52b0d4f
Minor changes to get better cleanup of debug and python_eval threads, accross multiple debug sessions and PLC runs.
etisserant
parents:
283
diff
changeset
|
122 |
def StatusChange(self): |
a2a8a52b0d4f
Minor changes to get better cleanup of debug and python_eval threads, accross multiple debug sessions and PLC runs.
etisserant
parents:
283
diff
changeset
|
123 |
if self.statuschange is not None: |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1435
diff
changeset
|
124 |
for callee in self.statuschange: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1435
diff
changeset
|
125 |
callee(self.PLCStatus) |
286
a2a8a52b0d4f
Minor changes to get better cleanup of debug and python_eval threads, accross multiple debug sessions and PLC runs.
etisserant
parents:
283
diff
changeset
|
126 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
127 |
@RunInMain |
917 | 128 |
def LogMessage(self, *args): |
129 |
if len(args) == 2: |
|
130 |
level, msg = args |
|
131 |
else: |
|
132 |
level = LogLevelsDefault |
|
133 |
msg, = args |
|
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1902
diff
changeset
|
134 |
PLCprint(msg) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1902
diff
changeset
|
135 |
if self._LogMessage is not None: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1902
diff
changeset
|
136 |
return self._LogMessage(level, msg, len(msg)) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1902
diff
changeset
|
137 |
return None |
917 | 138 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
139 |
@RunInMain |
1093 | 140 |
def ResetLogCount(self): |
141 |
if self._ResetLogCount is not None: |
|
142 |
self._ResetLogCount() |
|
917 | 143 |
|
1997 | 144 |
# used internaly |
917 | 145 |
def GetLogCount(self, level): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
146 |
if self._GetLogCount is not None: |
917 | 147 |
return int(self._GetLogCount(level)) |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
148 |
elif self._loading_error is not None and level == 0: |
1093 | 149 |
return 1 |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
150 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
151 |
@RunInMain |
917 | 152 |
def GetLogMessage(self, level, msgid): |
921 | 153 |
tick = ctypes.c_uint32() |
154 |
tv_sec = ctypes.c_uint32() |
|
155 |
tv_nsec = ctypes.c_uint32() |
|
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
156 |
if self._GetLogMessage is not None: |
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
157 |
maxsz = len(self._log_read_buffer)-1 |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
158 |
sz = self._GetLogMessage(level, msgid, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
159 |
self._log_read_buffer, maxsz, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
160 |
ctypes.byref(tick), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
161 |
ctypes.byref(tv_sec), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
162 |
ctypes.byref(tv_nsec)) |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
163 |
if sz and sz <= maxsz: |
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
164 |
self._log_read_buffer[sz] = '\x00' |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
165 |
return self._log_read_buffer.value, tick.value, tv_sec.value, tv_nsec.value |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
166 |
elif self._loading_error is not None and level == 0: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
167 |
return self._loading_error, 0, 0, 0 |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
168 |
return None |
911
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
169 |
|
229 | 170 |
def _GetMD5FileName(self): |
171 |
return os.path.join(self.workingdir, "lasttransferedPLC.md5") |
|
172 |
||
173 |
def _GetLibFileName(self): |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
174 |
return os.path.join(self.workingdir, self.CurrentPLCFilename) |
229 | 175 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
176 |
def _LoadPLC(self): |
229 | 177 |
""" |
178 |
Load PLC library |
|
179 |
Declare all functions, arguments and return values |
|
180 |
""" |
|
1457
ff7cfce737ca
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents:
1447
diff
changeset
|
181 |
md5 = open(self._GetMD5FileName(), "r").read() |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
182 |
self.PLClibraryLock.acquire() |
229 | 183 |
try: |
184 |
self._PLClibraryHandle = dlopen(self._GetLibFileName()) |
|
185 |
self.PLClibraryHandle = ctypes.CDLL(self.CurrentPLCFilename, handle=self._PLClibraryHandle) |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
186 |
|
1463
de311ffe3961
Changed runtime's global PLCID to PLC_ID, working around redefinition in windoze' headers.
Edouard Tisserant
parents:
1457
diff
changeset
|
187 |
self.PLC_ID = ctypes.c_char_p.in_dll(self.PLClibraryHandle, "PLC_ID") |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
188 |
if len(md5) == 32: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
189 |
self.PLC_ID.value = md5 |
1457
ff7cfce737ca
Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents:
1447
diff
changeset
|
190 |
|
229 | 191 |
self._startPLC = self.PLClibraryHandle.startPLC |
192 |
self._startPLC.restype = ctypes.c_int |
|
193 |
self._startPLC.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)] |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
194 |
|
455
e050ef5bd285
Refactoring in PLCobject, for PLC that do not use python plugin
ed
parents:
450
diff
changeset
|
195 |
self._stopPLC_real = self.PLClibraryHandle.stopPLC |
e050ef5bd285
Refactoring in PLCobject, for PLC that do not use python plugin
ed
parents:
450
diff
changeset
|
196 |
self._stopPLC_real.restype = None |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
197 |
|
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
365
diff
changeset
|
198 |
self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None) |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
365
diff
changeset
|
199 |
if self._PythonIterator is not None: |
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
365
diff
changeset
|
200 |
self._PythonIterator.restype = ctypes.c_char_p |
851
666f5bdad301
Added FBID variable to PY_EVAL evaluation context. FBID does identify uniquely py_eval block instance triggering execution
Edouard Tisserant
parents:
798
diff
changeset
|
201 |
self._PythonIterator.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p)] |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
202 |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
479
diff
changeset
|
203 |
self._stopPLC = self._stopPLC_real |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
365
diff
changeset
|
204 |
else: |
717 | 205 |
# If python confnode is not enabled, we reuse _PythonIterator |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
206 |
# as a call that block pythonthread until StopPLC |
1442
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
207 |
self.PlcStopping = Event() |
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
|
208 |
|
868
7e5da4962bea
Fix bug of PythonIterator signature in PLCObject when not using PythonLibrary
Edouard Tisserant
parents:
867
diff
changeset
|
209 |
def PythonIterator(res, blkid): |
1442
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
210 |
self.PlcStopping.clear() |
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
211 |
self.PlcStopping.wait() |
366
cd90e4c10261
Move python evaluator to create a python plugin containing any related python module
laurent
parents:
365
diff
changeset
|
212 |
return None |
455
e050ef5bd285
Refactoring in PLCobject, for PLC that do not use python plugin
ed
parents:
450
diff
changeset
|
213 |
self._PythonIterator = PythonIterator |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
214 |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
479
diff
changeset
|
215 |
def __StopPLC(): |
455
e050ef5bd285
Refactoring in PLCobject, for PLC that do not use python plugin
ed
parents:
450
diff
changeset
|
216 |
self._stopPLC_real() |
1442
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
217 |
self.PlcStopping.set() |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
479
diff
changeset
|
218 |
self._stopPLC = __StopPLC |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
219 |
|
229 | 220 |
self._ResetDebugVariables = self.PLClibraryHandle.ResetDebugVariables |
221 |
self._ResetDebugVariables.restype = None |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
222 |
|
235 | 223 |
self._RegisterDebugVariable = self.PLClibraryHandle.RegisterDebugVariable |
229 | 224 |
self._RegisterDebugVariable.restype = None |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
467
diff
changeset
|
225 |
self._RegisterDebugVariable.argtypes = [ctypes.c_int, ctypes.c_void_p] |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
226 |
|
229 | 227 |
self._FreeDebugData = self.PLClibraryHandle.FreeDebugData |
228 |
self._FreeDebugData.restype = None |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
229 |
|
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
230 |
self._GetDebugData = self.PLClibraryHandle.GetDebugData |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
231 |
self._GetDebugData.restype = ctypes.c_int |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
232 |
self._GetDebugData.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_void_p)] |
235 | 233 |
|
234 |
self._suspendDebug = self.PLClibraryHandle.suspendDebug |
|
614 | 235 |
self._suspendDebug.restype = ctypes.c_int |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
236 |
self._suspendDebug.argtypes = [ctypes.c_int] |
235 | 237 |
|
238 |
self._resumeDebug = self.PLClibraryHandle.resumeDebug |
|
239 |
self._resumeDebug.restype = None |
|
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
240 |
|
1093 | 241 |
self._ResetLogCount = self.PLClibraryHandle.ResetLogCount |
242 |
self._ResetLogCount.restype = None |
|
243 |
||
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
244 |
self._GetLogCount = self.PLClibraryHandle.GetLogCount |
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
245 |
self._GetLogCount.restype = ctypes.c_uint32 |
917 | 246 |
self._GetLogCount.argtypes = [ctypes.c_uint8] |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
247 |
|
911
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
248 |
self._LogMessage = self.PLClibraryHandle.LogMessage |
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
249 |
self._LogMessage.restype = ctypes.c_int |
971
c4550f76ae05
reverted PLCObject.py. ctypes.POINTER(ctypes.c_uint8) != string
Edouard Tisserant
parents:
969
diff
changeset
|
250 |
self._LogMessage.argtypes = [ctypes.c_uint8, ctypes.c_char_p, ctypes.c_uint32] |
1093 | 251 |
|
1760
ed2e2afb9573
clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
252 |
self._log_read_buffer = ctypes.create_string_buffer(1 << 14) # 16K |
911
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
253 |
self._GetLogMessage = self.PLClibraryHandle.GetLogMessage |
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
254 |
self._GetLogMessage.restype = ctypes.c_uint32 |
921 | 255 |
self._GetLogMessage.argtypes = [ctypes.c_uint8, ctypes.c_uint32, ctypes.c_char_p, ctypes.c_uint32, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32)] |
911
ffa24427396a
Log redirected to console, dump of all available log to console when connecting to PLC
Edouard Tisserant
parents:
906
diff
changeset
|
256 |
|
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
257 |
self._loading_error = None |
1035
0f905e027d18
Better mdns resolution failure signaling, added fixed bug whith runtime autostart
Edouard Tisserant
parents:
1027
diff
changeset
|
258 |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
259 |
except Exception: |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
260 |
self._loading_error = traceback.format_exc() |
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
261 |
PLCprint(self._loading_error) |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
262 |
return False |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
263 |
finally: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
264 |
self.PLClibraryLock.release() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
265 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
266 |
return True |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
267 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
268 |
@RunInMain |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
269 |
def LoadPLC(self): |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
270 |
res = self._LoadPLC() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
271 |
if res: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
272 |
self.PythonRuntimeInit() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
273 |
else: |
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
274 |
self._FreePLC() |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
275 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
276 |
return res |
229 | 277 |
|
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
278 |
@RunInMain |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1035
diff
changeset
|
279 |
def UnLoadPLC(self): |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1035
diff
changeset
|
280 |
self.PythonRuntimeCleanup() |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1035
diff
changeset
|
281 |
self._FreePLC() |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1035
diff
changeset
|
282 |
|
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
283 |
def _InitPLCStubCalls(self): |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
284 |
""" |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
285 |
create dummy C func proxies |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
286 |
""" |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
287 |
self._startPLC = lambda x, y: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
288 |
self._stopPLC = lambda: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
289 |
self._ResetDebugVariables = lambda: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
290 |
self._RegisterDebugVariable = lambda x, y: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
291 |
self._IterDebugData = lambda x, y: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
292 |
self._FreeDebugData = lambda: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
293 |
self._GetDebugData = lambda: -1 |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
294 |
self._suspendDebug = lambda x: -1 |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
295 |
self._resumeDebug = lambda: None |
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
296 |
self._PythonIterator = lambda: "" |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
297 |
self._GetLogCount = None |
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1902
diff
changeset
|
298 |
self._LogMessage = None |
914
94436558f0ce
More stable logging. Added small one-entry log for loading errors. Test now include python side concurrent logging
Edouard Tisserant
parents:
911
diff
changeset
|
299 |
self._GetLogMessage = None |
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
300 |
self._PLClibraryHandle = None |
229 | 301 |
self.PLClibraryHandle = None |
1984
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
302 |
|
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
303 |
def _FreePLC(self): |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
304 |
""" |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
305 |
Unload PLC library. |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
306 |
This is also called by __init__ to create dummy C func proxies |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
307 |
""" |
081265cda5b1
Intermediate state while implementing runtime worker to ensure that PLCObject Load and Unload methods always run main thread.
Edouard Tisserant
parents:
1983
diff
changeset
|
308 |
self.PLClibraryLock.acquire() |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
309 |
try: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
310 |
# Unload library explicitely |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
311 |
if getattr(self, "_PLClibraryHandle", None) is not None: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
312 |
dlclose(self._PLClibraryHandle) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
313 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
314 |
# Forget all refs to library |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
315 |
self._InitPLCStubCalls() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
316 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
317 |
finally: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
318 |
self.PLClibraryLock.release() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
319 |
|
229 | 320 |
return False |
321 |
||
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
322 |
def PythonRuntimeCall(self, methodname): |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
323 |
""" |
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
324 |
Calls init, start, stop or cleanup method provided by |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
325 |
runtime python files, loaded when new PLC uploaded |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
326 |
""" |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
327 |
for method in self.python_runtime_vars.get("_runtime_%s" % methodname, []): |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
328 |
_res, exp = self.evaluator(method) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
329 |
if exp is not None: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
330 |
self.LogMessage(0, '\n'.join(traceback.format_exception(*exp))) |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
331 |
|
1997 | 332 |
# used internaly |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
333 |
def PythonRuntimeInit(self): |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
334 |
MethodNames = ["init", "start", "stop", "cleanup"] |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
335 |
self.python_runtime_vars = globals().copy() |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1435
diff
changeset
|
336 |
self.python_runtime_vars.update(self.pyruntimevars) |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
337 |
parent = self |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1435
diff
changeset
|
338 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
339 |
class PLCSafeGlobals(object): |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
340 |
def __getattr__(self, name): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
341 |
try: |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
342 |
t = parent.python_runtime_vars["_"+name+"_ctype"] |
1156
9708ed2a4ac2
Added more clear error message in case of access to non declared PLC global from python code
Edouard Tisserant
parents:
1145
diff
changeset
|
343 |
except KeyError: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
344 |
raise KeyError("Try to get unknown shared global variable : %s" % name) |
1156
9708ed2a4ac2
Added more clear error message in case of access to non declared PLC global from python code
Edouard Tisserant
parents:
1145
diff
changeset
|
345 |
v = t() |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
346 |
parent.python_runtime_vars["_PySafeGetPLCGlob_"+name](ctypes.byref(v)) |
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
347 |
return parent.python_runtime_vars["_"+name+"_unpack"](v) |
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
348 |
|
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
349 |
def __setattr__(self, name, value): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
350 |
try: |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
351 |
t = parent.python_runtime_vars["_"+name+"_ctype"] |
1156
9708ed2a4ac2
Added more clear error message in case of access to non declared PLC global from python code
Edouard Tisserant
parents:
1145
diff
changeset
|
352 |
except KeyError: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
353 |
raise KeyError("Try to set unknown shared global variable : %s" % name) |
1868
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
354 |
v = parent.python_runtime_vars["_"+name+"_pack"](t, value) |
616c3f4bcbcb
fix pylint error '(no-self-argument) Method should have "self" as first argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
355 |
parent.python_runtime_vars["_PySafeSetPLCGlob_"+name](ctypes.byref(v)) |
1447
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
356 |
|
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
357 |
self.python_runtime_vars.update({ |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
358 |
"PLCGlobals": PLCSafeGlobals(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
359 |
"WorkingDir": self.workingdir, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
360 |
"PLCObject": self, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
361 |
"PLCBinary": self.PLClibraryHandle, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
362 |
"PLCGlobalsDesc": []}) |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
363 |
|
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
364 |
for methodname in MethodNames: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
365 |
self.python_runtime_vars["_runtime_%s" % methodname] = [] |
1447
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
366 |
|
972 | 367 |
try: |
1447
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
368 |
filenames = os.listdir(self.workingdir) |
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
369 |
filenames.sort() |
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1442
diff
changeset
|
370 |
for filename in filenames: |
972 | 371 |
name, ext = os.path.splitext(filename) |
372 |
if name.upper().startswith("RUNTIME") and ext.upper() == ".PY": |
|
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
373 |
execfile(os.path.join(self.workingdir, filename), self.python_runtime_vars) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
374 |
for methodname in MethodNames: |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
375 |
method = self.python_runtime_vars.get("_%s_%s" % (name, methodname), None) |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
376 |
if method is not None: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
377 |
self.python_runtime_vars["_runtime_%s" % methodname].append(method) |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
378 |
except Exception: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
379 |
self.LogMessage(0, traceback.format_exc()) |
972 | 380 |
raise |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
381 |
|
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
382 |
self.PythonRuntimeCall("init") |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
383 |
|
1997 | 384 |
# used internaly |
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
385 |
def PythonRuntimeCleanup(self): |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
386 |
if self.python_runtime_vars is not None: |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
387 |
self.PythonRuntimeCall("cleanup") |
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
388 |
|
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
1011
diff
changeset
|
389 |
self.python_runtime_vars = None |
291
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
390 |
|
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
391 |
def PythonThreadProc(self): |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
392 |
self.StartSem.release() |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
393 |
res, cmd, blkid = "None", "None", ctypes.c_void_p() |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
394 |
compile_cache = {} |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
395 |
while True: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
396 |
cmd = self._PythonIterator(res, blkid) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
397 |
FBID = blkid.value |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
398 |
if cmd is None: |
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
399 |
break |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
400 |
try: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
401 |
self.python_runtime_vars["FBID"] = FBID |
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
402 |
ccmd, AST = compile_cache.get(FBID, (None, None)) |
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
403 |
if ccmd is None or ccmd != cmd: |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
851
diff
changeset
|
404 |
AST = compile(cmd, '<plc>', 'eval') |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
405 |
compile_cache[FBID] = (cmd, AST) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
406 |
result, exp = self.evaluator(eval, AST, self.python_runtime_vars) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
407 |
if exp is not None: |
1052
fa7c5034c1d2
Better display of Python exceptions from Py_Eval
Edouard Tisserant
parents:
1051
diff
changeset
|
408 |
res = "#EXCEPTION : "+str(exp[1]) |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
409 |
self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % ( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
410 |
FBID, cmd, '\n'.join(traceback.format_exception(*exp)))) |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
851
diff
changeset
|
411 |
else: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
412 |
res = str(result) |
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
413 |
self.python_runtime_vars["FBID"] = None |
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2416
diff
changeset
|
414 |
except Exception as e: |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
415 |
res = "#EXCEPTION : "+str(e) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
416 |
self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e))) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
417 |
|
1988
19ca02e8074f
PLCObject got more methods serialized through worker : Start, Stop, NewPLC.
Edouard Tisserant
parents:
1987
diff
changeset
|
418 |
@RunInMain |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
419 |
def StartPLC(self): |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
420 |
if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped: |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
421 |
c_argv = ctypes.c_char_p * len(self.argv) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
422 |
res = self._startPLC(len(self.argv), c_argv(*self.argv)) |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
423 |
if res == 0: |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
424 |
self.PLCStatus = PlcStatus.Started |
1442
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
425 |
self.StatusChange() |
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
426 |
self.PythonRuntimeCall("start") |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
427 |
self.StartSem = Semaphore(0) |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
428 |
self.PythonThread = Thread(target=self.PythonThreadProc) |
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
429 |
self.PythonThread.start() |
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
430 |
self.StartSem.acquire() |
917 | 431 |
self.LogMessage("PLC started") |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
432 |
else: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
433 |
self.LogMessage(0, _("Problem starting PLC : error %d" % res)) |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
434 |
self.PLCStatus = PlcStatus.Broken |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
435 |
self.StatusChange() |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
436 |
|
1988
19ca02e8074f
PLCObject got more methods serialized through worker : Start, Stop, NewPLC.
Edouard Tisserant
parents:
1987
diff
changeset
|
437 |
@RunInMain |
229 | 438 |
def StopPLC(self): |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
439 |
if self.PLCStatus == PlcStatus.Started: |
917 | 440 |
self.LogMessage("PLC stopped") |
352 | 441 |
self._stopPLC() |
798
0d2423f283a6
Fix bug segmentation fault while cleanup extensions
laurent
parents:
795
diff
changeset
|
442 |
self.PythonThread.join() |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
443 |
self.PLCStatus = PlcStatus.Stopped |
1442
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
444 |
self.StatusChange() |
ad9a7853dea2
Fixed race condition preventing to stop PLC through WAMP
Edouard Tisserant
parents:
1440
diff
changeset
|
445 |
self.PythonRuntimeCall("stop") |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
446 |
if self.TraceThread is not 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:
1433
diff
changeset
|
447 |
self.TraceThread.join() |
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:
1433
diff
changeset
|
448 |
self.TraceThread = None |
229 | 449 |
return True |
450 |
return False |
|
451 |
||
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
452 |
@RunInMain |
229 | 453 |
def GetPLCstatus(self): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
454 |
return self.PLCStatus, map(self.GetLogCount, xrange(LogLevelsCount)) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
455 |
|
1988
19ca02e8074f
PLCObject got more methods serialized through worker : Start, Stop, NewPLC.
Edouard Tisserant
parents:
1987
diff
changeset
|
456 |
@RunInMain |
2324
1cf3768ebf85
Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents:
2309
diff
changeset
|
457 |
def GetPLCID(self): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
458 |
return getPSKID(partial(self.LogMessage, 0)) |
2324
1cf3768ebf85
Automatically get PSK and ID when connecting to PYRO[S], so that future connection through PYROS can use that same key. Also fixed case to UPPER for *PSK.
Edouard Tisserant
parents:
2309
diff
changeset
|
459 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
460 |
def _init_blobs(self): |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
461 |
self.blobs = {} |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
462 |
if os.path.exists(self.tmpdir): |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
463 |
shutil.rmtree(self.tmpdir) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
464 |
os.mkdir(self.tmpdir) |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
465 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
466 |
@RunInMain |
2487
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
467 |
def SeedBlob(self, seed): |
2540
fca79ca84272
Replace md5 module with hashlib
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2537
diff
changeset
|
468 |
blob = (mkstemp(dir=self.tmpdir) + (hashlib.new('md5'),)) |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
469 |
_fobj, _path, md5sum = blob |
2487
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
470 |
md5sum.update(seed) |
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
471 |
newBlobID = md5sum.digest() |
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
472 |
self.blobs[newBlobID] = blob |
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
473 |
return newBlobID |
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
474 |
|
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
475 |
@RunInMain |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
476 |
def AppendChunkToBlob(self, data, blobID): |
2487
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
477 |
blob = self.blobs.pop(blobID, None) |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
478 |
|
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
479 |
if blob is None: |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
480 |
return None |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
481 |
|
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
482 |
fobj, _path, md5sum = blob |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
483 |
md5sum.update(data) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
484 |
newBlobID = md5sum.digest() |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
485 |
os.write(fobj, data) |
2487
6a4f9a061994
Reworked chunk based transfer to support duplicated files (i.e. files with same content, but different names)
Edouard Tisserant
parents:
2486
diff
changeset
|
486 |
self.blobs[newBlobID] = blob |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
487 |
return newBlobID |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
488 |
|
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
489 |
@RunInMain |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
490 |
def PurgeBlobs(self): |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
491 |
for fobj, _path, _md5sum in self.blobs: |
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
492 |
os.close(fobj) |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
493 |
self._init_blobs() |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
494 |
|
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
495 |
def _BlobAsFile(self, blobID, newpath): |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
496 |
blob = self.blobs.pop(blobID, None) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
497 |
|
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
498 |
if blob is None: |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
499 |
raise Exception(_("Missing data to create file: {}").format(newpath)) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
500 |
|
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
501 |
fobj, path, _md5sum = blob |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
502 |
os.close(fobj) |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
503 |
shutil.move(path, newpath) |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2487
diff
changeset
|
504 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
505 |
@RunInMain |
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
506 |
def NewPLC(self, md5sum, plc_object, extrafiles): |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
507 |
if self.PLCStatus in [PlcStatus.Stopped, PlcStatus.Empty, PlcStatus.Broken]: |
229 | 508 |
NewFileName = md5sum + lib_ext |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
509 |
extra_files_log = os.path.join(self.workingdir, "extra_files.txt") |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
510 |
|
1997 | 511 |
old_PLC_filename = os.path.join(self.workingdir, self.CurrentPLCFilename) \ |
512 |
if self.CurrentPLCFilename is not None \ |
|
513 |
else None |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
514 |
new_PLC_filename = os.path.join(self.workingdir, NewFileName) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
515 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
516 |
self.UnLoadPLC() |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1035
diff
changeset
|
517 |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
518 |
self.LogMessage("NewPLC (%s)" % md5sum) |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
519 |
self.PLCStatus = PlcStatus.Empty |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
520 |
|
229 | 521 |
try: |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
522 |
os.remove(old_PLC_filename) |
2442
b13f021c68a5
python3 support: pylint, W1607 # (file-builtin) file built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
523 |
for filename in open(extra_files_log, "rt").readlines() + [extra_files_log]: |
229 | 524 |
try: |
364
27ea6a6747fc
Bug extra_files deletion in working directory fixed
laurent
parents:
361
diff
changeset
|
525 |
os.remove(os.path.join(self.workingdir, filename.strip())) |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
526 |
except Exception: |
229 | 527 |
pass |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
528 |
except Exception: |
229 | 529 |
pass |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
530 |
|
229 | 531 |
try: |
532 |
# Create new PLC file |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
533 |
self._BlobAsFile(plc_object, new_PLC_filename) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
534 |
|
229 | 535 |
# Store new PLC filename based on md5 key |
536 |
open(self._GetMD5FileName(), "w").write(md5sum) |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
537 |
|
229 | 538 |
# Then write the files |
2442
b13f021c68a5
python3 support: pylint, W1607 # (file-builtin) file built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
539 |
log = open(extra_files_log, "w") |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
540 |
for fname, blobID in extrafiles: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
541 |
fpath = os.path.join(self.workingdir, fname) |
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
542 |
self._BlobAsFile(blobID, fpath) |
229 | 543 |
log.write(fname+'\n') |
544 |
||
545 |
# Store new PLC filename |
|
546 |
self.CurrentPLCFilename = NewFileName |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
547 |
except Exception: |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
548 |
self.PLCStatus = PlcStatus.Broken |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
549 |
self.StatusChange() |
291
701c0601db02
Added systematic stdout.flush runtime side, so that results appear in log window
etisserant
parents:
290
diff
changeset
|
550 |
PLCprint(traceback.format_exc()) |
229 | 551 |
return False |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
552 |
|
2463
8742337a9fe3
Chunk based transfer for PLC binary and extra files, and some collateral code refactoring.
Edouard Tisserant
parents:
2459
diff
changeset
|
553 |
if self.LoadPLC(): |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
554 |
self.PLCStatus = PlcStatus.Stopped |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
555 |
else: |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
556 |
self.PLCStatus = PlcStatus.Broken |
906
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
557 |
self.StatusChange() |
de452d65865c
Python runtime now dlopens shared library immediatly after transfer, and release it only immediately before reloading a new one. This is probably going to reveal lot of dirty cleanups during start/stop cycles.
Edouard Tisserant
parents:
868
diff
changeset
|
558 |
|
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
559 |
return self.PLCStatus == PlcStatus.Stopped |
229 | 560 |
return False |
561 |
||
562 |
def MatchMD5(self, MD5): |
|
563 |
try: |
|
564 |
last_md5 = open(self._GetMD5FileName(), "r").read() |
|
565 |
return last_md5 == MD5 |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
566 |
except Exception: |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1438
diff
changeset
|
567 |
pass |
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1438
diff
changeset
|
568 |
return False |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
569 |
|
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
570 |
@RunInMain |
229 | 571 |
def SetTraceVariablesList(self, idxs): |
572 |
""" |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
573 |
Call ctype imported function to append |
229 | 574 |
these indexes to registred variables in PLC debugger |
575 |
""" |
|
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
576 |
self.DebugToken += 1 |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
577 |
if idxs: |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
578 |
# suspend but dont disable |
614 | 579 |
if self._suspendDebug(False) == 0: |
580 |
# keep a copy of requested idx |
|
581 |
self._ResetDebugVariables() |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
582 |
for idx, iectype, force in idxs: |
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
583 |
if force is not None: |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
584 |
c_type, _unpack_func, pack_func = \ |
614 | 585 |
TypeTranslator.get(iectype, |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
586 |
(None, None, None)) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
587 |
force = ctypes.byref(pack_func(c_type, force)) |
614 | 588 |
self._RegisterDebugVariable(idx, force) |
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:
1433
diff
changeset
|
589 |
self._TracesSwap() |
614 | 590 |
self._resumeDebug() |
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
591 |
return self.DebugToken |
462
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
592 |
else: |
274e83a5534e
Now debug is not a button anymore
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
461
diff
changeset
|
593 |
self._suspendDebug(True) |
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
594 |
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:
1433
diff
changeset
|
595 |
|
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:
1433
diff
changeset
|
596 |
def _TracesSwap(self): |
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:
1433
diff
changeset
|
597 |
self.LastSwapTrace = time() |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
598 |
if self.TraceThread is None and self.PLCStatus == PlcStatus.Started: |
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:
1433
diff
changeset
|
599 |
self.TraceThread = Thread(target=self.TraceThreadProc) |
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:
1433
diff
changeset
|
600 |
self.TraceThread.start() |
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:
1433
diff
changeset
|
601 |
self.TraceLock.acquire() |
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:
1433
diff
changeset
|
602 |
Traces = self.Traces |
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:
1433
diff
changeset
|
603 |
self.Traces = [] |
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:
1433
diff
changeset
|
604 |
self.TraceLock.release() |
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:
1433
diff
changeset
|
605 |
return Traces |
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:
1433
diff
changeset
|
606 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
607 |
@RunInMain |
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
608 |
def GetTraceVariables(self, DebugToken): |
2546
f5dae7b85906
Fix pylint warning [C0325(superfluous-parens), ] Unnecessary parens after u'if' keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2540
diff
changeset
|
609 |
if DebugToken is not None and DebugToken == self.DebugToken: |
2485
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
610 |
return self.PLCStatus, self._TracesSwap() |
ef327451d067
Add a debugger token to SetTraceVariables and GetTraceVariables to prevent crash an inconsistant data in case of multiple connections. Last connection now takes over existing connections's debug, and first connected IDE gets a wrning.
Edouard Tisserant
parents:
2463
diff
changeset
|
611 |
return PlcStatus.Broken, [] |
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:
1433
diff
changeset
|
612 |
|
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:
1433
diff
changeset
|
613 |
def TraceThreadProc(self): |
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:
1433
diff
changeset
|
614 |
""" |
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:
1433
diff
changeset
|
615 |
Return a list of traces, corresponding to the list of required idx |
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:
1433
diff
changeset
|
616 |
""" |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
617 |
self._resumeDebug() # Re-enable debugger |
2416
1ca207782dde
Use predefined constants for PlcStatus instead of string literals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1997
diff
changeset
|
618 |
while self.PLCStatus == PlcStatus.Started: |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
619 |
tick = ctypes.c_uint32() |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
446
diff
changeset
|
620 |
size = ctypes.c_uint32() |
1075
8078c01ae464
Now Debug Buffer Unpacking is a separate function, declared in typemapping.py
Edouard Tisserant
parents:
1074
diff
changeset
|
621 |
buff = ctypes.c_void_p() |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
622 |
TraceBuffer = None |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
623 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
624 |
self.PLClibraryLock.acquire() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
625 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
626 |
res = self._GetDebugData(ctypes.byref(tick), |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
627 |
ctypes.byref(size), |
1997 | 628 |
ctypes.byref(buff)) |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
629 |
if res == 0: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
630 |
if size.value: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
631 |
TraceBuffer = ctypes.string_at(buff.value, size.value) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
632 |
self._FreeDebugData() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
633 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
634 |
self.PLClibraryLock.release() |
1997 | 635 |
|
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
636 |
# leave thread if GetDebugData isn't happy. |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
637 |
if res != 0: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
638 |
break |
1990
2e0fbdd152de
Fixed Xenomai 3 PLC stop freeze. Now use explicit finish command with pipes. Closing both ends of pipes doesn't abort blocking read anymore.
Edouard Tisserant
parents:
1988
diff
changeset
|
639 |
|
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
640 |
if TraceBuffer is not None: |
1994
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
641 |
self.TraceLock.acquire() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
642 |
lT = len(self.Traces) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
643 |
if lT != 0 and lT * len(self.Traces[0]) > 1024 * 1024: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
644 |
self.Traces.pop(0) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
645 |
self.Traces.append((tick.value, TraceBuffer)) |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
646 |
self.TraceLock.release() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
647 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
648 |
# TraceProc stops here if Traces not polled for 3 seconds |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
649 |
traces_age = time() - self.LastSwapTrace |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
650 |
if traces_age > 3: |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
651 |
self.TraceLock.acquire() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
652 |
self.Traces = [] |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
653 |
self.TraceLock.release() |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
654 |
self._suspendDebug(True) # Disable debugger |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
655 |
break |
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
656 |
|
1fdc32be71b8
Rework of runtime non-real-time threading, and shared object dynamic loading :
Edouard Tisserant
parents:
1993
diff
changeset
|
657 |
self.TraceThread = 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:
1433
diff
changeset
|
658 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1438
diff
changeset
|
659 |
def RemoteExec(self, script, *kwargs): |
699
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
660 |
try: |
2419
c081dabc0f63
Fix old style exception raise and exec syntax
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
661 |
exec(script, kwargs) |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
662 |
except Exception: |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
663 |
_e_type, e_value, e_traceback = sys.exc_info() |
699
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
664 |
line_no = traceback.tb_lineno(get_last_traceback(e_traceback)) |
1433
4a45f6642523
Moved trace buffer unpacking in the IDE. Latest traced variable samples are now passed as a single string
Edouard Tisserant
parents:
1288
diff
changeset
|
665 |
return (-1, "RemoteExec script failed!\n\nLine %d: %s\n\t%s" % |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1868
diff
changeset
|
666 |
(line_no, e_value, script.splitlines()[line_no - 1])) |
699
6ff64cadb1ff
Adding support for executing python scripts on remote runtime
laurent
parents:
690
diff
changeset
|
667 |
return (0, kwargs.get("returnVal", None)) |