author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Wed, 05 Jun 2024 15:18:15 +0200 | |
changeset 3960 | 9271afc4f34a |
parent 3765 | 88fe6fc9fd38 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
6 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
8 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
10 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
15 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
19 |
# GNU General Public License for more details. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
20 |
# |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1431
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 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 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
1881
diff
changeset
|
26 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
27 |
from threading import Lock, Timer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
28 |
from time import time as gettime |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
29 |
|
814 | 30 |
import wx |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
31 |
|
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
32 |
REFRESH_PERIOD = 0.1 # Minimum time between 2 refresh |
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
33 |
DEBUG_REFRESH_LOCK = Lock() # Common refresh lock for all debug viewers |
814 | 34 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
35 |
# ------------------------------------------------------------------------------- |
814 | 36 |
# Debug Viewer Class |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
37 |
# ------------------------------------------------------------------------------- |
814 | 38 |
|
39 |
||
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
40 |
class DebugViewer(object): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
Class that implements common behavior of every viewers able to display debug |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
43 |
values |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
44 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
45 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
46 |
def __init__(self, producer, debug, subscribe_tick=True): |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
47 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
48 |
Constructor |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
49 |
@param producer: Object receiving debug value and dispatching them to |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
50 |
consumers |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
51 |
@param debug: Flag indicating that Viewer is debugging |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
52 |
@param subscribe_tick: Flag indicating that viewer need tick value to |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
53 |
synchronize |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
54 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
55 |
self.Debug = debug |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
56 |
self.SubscribeTick = subscribe_tick |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
57 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
58 |
# Flag indicating that consumer value update inhibited |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
59 |
# (DebugViewer is refreshing) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
60 |
self.Inhibited = False |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
61 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
62 |
# List of data consumers subscribed to DataProducer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
63 |
self.DataConsumers = {} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
64 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
65 |
# Time stamp indicating when last refresh have been initiated |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
66 |
self.LastRefreshTime = gettime() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
67 |
# Flag indicating that DebugViewer has acquire common debug lock |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
68 |
self.HasAcquiredLock = False |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
69 |
# Lock for access to the two preceding variable |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
70 |
self.AccessLock = Lock() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
71 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
72 |
# Timer to refresh Debug Viewer one last time in the case that a new |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
73 |
# value have been received during refresh was inhibited and no one |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
74 |
# after refresh was activated |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
75 |
self.LastRefreshTimer = None |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
76 |
# Lock for access to the timer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
77 |
self.TimerAccessLock = Lock() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
78 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
79 |
# Set DataProducer and subscribe tick if needed |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
80 |
self.SetDataProducer(producer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
81 |
|
814 | 82 |
def SetDataProducer(self, producer): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
83 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
84 |
Set Data Producer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
85 |
@param producer: Data Producer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
86 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
87 |
# In the case that tick need to be subscribed and DebugViewer is |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
88 |
# debugging |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
89 |
if self.SubscribeTick and self.Debug: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
90 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
91 |
# Subscribe tick to new data producer |
814 | 92 |
if producer is not None: |
1365
debc97102b23
Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents:
1363
diff
changeset
|
93 |
producer.SubscribeDebugIECVariable("__tick__", self, True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
94 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
95 |
# Unsubscribe tick from old data producer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
96 |
if getattr(self, "DataProducer", None) is not None: |
1089
5cd1f8df71aa
Fixed bug when transferring program and a output located variable is forced
Laurent Bessard
parents:
1069
diff
changeset
|
97 |
self.DataProducer.UnsubscribeDebugIECVariable("__tick__", self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
98 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
99 |
# Save new data producer |
814 | 100 |
self.DataProducer = producer |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
101 |
|
814 | 102 |
def IsDebugging(self): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
103 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
104 |
Get flag indicating if Debug Viewer is debugging |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
105 |
@return: Debugging flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
106 |
""" |
814 | 107 |
return self.Debug |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
108 |
|
814 | 109 |
def Inhibit(self, inhibit): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
110 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
111 |
Set consumer value update inhibit flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
112 |
@param inhibit: Inhibit flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
113 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
114 |
# Inhibit every data consumers in list |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
1881
diff
changeset
|
115 |
for consumer, _iec_path in self.DataConsumers.items(): |
814 | 116 |
consumer.Inhibit(inhibit) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
117 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
118 |
# Save inhibit flag |
814 | 119 |
self.Inhibited = inhibit |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
120 |
|
1365
debc97102b23
Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents:
1363
diff
changeset
|
121 |
def AddDataConsumer(self, iec_path, consumer, buffer_list=False): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
122 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
123 |
Subscribe data consumer to DataProducer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
124 |
@param iec_path: Path in PLC of variable needed by data consumer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
125 |
@param consumer: Data consumer to subscribe |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
126 |
@return: List of value already received [(tick, data),...] (None if |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
127 |
subscription failed) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
128 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
129 |
# Return immediately if no DataProducer defined |
814 | 130 |
if self.DataProducer is None: |
131 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
132 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
133 |
# Subscribe data consumer to DataProducer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
134 |
result = self.DataProducer.SubscribeDebugIECVariable( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
135 |
iec_path, consumer, buffer_list) |
814 | 136 |
if result is not None and consumer != self: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
137 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
138 |
# Store data consumer if successfully subscribed and inform |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
139 |
# consumer of variable data type |
814 | 140 |
self.DataConsumers[consumer] = iec_path |
141 |
consumer.SetDataType(self.GetDataType(iec_path)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
142 |
|
814 | 143 |
return result |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
144 |
|
814 | 145 |
def RemoveDataConsumer(self, consumer): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
146 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
147 |
Unsubscribe data consumer from DataProducer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
148 |
@param consumer: Data consumer to unsubscribe |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
149 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
150 |
# Remove consumer from data consumer list |
814 | 151 |
iec_path = self.DataConsumers.pop(consumer, None) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
152 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
153 |
# Unsubscribe consumer from DataProducer |
814 | 154 |
if iec_path is not None: |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
155 |
self.DataProducer.UnsubscribeDebugIECVariable(iec_path, consumer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
156 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
157 |
def SubscribeAllDataConsumers(self): |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
158 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
159 |
Called to Subscribe all data consumers contained in DebugViewer. |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
160 |
May be overridden by inherited classes. |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
161 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
162 |
# Subscribe tick if needed |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
163 |
if self.SubscribeTick and self.Debug and self.DataProducer is not None: |
1365
debc97102b23
Added support for optimizing debug, preventing to filling buffers with only the last value for debug data consumers that only show the current state
Laurent Bessard
parents:
1363
diff
changeset
|
164 |
self.DataProducer.SubscribeDebugIECVariable("__tick__", self, True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
165 |
|
1205
638d1d430d24
Fixed bug Viewer not refreshed when debugging
Laurent Bessard
parents:
1176
diff
changeset
|
166 |
def UnsubscribeAllDataConsumers(self, tick=True): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
167 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
168 |
Called to Unsubscribe all data consumers. |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
169 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
170 |
if self.DataProducer is not None: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
171 |
|
1210
9a35da8f714b
Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents:
1205
diff
changeset
|
172 |
# Unscribe tick if needed |
9a35da8f714b
Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents:
1205
diff
changeset
|
173 |
if self.SubscribeTick and tick and self.Debug: |
9a35da8f714b
Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents:
1205
diff
changeset
|
174 |
self.DataProducer.UnsubscribeDebugIECVariable("__tick__", self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
175 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
176 |
# Unsubscribe all data consumers in list |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
1881
diff
changeset
|
177 |
for consumer, iec_path in self.DataConsumers.items(): |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
178 |
self.DataProducer.UnsubscribeDebugIECVariable(iec_path, consumer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
179 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
180 |
self.DataConsumers = {} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
181 |
|
814 | 182 |
def GetDataType(self, iec_path): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
183 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
184 |
Return variable data type. |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
185 |
@param iec_path: Path in PLC of variable |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
186 |
@return: variable data type (None if not found) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
187 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
188 |
if self.DataProducer is not None: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
189 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
190 |
# Search for variable informations in project compilation files |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
191 |
data_type = self.DataProducer.GetDebugIECVariableType( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
192 |
iec_path.upper()) |
1102 | 193 |
if data_type is not None: |
194 |
return data_type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
195 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
196 |
# Search for variable informations in project data |
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
880
diff
changeset
|
197 |
infos = self.DataProducer.GetInstanceInfos(iec_path) |
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
880
diff
changeset
|
198 |
if infos is not None: |
1363
e87e0166d0a7
Added new debug process separating non-wx thread extracting debug values from connector and 10 Hz wx timer refreshing Beremiz debug Viewers and communicating throw double-buffering, to avoid segmentation faults and optimize CPU usage
Laurent Bessard
parents:
1215
diff
changeset
|
199 |
return infos.type |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
200 |
|
814 | 201 |
return None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
202 |
|
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
880
diff
changeset
|
203 |
def IsNumType(self, data_type): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
204 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
205 |
Indicate if data type given is a numeric data type |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
206 |
@param data_type: Data type to test |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
207 |
@return: True if data type given is numeric |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
208 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
209 |
if self.DataProducer is not None: |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
210 |
return self.DataProducer.IsNumType(data_type) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
211 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
212 |
return False |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
213 |
|
814 | 214 |
def ForceDataValue(self, iec_path, value): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
215 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
216 |
Force PLC variable value |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
217 |
@param iec_path: Path in PLC of variable to force |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
218 |
@param value: Value forced |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
219 |
""" |
814 | 220 |
if self.DataProducer is not None: |
221 |
self.DataProducer.ForceDebugIECVariable(iec_path, value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
222 |
|
814 | 223 |
def ReleaseDataValue(self, iec_path): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
224 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
225 |
Release PLC variable value |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
226 |
@param iec_path: Path in PLC of variable to release |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
227 |
""" |
814 | 228 |
if self.DataProducer is not None: |
229 |
self.DataProducer.ReleaseDebugIECVariable(iec_path) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
230 |
|
1431 | 231 |
def NewDataAvailable(self, ticks): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
232 |
""" |
1215 | 233 |
Called by DataProducer for each tick captured |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
234 |
@param tick: PLC tick captured |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
235 |
All other parameters are passed to refresh function |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
236 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
237 |
# Stop last refresh timer |
877
7e695249be8d
Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents:
875
diff
changeset
|
238 |
self.TimerAccessLock.acquire() |
875
a8952b79caec
Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents:
857
diff
changeset
|
239 |
if self.LastRefreshTimer is not None: |
a8952b79caec
Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents:
857
diff
changeset
|
240 |
self.LastRefreshTimer.cancel() |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
241 |
self.LastRefreshTimer = None |
877
7e695249be8d
Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents:
875
diff
changeset
|
242 |
self.TimerAccessLock.release() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
243 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
244 |
# Only try to refresh DebugViewer if it is visible on screen and not |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
245 |
# already refreshing |
887
d3c6c4ab8b28
Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents:
880
diff
changeset
|
246 |
if self.IsShown() and not self.Inhibited: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
247 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
248 |
# Try to get acquire common refresh lock if minimum period between |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
249 |
# two refresh has expired |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
250 |
if gettime() - self.LastRefreshTime > REFRESH_PERIOD and \ |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
251 |
DEBUG_REFRESH_LOCK.acquire(False): |
1431 | 252 |
self.StartRefreshing() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
253 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
254 |
# If common lock wasn't acquired for any reason, restart last |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
255 |
# refresh timer |
933 | 256 |
else: |
1431 | 257 |
self.StartLastRefreshTimer() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
258 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
259 |
# In the case that DebugViewer isn't visible on screen and has already |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
260 |
# acquired common refresh lock, reset DebugViewer |
877
7e695249be8d
Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents:
875
diff
changeset
|
261 |
elif not self.IsShown() and self.HasAcquiredLock: |
7e695249be8d
Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents:
875
diff
changeset
|
262 |
DebugViewer.RefreshNewData(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
263 |
|
1431 | 264 |
def ShouldRefresh(self): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
265 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
266 |
Callback function called when last refresh timer expired |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
267 |
All parameters are passed to refresh function |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
268 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
269 |
# Cancel if DebugViewer is not visible on screen |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
270 |
if self and self.IsShown(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
271 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
272 |
# Try to acquire common refresh lock |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
273 |
if DEBUG_REFRESH_LOCK.acquire(False): |
1431 | 274 |
self.StartRefreshing() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
275 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
276 |
# Restart last refresh timer if common refresh lock acquired failed |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
277 |
else: |
1431 | 278 |
self.StartLastRefreshTimer() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
279 |
|
1431 | 280 |
def StartRefreshing(self): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
281 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
282 |
Called to initiate a refresh of DebugViewer |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
283 |
All parameters are passed to refresh function |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
284 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
285 |
# Update last refresh time stamp and flag for common refresh |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
286 |
# lock acquired |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
287 |
self.AccessLock.acquire() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
288 |
self.HasAcquiredLock = True |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
289 |
self.LastRefreshTime = gettime() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
290 |
self.AccessLock.release() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
291 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
292 |
# Inhibit data consumer value update |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
293 |
self.Inhibit(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
294 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
295 |
# Initiate DebugViewer refresh |
1431 | 296 |
wx.CallAfter(self.RefreshNewData) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
297 |
|
1431 | 298 |
def StartLastRefreshTimer(self): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
299 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
300 |
Called to start last refresh timer for the minimum time between 2 |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
301 |
refresh |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
302 |
All parameters are passed to refresh function |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
303 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
304 |
self.TimerAccessLock.acquire() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
305 |
self.LastRefreshTimer = Timer( |
1431 | 306 |
REFRESH_PERIOD, self.ShouldRefresh) |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
307 |
self.LastRefreshTimer.start() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
308 |
self.TimerAccessLock.release() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
309 |
|
1431 | 310 |
def RefreshNewData(self): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
311 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
312 |
Called to refresh DebugViewer according to values received by data |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
313 |
consumers |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
314 |
May be overridden by inherited classes |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
315 |
Can receive any parameters depending on what is needed by inherited |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
316 |
class |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
317 |
""" |
814 | 318 |
if self: |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
319 |
# Activate data consumer value update |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
320 |
self.Inhibit(False) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
321 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
322 |
# Release common refresh lock if acquired and update |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
323 |
# last refresh time |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
324 |
self.AccessLock.acquire() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
325 |
if self.HasAcquiredLock: |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
326 |
DEBUG_REFRESH_LOCK.release() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
327 |
self.HasAcquiredLock = False |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
328 |
if gettime() - self.LastRefreshTime > REFRESH_PERIOD: |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
329 |
self.LastRefreshTime = gettime() |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
330 |
self.AccessLock.release() |