Changes merged
authorlaurent
Wed, 09 Dec 2009 09:46:37 +0100
changeset 488 edbd8688a6a1
parent 487 1df4a28d3586 (diff)
parent 484 3d0c06e2648c (current diff)
child 489 e3adb9f63171
Changes merged
--- a/LPCBeremiz.py	Wed Dec 09 09:41:00 2009 +0100
+++ b/LPCBeremiz.py	Wed Dec 09 09:46:37 2009 +0100
@@ -359,12 +359,31 @@
          "name" : _("Build"),
          "tooltip" : _("Build project into build folder"),
          "method" : "_build"},
+        {"bitmap" : opjimg("Run"),
+         "name" : _("Run"),
+         "shown" : False,
+         "tooltip" : _("Start PLC"),
+         "method" : "_Run"},
+        {"bitmap" : opjimg("Stop"),
+         "name" : _("Stop"),
+         "shown" : False,
+         "tooltip" : _("Stop Running PLC"),
+         "method" : "_Stop"},
+        {"bitmap" : opjimg("Transfer"),
+         "name" : _("Transfer"),
+         "shown" : False,
+         "tooltip" : _("Transfer PLC"),
+         "method" : "_Transfer"},
     ]
 
     def __init__(self, frame, logger):
         PluginsRoot.__init__(self, frame, logger)
+        
         self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
 
+        self.OnlineMode = 0
+        self.OnlinePath = None
+
     def GetProjectName(self):
         return self.Project.getname()
 
@@ -378,6 +397,11 @@
     def SetProjectName(self, name):
         return self.Project.setname(name)
 
+    def SetOnlineMode(self, mode, path=None):
+        self.OnlineMode = mode
+        self.OnlinePath = path
+        self.UpdateMethodsFromPLCStatus()
+
     # Update a PLCOpenEditor Pou variable name
     def UpdateProjectVariableName(self, old_name, new_name):
         self.Project.updateElementName(old_name, new_name)
@@ -430,6 +454,42 @@
     def SaveProject(self):
         self.SaveXMLFile(self.ProjectPath)
 
+    ############# Real PLC object access #############
+    def UpdateMethodsFromPLCStatus(self):
+        # Get PLC state : Running or Stopped
+        # TODO : use explicit status instead of boolean
+        if self.OnlineMode == 0:
+            status = "Disconnected"
+        elif self.OnlineMode == 1:
+            status = "Connected"
+        elif self._connector is not None:
+            status = self._connector.GetPLCstatus()
+        else:
+            status = "Disconnected"
+        if(self.previous_plcstate != status):
+            for args in {
+                     "Started" :     [("_build", False),
+                                      ("_Run", False),
+                                      ("_Stop", True),
+                                      ("_Transfer", False)],
+                     "Stopped" :     [("_build", False),
+                                      ("_Run", True),
+                                      ("_Stop", False),
+                                      ("_Transfer", False)],
+                     "Connected" :   [("_build", False),
+                                      ("_Run", False),
+                                      ("_Stop", False),
+                                      ("_Transfer", True)],
+                     "Disconnected" :[("_build", True),
+                                      ("_Run", False),
+                                      ("_Stop", False),
+                                      ("_Transfer", False)],
+                   }.get(status,[]):
+                self.ShowMethod(*args)
+            self.previous_plcstate = status
+            return True
+        return False
+
 #-------------------------------------------------------------------------------
 #                              LPCBeremiz Class
 #-------------------------------------------------------------------------------
@@ -785,6 +845,10 @@
             self.PluginRoot.SetProjectName(name)
             self.RestartTimer()
         
+        def SetOnlineMode(self, mode, path=None):
+            self.PluginRoot.SetOnlineMode(mode, path)
+            self.RestartTimer()
+        
         def AddBus(self, iec_channel, name, icon=None):
             for child in self.PluginRoot.IterChilds():
                 if child.BaseParams.getName() == name:
@@ -1007,6 +1071,7 @@
                                        "Close": ([], 0),
                                        "Compile": ([], 0),
                                        "SetProjectName": ([str], 0),
+                                       "SetOnlineMode": ([int, str], 1),
                                        "AddBus": ([int, str, str], 1),
                                        "RenameBus": ([int, str], 0),
                                        "ChangeBusIECChannel": ([int, int], 0),
--- a/connectors/PYRO/__init__.py	Wed Dec 09 09:41:00 2009 +0100
+++ b/connectors/PYRO/__init__.py	Wed Dec 09 09:46:37 2009 +0100
@@ -56,6 +56,9 @@
         def catcher_func(*args,**kwargs):
             try:
                 return func(*args,**kwargs)
+            except Pyro.errors.ConnectionClosedError, e:
+                pluginsroot.logger.write_error("Connection lost!\n")
+                pluginsroot._connector = None
             except Exception,e:
                 #pluginsroot.logger.write_error(traceback.format_exc())
                 errmess = ''.join(Pyro.util.getPyroTraceback(e))
--- a/plugger.py	Wed Dec 09 09:41:00 2009 +0100
+++ b/plugger.py	Wed Dec 09 09:46:37 2009 +0100
@@ -1540,9 +1540,10 @@
     def UpdateMethodsFromPLCStatus(self):
         # Get PLC state : Running or Stopped
         # TODO : use explicit status instead of boolean
+        status = None
         if self._connector is not None:
             status = self._connector.GetPLCstatus()
-        else:
+        if status is None:
             status = "Disconnected"
         if(self.previous_plcstate != status):
             for args in {
@@ -1568,6 +1569,7 @@
         if self._connector is None:
             self.StatusTimer.Stop()
         if self.UpdateMethodsFromPLCStatus():
+            
             status = _(self.previous_plcstate)
             {"Broken": self.logger.write_error,
              None: lambda x: None}.get(
--- a/targets/Linux/plc_Linux_main.c	Wed Dec 09 09:41:00 2009 +0100
+++ b/targets/Linux/plc_Linux_main.c	Wed Dec 09 09:46:37 2009 +0100
@@ -159,6 +159,8 @@
     pthread_mutex_lock(&debug_mutex);
     /*__DEBUG is protected by this mutex */
     __DEBUG = !disable;
+    if (disable)
+    	pthread_mutex_unlock(&debug_mutex);
 }
 
 void resumeDebug(void)