59 from PLCControler import PLCControler |
59 from PLCControler import PLCControler |
60 from plcopen.structures import IEC_KEYWORDS |
60 from plcopen.structures import IEC_KEYWORDS |
61 from plcopen.types_enums import ComputeConfigurationResourceName, ITEM_CONFNODE |
61 from plcopen.types_enums import ComputeConfigurationResourceName, ITEM_CONFNODE |
62 import targets |
62 import targets |
63 from runtime.typemapping import DebugTypesSize, UnpackDebugBuffer |
63 from runtime.typemapping import DebugTypesSize, UnpackDebugBuffer |
|
64 from runtime import PlcStatus |
64 from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage |
65 from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage |
65 |
66 |
66 base_folder = paths.AbsParentDir(__file__) |
67 base_folder = paths.AbsParentDir(__file__) |
67 |
68 |
68 MATIEC_ERROR_MODEL = re.compile( |
69 MATIEC_ERROR_MODEL = re.compile( |
796 # Invoke compiler. |
797 # Invoke compiler. |
797 # Output files are listed to stdout, errors to stderr |
798 # Output files are listed to stdout, errors to stderr |
798 status, result, err_result = ProcessLogger(self.logger, buildcmd, |
799 status, result, err_result = ProcessLogger(self.logger, buildcmd, |
799 no_stdout=True, |
800 no_stdout=True, |
800 no_stderr=True).spin() |
801 no_stderr=True).spin() |
801 except Exception, e: |
802 except Exception as e: |
802 self.logger.write_error(buildcmd + "\n") |
803 self.logger.write_error(buildcmd + "\n") |
803 self.logger.write_error(repr(e) + "\n") |
804 self.logger.write_error(repr(e) + "\n") |
804 return False |
805 return False |
805 |
806 |
806 if status: |
807 if status: |
1326 if self._ProjectFilesView is None: |
1327 if self._ProjectFilesView is None: |
1327 self._ProjectFilesView = FileManagementPanel( |
1328 self._ProjectFilesView = FileManagementPanel( |
1328 self.AppFrame.TabsOpened, self, name, self._getProjectFilesPath(), True) |
1329 self.AppFrame.TabsOpened, self, name, self._getProjectFilesPath(), True) |
1329 |
1330 |
1330 extensions = [] |
1331 extensions = [] |
1331 for extension, name, editor in features.file_editors: |
1332 for extension, _name, _editor in features.file_editors: |
1332 if extension not in extensions: |
1333 if extension not in extensions: |
1333 extensions.append(extension) |
1334 extensions.append(extension) |
1334 self._ProjectFilesView.SetEditableFileExtensions(extensions) |
1335 self._ProjectFilesView.SetEditableFileExtensions(extensions) |
1335 |
1336 |
1336 if self._ProjectFilesView is not None: |
1337 if self._ProjectFilesView is not None: |
1425 "_Connect": True, |
1426 "_Connect": True, |
1426 "_Disconnect": False |
1427 "_Disconnect": False |
1427 } |
1428 } |
1428 |
1429 |
1429 MethodsFromStatus = { |
1430 MethodsFromStatus = { |
1430 "Started": {"_Stop": True, |
1431 PlcStatus.Started: {"_Stop": True, |
1431 "_Transfer": True, |
1432 "_Transfer": True, |
1432 "_Connect": False, |
1433 "_Connect": False, |
1433 "_Disconnect": True}, |
1434 "_Disconnect": True}, |
1434 "Stopped": {"_Run": True, |
1435 PlcStatus.Stopped: {"_Run": True, |
1435 "_Transfer": True, |
1436 "_Transfer": True, |
1436 "_Connect": False, |
1437 "_Connect": False, |
1437 "_Disconnect": True}, |
1438 "_Disconnect": True}, |
1438 "Empty": {"_Transfer": True, |
1439 PlcStatus.Empty: {"_Transfer": True, |
1439 "_Connect": False, |
1440 "_Connect": False, |
1440 "_Disconnect": True}, |
1441 "_Disconnect": True}, |
1441 "Broken": {"_Connect": False, |
1442 PlcStatus.Broken: {"_Connect": False, |
1442 "_Disconnect": True}, |
1443 "_Disconnect": True}, |
1443 "Disconnected": {}, |
1444 PlcStatus.Disconnected: {}, |
1444 } |
1445 } |
1445 |
1446 |
1446 def UpdateMethodsFromPLCStatus(self): |
1447 def UpdateMethodsFromPLCStatus(self): |
1447 updated = False |
1448 updated = False |
1448 status = None |
1449 status = None |
1451 if PLCstatus is not None: |
1452 if PLCstatus is not None: |
1452 status, log_count = PLCstatus |
1453 status, log_count = PLCstatus |
1453 self.UpdatePLCLog(log_count) |
1454 self.UpdatePLCLog(log_count) |
1454 if status is None: |
1455 if status is None: |
1455 self._SetConnector(None, False) |
1456 self._SetConnector(None, False) |
1456 status = "Disconnected" |
1457 status = PlcStatus.Disconnected |
1457 if self.previous_plcstate != status: |
1458 if self.previous_plcstate != status: |
1458 allmethods = self.DefaultMethods.copy() |
1459 allmethods = self.DefaultMethods.copy() |
1459 allmethods.update( |
1460 allmethods.update( |
1460 self.MethodsFromStatus.get(status, {})) |
1461 self.MethodsFromStatus.get(status, {})) |
1461 for method, active in allmethods.items(): |
1462 for method, active in allmethods.items(): |
1462 self.ShowMethod(method, active) |
1463 self.ShowMethod(method, active) |
1463 self.previous_plcstate = status |
1464 self.previous_plcstate = status |
1464 if self.AppFrame is not None: |
1465 if self.AppFrame is not None: |
1465 updated = True |
1466 updated = True |
1466 self.AppFrame.RefreshStatusToolBar() |
1467 self.AppFrame.RefreshStatusToolBar() |
1467 if status == "Disconnected": |
1468 if status == PlcStatus.Disconnected: |
1468 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1469 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1469 self.GetTextStatus(status), 1) |
1470 _(status), 1) |
1470 self.AppFrame.ConnectionStatusBar.SetStatusText('', 2) |
1471 self.AppFrame.ConnectionStatusBar.SetStatusText('', 2) |
1471 else: |
1472 else: |
1472 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1473 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1473 _("Connected to URI: %s") % self.BeremizRoot.getURI_location().strip(), 1) |
1474 _("Connected to URI: %s") % self.BeremizRoot.getURI_location().strip(), 1) |
1474 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1475 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1475 self.GetTextStatus(status), 2) |
1476 _(status), 2) |
1476 return updated |
1477 return updated |
1477 |
|
1478 def GetTextStatus(self, status): |
|
1479 msgs = { |
|
1480 "Started": _("Started"), |
|
1481 "Stopped": _("Stopped"), |
|
1482 "Empty": _("Empty"), |
|
1483 "Broken": _("Broken"), |
|
1484 "Disconnected": _("Disconnected") |
|
1485 } |
|
1486 return msgs.get(status, status) |
|
1487 |
1478 |
1488 def ShowPLCProgress(self, status="", progress=0): |
1479 def ShowPLCProgress(self, status="", progress=0): |
1489 self.AppFrame.ProgressStatusBar.Show() |
1480 self.AppFrame.ProgressStatusBar.Show() |
1490 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1481 self.AppFrame.ConnectionStatusBar.SetStatusText( |
1491 self.GetTextStatus(status), 1) |
1482 _(status), 1) |
1492 self.AppFrame.ProgressStatusBar.SetValue(progress) |
1483 self.AppFrame.ProgressStatusBar.SetValue(progress) |
1493 |
1484 |
1494 def HidePLCProgress(self): |
1485 def HidePLCProgress(self): |
1495 # clear previous_plcstate to restore status |
1486 # clear previous_plcstate to restore status |
1496 # in UpdateMethodsFromPLCStatus() |
1487 # in UpdateMethodsFromPLCStatus() |
1504 def SnapshotAndResetDebugValuesBuffers(self): |
1495 def SnapshotAndResetDebugValuesBuffers(self): |
1505 if self._connector is not None: |
1496 if self._connector is not None: |
1506 plc_status, Traces = self._connector.GetTraceVariables() |
1497 plc_status, Traces = self._connector.GetTraceVariables() |
1507 # print [dict.keys() for IECPath, (dict, log, status, fvalue) in |
1498 # print [dict.keys() for IECPath, (dict, log, status, fvalue) in |
1508 # self.IECdebug_datas.items()] |
1499 # self.IECdebug_datas.items()] |
1509 if plc_status == "Started": |
1500 if plc_status == PlcStatus.Started: |
1510 if len(Traces) > 0: |
1501 if len(Traces) > 0: |
1511 for debug_tick, debug_buff in Traces: |
1502 for debug_tick, debug_buff in Traces: |
1512 debug_vars = UnpackDebugBuffer( |
1503 debug_vars = UnpackDebugBuffer( |
1513 debug_buff, self.TracedIECTypes) |
1504 debug_buff, self.TracedIECTypes) |
1514 if debug_vars is not None and len(debug_vars) == len(self.TracedIECPath): |
1505 if debug_vars is not None and len(debug_vars) == len(self.TracedIECPath): |
1573 self.TracedIECPath = [] |
1564 self.TracedIECPath = [] |
1574 self._connector.SetTraceVariablesList([]) |
1565 self._connector.SetTraceVariablesList([]) |
1575 self.SnapshotAndResetDebugValuesBuffers() |
1566 self.SnapshotAndResetDebugValuesBuffers() |
1576 |
1567 |
1577 def IsPLCStarted(self): |
1568 def IsPLCStarted(self): |
1578 return self.previous_plcstate == "Started" |
1569 return self.previous_plcstate == PlcStatus.Started |
1579 |
1570 |
1580 def ReArmDebugRegisterTimer(self): |
1571 def ReArmDebugRegisterTimer(self): |
1581 if self.DebugTimer is not None: |
1572 if self.DebugTimer is not None: |
1582 self.DebugTimer.cancel() |
1573 self.DebugTimer.cancel() |
1583 |
1574 |
1812 else: |
1803 else: |
1813 self.CompareLocalAndRemotePLC() |
1804 self.CompareLocalAndRemotePLC() |
1814 |
1805 |
1815 # Init with actual PLC status and print it |
1806 # Init with actual PLC status and print it |
1816 self.UpdateMethodsFromPLCStatus() |
1807 self.UpdateMethodsFromPLCStatus() |
1817 if self.previous_plcstate in ["Started", "Stopped"]: |
1808 if self.previous_plcstate in [PlcStatus.Started, PlcStatus.Stopped]: |
1818 if self.DebugAvailable() and self.GetIECProgramsAndVariables(): |
1809 if self.DebugAvailable() and self.GetIECProgramsAndVariables(): |
1819 self.logger.write(_("Debugger ready\n")) |
1810 self.logger.write(_("Debugger ready\n")) |
1820 self._connect_debug() |
1811 self._connect_debug() |
1821 else: |
1812 else: |
1822 self.logger.write_warning( |
1813 self.logger.write_warning( |