230 @return: True if data type is numeric |
230 @return: True if data type is numeric |
231 """ |
231 """ |
232 return (self.Parent.IsNumType(self.VariableType) or |
232 return (self.Parent.IsNumType(self.VariableType) or |
233 self.VariableType in ["STRING", "WSTRING"]) |
233 self.VariableType in ["STRING", "WSTRING"]) |
234 |
234 |
235 def NewValue(self, tick, value, forced=False): |
235 def NewValues(self, ticks, values, forced=False): |
236 """ |
236 """ |
237 Function called by debug thread when a new debug value is available |
237 Function called by debug thread when a new debug value is available |
238 @param tick: PLC tick when value was captured |
238 @param tick: PLC tick when value was captured |
239 @param value: Value captured |
239 @param value: Value captured |
240 @param forced: Forced flag, True if value is forced (default: False) |
240 @param forced: Forced flag, True if value is forced (default: False) |
241 """ |
241 """ |
242 DebugDataConsumer.NewValue(self, tick, value, forced, raw=None) |
242 DebugDataConsumer.NewValues(self, ticks, values, forced, raw=None) |
243 |
243 |
244 if self.Data is not None: |
244 if self.Data is not None: |
245 # String data value is CRC |
245 |
246 num_value = (binascii.crc32(value) & STRING_CRC_MASK |
246 if self.VariableType in ["STRING", "WSTRING"]: |
247 if self.VariableType in ["STRING", "WSTRING"] |
247 last_raw_data = (self.RawData[-1] |
248 else float(value)) |
248 if len(self.RawData) > 0 else None) |
249 |
249 last_raw_data_idx = len(self.RawData) - 1 |
250 # Update variable range values |
250 |
251 self.MinValue = (min(self.MinValue, num_value) |
|
252 if self.MinValue is not None |
|
253 else num_value) |
|
254 self.MaxValue = (max(self.MaxValue, num_value) |
|
255 if self.MaxValue is not None |
|
256 else num_value) |
|
257 |
|
258 # Translate forced flag to float for storing in Data table |
251 # Translate forced flag to float for storing in Data table |
259 forced_value = float(forced) |
252 forced_value = float(forced) |
260 |
253 |
261 # In the case of string variables, we store raw string value and |
254 data_values = [] |
262 # forced flag in raw data table. Only changes in this two values |
255 for tick, value in zip(ticks, values): |
263 # are stored. Index to the corresponding raw value is stored in |
256 |
264 # data third column |
257 # String data value is CRC |
265 if self.VariableType in ["STRING", "WSTRING"]: |
258 num_value = (binascii.crc32(value) & STRING_CRC_MASK |
266 raw_data = (value, forced_value) |
259 if self.VariableType in ["STRING", "WSTRING"] |
267 if len(self.RawData) == 0 or self.RawData[-1] != raw_data: |
260 else float(value)) |
268 extra_value = len(self.RawData) |
261 |
269 self.RawData.append(raw_data) |
262 # Update variable range values |
|
263 self.MinValue = (min(self.MinValue, num_value) |
|
264 if self.MinValue is not None |
|
265 else num_value) |
|
266 self.MaxValue = (max(self.MaxValue, num_value) |
|
267 if self.MaxValue is not None |
|
268 else num_value) |
|
269 |
|
270 # In the case of string variables, we store raw string value and |
|
271 # forced flag in raw data table. Only changes in this two values |
|
272 # are stored. Index to the corresponding raw value is stored in |
|
273 # data third column |
|
274 if self.VariableType in ["STRING", "WSTRING"]: |
|
275 raw_data = (value, forced_value) |
|
276 if len(self.RawData) == 0 or last_raw_data != raw_data: |
|
277 last_raw_data_idx += 1 |
|
278 last_raw_data = raw_data |
|
279 self.RawData.append(raw_data) |
|
280 extra_value = last_raw_data_idx |
|
281 |
|
282 # In other case, data third column is forced flag |
270 else: |
283 else: |
271 extra_value = len(self.RawData) - 1 |
284 extra_value = forced_value |
272 |
285 |
273 # In other case, data third column is forced flag |
286 data_values.append( |
274 else: |
287 [float(tick), num_value, extra_value]) |
275 extra_value = forced_value |
|
276 |
288 |
277 # Add New data to stored data table |
289 # Add New data to stored data table |
278 self.Data = numpy.append(self.Data, |
290 self.Data = numpy.append(self.Data, data_values, axis=0) |
279 [[float(tick), num_value, extra_value]], axis=0) |
291 |
280 |
|
281 # Signal to debug variable panel to refresh |
292 # Signal to debug variable panel to refresh |
282 self.Parent.HasNewData = True |
293 self.Parent.HasNewData = True |
283 |
294 |
284 def SetForced(self, forced): |
295 def SetForced(self, forced): |
285 """ |
296 """ |