--- a/plugger.py Thu May 28 13:29:23 2009 +0200
+++ b/plugger.py Thu May 28 13:40:29 2009 +0200
@@ -708,12 +708,17 @@
self.ResetIECProgramsAndVariables()
+ # Timer to pull PLC status + ID_STATUSTIMER = wx.NewId() + self.StatusTimer = wx.Timer(self.AppFrame, ID_STATUSTIMER) + self.AppFrame.Bind(wx.EVT_TIMER, self.PullPLCStatusProc, self.StatusTimer) #This method are not called here... but in NewProject and OpenProject
#self._AddParamsMembers()
# In both new or load scenario, no need to save
- self.ChangesToSave = False
+ self.ChangesToSave = False # Keep track of the plugin type name
@@ -725,6 +730,9 @@
+ self.previous_plcstate = None + self.StatusPrint = {"Broken": self.logger.write_error, # copy PluginMethods so that it can be later customized
self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
@@ -1399,7 +1407,6 @@
# TODO : use explicit status instead of boolean
if self._connector is not None:
status = self._connector.GetPLCstatus()
- self.logger.write("PLC is %s\n"%status)
@@ -1415,20 +1422,28 @@
"Dirty": [("_Run", True),
+ "Broken": [("_Run", True), "Disconnected": [("_Run", False),
+ def PullPLCStatusProc(self, event): + current_status = self.UpdateMethodsFromPLCStatus() + if current_status != self.previous_plcstate: + self.previous_plcstate = current_status + self.StatusPrint.get(current_status, self.logger.write)("PLC is %s\n"%current_status) + self.AppFrame.RefreshAll() - if self._connector.StartPLC():
- self.logger.write("Starting PLC\n")
- self.logger.write_error("Couldn't start PLC !\n")
+ self._connector.StartPLC() self.UpdateMethodsFromPLCStatus()
def RegisterDebugVarToConnector(self):
@@ -1569,8 +1584,8 @@
- if self.GetIECProgramsAndVariables() and \
- self._connector.StartPLC(debug=True):
+ if self.GetIECProgramsAndVariables(): + self._connector.StartPLC(debug=True) self.logger.write("Starting PLC (debug mode)\n")
if self.PLCDebug is None:
self.RefreshPluginsBlockLists()
@@ -1613,9 +1628,7 @@
self.logger.write("Stopping debug\n")
- if self._connector.StopPLC():
- self.logger.write("Stopping PLC\n")
+ if not self._connector.StopPLC(): self.logger.write_error("Couldn't stop PLC !\n")
self.UpdateMethodsFromPLCStatus()
@@ -1662,7 +1675,13 @@
self.ShowMethod("_Transfer", True)
self.CompareLocalAndRemotePLC()
- self.UpdateMethodsFromPLCStatus()
+ # Init with actual PLC status and print it + self.previous_plcstate = self.UpdateMethodsFromPLCStatus() + self.logger.write("PLC is %s\n"%self.previous_plcstate) + # Start the status Timer + self.StatusTimer.Start(milliseconds=500, oneShot=False) def CompareLocalAndRemotePLC(self):
if self._connector is None:
@@ -1691,6 +1710,7 @@
self.ShowMethod("_Transfer", False)
self.ShowMethod("_Connect", True)
self.ShowMethod("_Disconnect", False)
+ self.StatusTimer.Stop() self.UpdateMethodsFromPLCStatus()
--- a/runtime/PLCObject.py Thu May 28 13:29:23 2009 +0200
+++ b/runtime/PLCObject.py Thu May 28 13:40:29 2009 +0200
@@ -237,57 +237,62 @@
self.python_threads_vars = None
- def PythonThreadProc(self):
+ def PythonThreadProc(self, debug): PLCprint("PythonThreadProc started")
- self.evaluator(self.PrepareRuntimePy)
- res,cmd = "None","None"
- while self.PLCStatus == "Started":
- #print "_PythonIterator(", res, ")",
- cmd = self._PythonIterator(res)
- res = str(self.evaluator(eval,cmd,self.python_threads_vars))
- res = "#EXCEPTION : "+str(e)
- self.evaluator(self.FinishRuntimePy)
- PLCprint("PythonThreadProc interrupted")
- def StartPLC(self, debug=False):
- if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped":
- c_argv = ctypes.c_char_p * len(self.argv)
- if self._LoadNewPLC() and self._startPLC(len(self.argv),c_argv(*self.argv)) == 0:
+ c_argv = ctypes.c_char_p * len(self.argv) + if self._startPLC(len(self.argv),c_argv(*self.argv)) == 0: self._RegisterDebugVariable(idx)
self.PLCStatus = "Started"
- self.PythonThread = Thread(target=self.PythonThreadProc)
- self.PythonThread.start()
+ self.evaluator(self.PrepareRuntimePy) + res,cmd = "None","None" + while self.PLCStatus == "Started": + #print "_PythonIterator(", res, ")", + cmd = self._PythonIterator(res) + res = str(self.evaluator(eval,cmd,self.python_threads_vars)) + res = "#EXCEPTION : "+str(e) + self.PLCStatus = "Stopped" + self.evaluator(self.FinishRuntimePy) - PLCprint("Problem starting PLC")
+ PLCprint("Problem %s PLC"%error) + self.PLCStatus = "Broken" + PLCprint("PythonThreadProc interrupted") + def StartPLC(self, debug=False): + if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped": + self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug]) + self.PythonThread.start() - self.PLCStatus = "Stopped"
- if self.PythonThread.isAlive():
- self.PythonThread.join()
- self.PLCStatus = "Dirty"
if self.PLCStatus == "Started":
+ self.PLCStatus = "Stopped" @@ -308,7 +313,7 @@
def NewPLC(self, md5sum, data, extrafiles):
PLCprint("NewPLC (%s)"%md5sum)
- if self.PLCStatus in ["Stopped", "Empty", "Dirty"]:
+ if self.PLCStatus in ["Stopped", "Empty", "Dirty", "Broken"]: NewFileName = md5sum + lib_ext
extra_files_log = os.path.join(self.workingdir,"extra_files.txt")