940 def ShowError(self, logger, from_location, to_location): |
940 def ShowError(self, logger, from_location, to_location): |
941 chunk_infos = self.GetChunkInfos(from_location, to_location) |
941 chunk_infos = self.GetChunkInfos(from_location, to_location) |
942 for infos, (start_row, start_col) in chunk_infos: |
942 for infos, (start_row, start_col) in chunk_infos: |
943 start = (from_location[0] - start_row, from_location[1] - start_col) |
943 start = (from_location[0] - start_row, from_location[1] - start_col) |
944 end = (to_location[0] - start_row, to_location[1] - start_col) |
944 end = (to_location[0] - start_row, to_location[1] - start_col) |
945 #print from_location, to_location, start_row, start_col, start, end |
|
946 if self.AppFrame is not None: |
945 if self.AppFrame is not None: |
947 self.AppFrame.ShowError(infos, start, end) |
946 self.AppFrame.ShowError(infos, start, end) |
948 |
947 |
949 _IECCodeView = None |
948 _IECCodeView = None |
950 def _showIECcode(self): |
949 def _showIECcode(self): |
1077 self._builder = None |
1076 self._builder = None |
1078 self.CompareLocalAndRemotePLC() |
1077 self.CompareLocalAndRemotePLC() |
1079 |
1078 |
1080 def UpdatePLCLog(self, log_count): |
1079 def UpdatePLCLog(self, log_count): |
1081 if log_count and self.previous_log_count != log_count: |
1080 if log_count and self.previous_log_count != log_count: |
1082 #self.logger.write("Now log count is "+repr(log_count)+"\n") |
1081 # XXX replace dump to console with dedicated log panel. |
1083 to_console = [''] |
1082 to_console = [''] |
1084 for msgidx in xrange(log_count-1, self.previous_log_count - 1 if self.previous_log_count is not None else 0,-1): |
1083 dump_end = max( # request message sent after the last one we already got |
|
1084 self.previous_log_count - 1 if self.previous_log_count is not None else -1, |
|
1085 log_count - 100) # 100 is purely arbitrary number |
|
1086 # dedicated panel should only ask for a small range, |
|
1087 # depending on how user navigate in the panel |
|
1088 # and only ask for last one in follow mode |
|
1089 for msgidx in xrange(log_count-1, dump_end,-1): |
1085 msg = self._connector.GetLogMessage(msgidx) |
1090 msg = self._connector.GetLogMessage(msgidx) |
1086 if msg is not None : |
1091 if msg is not None : |
1087 to_console.insert(0, '#' + repr(msgidx) + ": " + msg) |
1092 to_console.insert(0, '#' + repr(msgidx) + ": " + msg) |
1088 else: |
1093 else: |
1089 #self.logger.write(repr(msgidx) + " : GetLogMessage returned None\n") |
|
1090 to_console.insert(0, 'No log before #'+repr(msgidx)) |
1094 to_console.insert(0, 'No log before #'+repr(msgidx)) |
1091 break; |
1095 break; |
1092 self.logger.write("\n".join(to_console)) |
1096 self.logger.write("\n".join(to_console)) |
1093 self.previous_log_count = log_count |
1097 self.previous_log_count = log_count |
1094 |
1098 |
1141 for IECPath,data_tuple in self.IECdebug_datas.iteritems(): |
1145 for IECPath,data_tuple in self.IECdebug_datas.iteritems(): |
1142 WeakCallableDict, data_log, status, fvalue = data_tuple |
1146 WeakCallableDict, data_log, status, fvalue = data_tuple |
1143 if len(WeakCallableDict) == 0: |
1147 if len(WeakCallableDict) == 0: |
1144 # Callable Dict is empty. |
1148 # Callable Dict is empty. |
1145 # This variable is not needed anymore! |
1149 # This variable is not needed anymore! |
1146 #print "Unused : " + IECPath |
|
1147 IECPathsToPop.append(IECPath) |
1150 IECPathsToPop.append(IECPath) |
1148 elif IECPath != "__tick__": |
1151 elif IECPath != "__tick__": |
1149 # Convert |
1152 # Convert |
1150 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1153 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1151 if Idx is not None: |
1154 if Idx is not None: |
1164 self._connector.SetTraceVariablesList(zip(*zip(*Idxs)[0:3])) |
1167 self._connector.SetTraceVariablesList(zip(*zip(*Idxs)[0:3])) |
1165 else: |
1168 else: |
1166 self.TracedIECPath = [] |
1169 self.TracedIECPath = [] |
1167 self._connector.SetTraceVariablesList([]) |
1170 self._connector.SetTraceVariablesList([]) |
1168 self.IECdebug_lock.release() |
1171 self.IECdebug_lock.release() |
1169 |
|
1170 #for IEC_path, IECdebug_data in self.IECdebug_datas.iteritems(): |
|
1171 # print IEC_path, IECdebug_data[0].keys() |
|
1172 |
1172 |
1173 def ReArmDebugRegisterTimer(self): |
1173 def ReArmDebugRegisterTimer(self): |
1174 if self.DebugTimer is not None: |
1174 if self.DebugTimer is not None: |
1175 self.DebugTimer.cancel() |
1175 self.DebugTimer.cancel() |
1176 |
1176 |
1211 self.ReArmDebugRegisterTimer() |
1211 self.ReArmDebugRegisterTimer() |
1212 |
1212 |
1213 return IECdebug_data[1] |
1213 return IECdebug_data[1] |
1214 |
1214 |
1215 def UnsubscribeDebugIECVariable(self, IECPath, callableobj): |
1215 def UnsubscribeDebugIECVariable(self, IECPath, callableobj): |
1216 #print "Unsubscribe", IECPath, callableobj |
|
1217 self.IECdebug_lock.acquire() |
1216 self.IECdebug_lock.acquire() |
1218 IECdebug_data = self.IECdebug_datas.get(IECPath, None) |
1217 IECdebug_data = self.IECdebug_datas.get(IECPath, None) |
1219 if IECdebug_data is not None: |
1218 if IECdebug_data is not None: |
1220 IECdebug_data[0].pop(callableobj,None) |
1219 IECdebug_data[0].pop(callableobj,None) |
1221 self.IECdebug_lock.release() |
1220 self.IECdebug_lock.release() |
1263 data_tuple = self.IECdebug_datas.get(IECPath, None) |
1262 data_tuple = self.IECdebug_datas.get(IECPath, None) |
1264 if data_tuple is not None: |
1263 if data_tuple is not None: |
1265 WeakCallableDict, data_log, status, fvalue = data_tuple |
1264 WeakCallableDict, data_log, status, fvalue = data_tuple |
1266 #data_log.append((debug_tick, value)) |
1265 #data_log.append((debug_tick, value)) |
1267 for weakcallable,(args,kwargs) in WeakCallableDict.iteritems(): |
1266 for weakcallable,(args,kwargs) in WeakCallableDict.iteritems(): |
1268 #print weakcallable, value, args, kwargs |
|
1269 function = getattr(weakcallable, function_name, None) |
1267 function = getattr(weakcallable, function_name, None) |
1270 if function is not None: |
1268 if function is not None: |
1271 if status == "Forced" and cargs[1] == fvalue: |
1269 if status == "Forced" and cargs[1] == fvalue: |
1272 function(*(cargs + (True,) + args), **kwargs) |
1270 function(*(cargs + (True,) + args), **kwargs) |
1273 else: |
1271 else: |
1293 if(Trace): |
1291 if(Trace): |
1294 plc_status, log_count, debug_tick, debug_vars = Trace |
1292 plc_status, log_count, debug_tick, debug_vars = Trace |
1295 else: |
1293 else: |
1296 plc_status = None |
1294 plc_status = None |
1297 debug_getvar_retry += 1 |
1295 debug_getvar_retry += 1 |
1298 #print debug_tick, debug_vars |
|
1299 if plc_status == "Started": |
1296 if plc_status == "Started": |
1300 self.IECdebug_lock.acquire() |
1297 self.IECdebug_lock.acquire() |
1301 if len(debug_vars) == len(self.TracedIECPath): |
1298 if len(debug_vars) == len(self.TracedIECPath): |
1302 if debug_getvar_retry > DEBUG_RETRIES_WARN: |
1299 if debug_getvar_retry > DEBUG_RETRIES_WARN: |
1303 self.logger.write(_("... debugger recovered\n")) |
1300 self.logger.write(_("... debugger recovered\n")) |
1331 else: |
1328 else: |
1332 self.logger.write(_("Debugger stopped.\n")) |
1329 self.logger.write(_("Debugger stopped.\n")) |
1333 self.DebugThread = None |
1330 self.DebugThread = None |
1334 |
1331 |
1335 def _connect_debug(self): |
1332 def _connect_debug(self): |
|
1333 self.previous_plcstate = None |
|
1334 self.previous_log_count = None |
1336 if self.AppFrame: |
1335 if self.AppFrame: |
1337 self.AppFrame.ResetGraphicViewers() |
1336 self.AppFrame.ResetGraphicViewers() |
1338 self.RegisterDebugVarToConnector() |
1337 self.RegisterDebugVarToConnector() |
1339 if self.DebugThread is None: |
1338 if self.DebugThread is None: |
1340 self.DebugThread = Thread(target=self.DebugThreadProc) |
1339 self.DebugThread = Thread(target=self.DebugThreadProc) |
1509 self.logger.write(_("Transfer completed successfully.\n")) |
1508 self.logger.write(_("Transfer completed successfully.\n")) |
1510 else: |
1509 else: |
1511 self.logger.write_error(_("Transfer failed\n")) |
1510 self.logger.write_error(_("Transfer failed\n")) |
1512 else: |
1511 else: |
1513 self.logger.write_error(_("No PLC to transfer (did build succeed ?)\n")) |
1512 self.logger.write_error(_("No PLC to transfer (did build succeed ?)\n")) |
|
1513 |
|
1514 self.previous_log_count = None |
1514 |
1515 |
1515 wx.CallAfter(self.UpdateMethodsFromPLCStatus) |
1516 wx.CallAfter(self.UpdateMethodsFromPLCStatus) |
1516 |
1517 |
1517 StatusMethods = [ |
1518 StatusMethods = [ |
1518 {"bitmap" : "Build", |
1519 {"bitmap" : "Build", |