1390 This thread waid PLC debug data, and dispatch them to subscribers |
1387 This thread waid PLC debug data, and dispatch them to subscribers |
1391 """ |
1388 """ |
1392 self.debug_break = False |
1389 self.debug_break = False |
1393 debug_getvar_retry = 0 |
1390 debug_getvar_retry = 0 |
1394 while (not self.debug_break) and (self._connector is not None): |
1391 while (not self.debug_break) and (self._connector is not None): |
1395 Trace = self._connector.GetTraceVariables() |
1392 plc_status, Traces = self._connector.GetTraceVariables() |
1396 if(Trace): |
|
1397 plc_status, debug_tick, debug_buff = Trace |
|
1398 else: |
|
1399 plc_status = None |
|
1400 debug_getvar_retry += 1 |
1393 debug_getvar_retry += 1 |
1401 #print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()] |
1394 #print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()] |
1402 if plc_status == "Started" and debug_buff is not None: |
1395 if plc_status == "Started" : |
1403 self.IECdebug_lock.acquire() |
1396 if len(Traces) > 0: |
1404 debug_vars = UnpackDebugBuffer(debug_buff, self.TracedIECTypes) |
1397 Failed = False |
1405 if (debug_tick is not None and debug_vars is not None and |
1398 self.IECdebug_lock.acquire() |
1406 len(debug_vars) == len(self.TracedIECPath)): |
1399 for debug_tick, debug_buff in Traces : |
1407 if debug_getvar_retry > DEBUG_RETRIES_WARN: |
1400 debug_vars = UnpackDebugBuffer(debug_buff, self.TracedIECTypes) |
1408 self.logger.write(_("... debugger recovered\n")) |
1401 if (debug_vars is not None and |
1409 debug_getvar_retry = 0 |
1402 len(debug_vars) == len(self.TracedIECPath)): |
1410 for IECPath, values_buffer, value in izip( |
1403 for IECPath, values_buffer, value in izip( |
1411 self.TracedIECPath, |
1404 self.TracedIECPath, |
1412 self.DebugValuesBuffers, |
1405 self.DebugValuesBuffers, |
1413 debug_vars): |
1406 debug_vars): |
1414 IECdebug_data = self.IECdebug_datas.get(IECPath, None) #FIXME get |
1407 IECdebug_data = self.IECdebug_datas.get(IECPath, None) #FIXME get |
1415 if IECdebug_data is not None and value is not None: |
1408 if IECdebug_data is not None and value is not None: |
1416 forced = IECdebug_data[2:4] == ["Forced", value] |
1409 forced = IECdebug_data[2:4] == ["Forced", value] |
1417 if not IECdebug_data[4] and len(values_buffer) > 0: |
1410 if not IECdebug_data[4] and len(values_buffer) > 0: |
1418 values_buffer[-1] = (value, forced) |
1411 values_buffer[-1] = (value, forced) |
1419 else: |
1412 else: |
1420 values_buffer.append((value, forced)) |
1413 values_buffer.append((value, forced)) |
1421 self.DebugTicks.append(debug_tick) |
1414 self.DebugTicks.append(debug_tick) |
1422 self.IECdebug_lock.release() |
1415 debug_getvar_retry = 0 |
1423 if debug_getvar_retry == DEBUG_RETRIES_WARN: |
1416 self.IECdebug_lock.release() |
1424 self.logger.write(_("Waiting debugger to recover...\n")) |
1417 |
1425 if debug_getvar_retry == DEBUG_RETRIES_REREGISTER: |
|
1426 # re-register debug registry to PLC |
|
1427 wx.CallAfter(self.RegisterDebugVarToConnector) |
|
1428 if debug_getvar_retry != 0: |
1418 if debug_getvar_retry != 0: |
1429 # Be patient, tollerate PLC to come up before debugging |
1419 # Be patient, tollerate PLC to come with fresh samples |
1430 time.sleep(0.1) |
1420 time.sleep(0.1) |
1431 else: |
1421 else: |
1432 self.debug_break = True |
1422 self.debug_break = True |
1433 self.logger.write(_("Debugger disabled\n")) |
1423 self.logger.write(_("Debugger disabled\n")) |
1434 self.DebugThread = None |
1424 self.DebugThread = None |