author | Edouard Tisserant |
Mon, 09 Feb 2015 13:38:00 +0100 | |
changeset 1444 | c162f1b0fbac |
parent 1365 | debc97102b23 |
child 1571 | 486f94a8032c |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import datetime |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
26 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
27 |
#------------------------------------------------------------------------------- |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
28 |
# Date and Time conversion function |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
29 |
#------------------------------------------------------------------------------- |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
30 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
31 |
SECOND = 1000000 # Number of microseconds in one second |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
32 |
MINUTE = 60 * SECOND # Number of microseconds in one minute |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
33 |
HOUR = 60 * MINUTE # Number of microseconds in one hour |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
34 |
DAY = 24 * HOUR # Number of microseconds in one day |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
35 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
36 |
# Date corresponding to Epoch (1970 January the first) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
37 |
DATE_ORIGIN = datetime.datetime(1970, 1, 1) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
38 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
39 |
def get_microseconds(value): |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
40 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
41 |
Function converting time duration expressed in day, second and microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
42 |
into one expressed in microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
43 |
@param value: Time duration to convert |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
44 |
@return: Time duration expressed in microsecond |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
45 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
46 |
return float(value.days * DAY + \ |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
47 |
value.seconds * SECOND + \ |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
48 |
value.microseconds) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
49 |
return |
814 | 50 |
|
51 |
def generate_time(value): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
52 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
53 |
Function converting time duration expressed in day, second and microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
54 |
into a IEC 61131 TIME literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
55 |
@param value: Time duration to convert |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
56 |
@return: IEC 61131 TIME literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
57 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
58 |
microseconds = get_microseconds(value) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
59 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
60 |
# Get absolute microseconds value and save if it was negative |
814 | 61 |
negative = microseconds < 0 |
62 |
microseconds = abs(microseconds) |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
63 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
64 |
# TIME literal prefix |
814 | 65 |
data = "T#" |
66 |
if negative: |
|
67 |
data += "-" |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
68 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
69 |
# In TIME literal format, it isn't mandatory to indicate null values |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
70 |
# if no greater non-null values are available. This variable is used to |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
71 |
# inhibit formatting until a non-null value is found |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
72 |
not_null = False |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
73 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
74 |
for val, format in [ |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
75 |
(int(microseconds) / DAY, "%dd"), # Days |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
76 |
((int(microseconds) % DAY) / HOUR, "%dh"), # Hours |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
77 |
((int(microseconds) % HOUR) / MINUTE, "%dm"), # Minutes |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
78 |
((int(microseconds) % MINUTE) / SECOND, "%ds")]: # Seconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
79 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
80 |
# Add value to TIME literal if value is non-null or another non-null |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
81 |
# value have already be found |
814 | 82 |
if val > 0 or not_null: |
83 |
data += format % val |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
84 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
85 |
# Update non-null variable |
814 | 86 |
not_null = True |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
87 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
88 |
# In any case microseconds have to be added to TIME literal |
814 | 89 |
data += "%gms" % (microseconds % SECOND / 1000.) |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
90 |
|
814 | 91 |
return data |
92 |
||
93 |
def generate_date(value): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
94 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
95 |
Function converting time duration expressed in day, second and microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
96 |
into a IEC 61131 DATE literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
97 |
@param value: Time duration to convert |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
98 |
@return: IEC 61131 DATE literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
99 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
100 |
return (DATE_ORIGIN + value).strftime("DATE#%Y-%m-%d") |
814 | 101 |
|
102 |
def generate_datetime(value): |
|
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 |
Function converting time duration expressed in day, second and microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
105 |
into a IEC 61131 DATE_AND_TIME literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
106 |
@param value: Time duration to convert |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
107 |
@return: IEC 61131 DATE_AND_TIME literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
108 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
109 |
return (DATE_ORIGIN + value).strftime("DT#%Y-%m-%d-%H:%M:%S.%f") |
814 | 110 |
|
111 |
def generate_timeofday(value): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
112 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
113 |
Function converting time duration expressed in day, second and microseconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
114 |
into a IEC 61131 TIME_OF_DAY literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
115 |
@param value: Time duration to convert |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
116 |
@return: IEC 61131 TIME_OF_DAY literal |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
117 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
118 |
microseconds = get_microseconds(value) |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
119 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
120 |
# TIME_OF_DAY literal prefix |
814 | 121 |
data = "TOD#" |
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 |
for val, format in [ |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
124 |
(int(microseconds) / HOUR, "%2.2d:"), # Hours |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
125 |
((int(microseconds) % HOUR) / MINUTE, "%2.2d:"), # Minutes |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
126 |
((int(microseconds) % MINUTE) / SECOND, "%2.2d."), # Seconds |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
127 |
(microseconds % SECOND, "%6.6d")]: # Microseconds |
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 |
# Add value to TIME_OF_DAY literal |
814 | 130 |
data += format % val |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
131 |
|
814 | 132 |
return data |
133 |
||
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
134 |
# Dictionary of translation functions from value send by debugger to IEC |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
135 |
# literal stored by type |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
136 |
TYPE_TRANSLATOR = { |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
137 |
"TIME": generate_time, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
138 |
"DATE": generate_date, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
139 |
"DT": generate_datetime, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
140 |
"TOD": generate_timeofday, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
141 |
"STRING": lambda v: "'%s'" % v, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
142 |
"WSTRING": lambda v: '"%s"' % v, |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
143 |
"REAL": lambda v: "%.6g" % v, |
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1193
diff
changeset
|
144 |
"LREAL": lambda v: "%.6g" % v} |
814 | 145 |
|
146 |
#------------------------------------------------------------------------------- |
|
147 |
# Debug Data Consumer Class |
|
148 |
#------------------------------------------------------------------------------- |
|
149 |
||
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
150 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
151 |
Class that implements an element that consumes debug values |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
152 |
Value update can be inhibited during the time the associated Debug Viewer is |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
153 |
refreshing |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
154 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
155 |
|
814 | 156 |
class DebugDataConsumer: |
157 |
||
158 |
def __init__(self): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
159 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
160 |
Constructor |
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 |
# Debug value and forced flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
163 |
self.Value = None |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
164 |
self.Forced = False |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
165 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
166 |
# Store debug value and forced flag when value update is inhibited |
814 | 167 |
self.LastValue = None |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
168 |
self.LastForced = False |
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 |
# Value IEC data type |
814 | 171 |
self.DataType = None |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
172 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
173 |
# Flag that value update is inhibited |
814 | 174 |
self.Inhibited = False |
175 |
||
176 |
def Inhibit(self, inhibit): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
177 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
178 |
Set flag to inhibit or activate value update |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
179 |
@param inhibit: Inhibit flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
180 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
181 |
# Save inhibit flag |
814 | 182 |
self.Inhibited = inhibit |
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 |
# When reactivated update value and forced flag with stored values |
814 | 185 |
if not inhibit and self.LastValue is not None: |
186 |
self.SetForced(self.LastForced) |
|
187 |
self.SetValue(self.LastValue) |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
188 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
189 |
# Reset stored values |
814 | 190 |
self.LastValue = None |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
191 |
self.LastForced = False |
814 | 192 |
|
193 |
def SetDataType(self, data_type): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
194 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
195 |
Set value IEC data type |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
196 |
@param data_type: Value IEC data type |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
197 |
""" |
814 | 198 |
self.DataType = data_type |
199 |
||
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
|
200 |
def NewValues(self, tick, values, raw="BOOL"): |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
201 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
202 |
Function called by debug thread when a new debug value is available |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
203 |
@param tick: PLC tick when value was captured |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
204 |
@param value: Value captured |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
205 |
@param forced: Forced flag, True if value is forced (default: False) |
1220
16c283246241
Fixed in DebugDataConsumer value translation inhibit support
Laurent Bessard
parents:
1214
diff
changeset
|
206 |
@param raw: Data type of values not translated (default: 'BOOL') |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
207 |
""" |
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
|
208 |
value, forced = values |
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:
1220
diff
changeset
|
209 |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
210 |
# Translate value to IEC literal |
1220
16c283246241
Fixed in DebugDataConsumer value translation inhibit support
Laurent Bessard
parents:
1214
diff
changeset
|
211 |
if self.DataType != raw: |
1214
2ef048b5383c
Added support for opening text viewer by default and toggling between GraphicViewer and TextViewer
Laurent Bessard
parents:
1193
diff
changeset
|
212 |
value = TYPE_TRANSLATOR.get(self.DataType, str)(value) |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
213 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
214 |
# Store value and forced flag when value update is inhibited |
814 | 215 |
if self.Inhibited: |
216 |
self.LastValue = value |
|
217 |
self.LastForced = forced |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
218 |
|
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
219 |
# Update value and forced flag in any other case |
814 | 220 |
else: |
221 |
self.SetForced(forced) |
|
222 |
self.SetValue(value) |
|
223 |
||
224 |
def SetValue(self, value): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
225 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
226 |
Update value. |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
227 |
May be overridden by inherited classes |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
228 |
@param value: New value |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
229 |
""" |
814 | 230 |
self.Value = value |
231 |
||
232 |
def GetValue(self): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
233 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
234 |
Return current value |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
235 |
@return: Current value |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
236 |
""" |
814 | 237 |
return self.Value |
238 |
||
239 |
def SetForced(self, forced): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
240 |
""" |
1193
59c196884fec
Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents:
1176
diff
changeset
|
241 |
Update Forced flag. |
59c196884fec
Moved and start to rewrite DebugVariablePanel splitting it into multiple files
Laurent Bessard
parents:
1176
diff
changeset
|
242 |
May be overridden by inherited classes |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
243 |
@param forced: New forced flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
244 |
""" |
814 | 245 |
self.Forced = forced |
246 |
||
247 |
def IsForced(self): |
|
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
248 |
""" |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
249 |
Indicate if current value is forced |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
250 |
@return: Current forced flag |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1173
diff
changeset
|
251 |
""" |
814 | 252 |
return self.Forced |