--- a/Beremiz.py Sun Nov 29 18:57:49 2009 +0100
+++ b/Beremiz.py Tue Dec 01 13:41:29 2009 +0100
@@ -28,6 +28,7 @@
CWD = os.path.split(os.path.realpath(__file__))[0]
@@ -252,6 +253,8 @@
self.black_white = wx.TextAttr("BLACK", "WHITE")
self.default_style = None
+ # to prevent rapid fire on rising log panel def write(self, s, style = None):
if style is None : style=self.black_white
@@ -263,6 +266,10 @@
self.output.ScrollLines(s.count('\n')+1)
self.output.ShowPosition(self.output.GetLastPosition())
+ if newtime - self.rising_timer > 1: + self.rising_timer = newtime def write_warning(self, s):
self.write(s,self.red_white)
@@ -376,6 +383,7 @@
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
+ self.LogConsole.Rise = self.RiseLogConsole self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
@@ -422,6 +430,13 @@
self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+ def RiseLogConsole(self): + for idx in xrange(self.BottomNoteBook.GetPageCount()): + window = self.BottomNoteBook.GetPage(idx) + if window == self.LogConsole: + self.BottomNoteBook.SetSelection(idx) if self.PluginRoot is not None:
--- a/Beremiz_service.py Sun Nov 29 18:57:49 2009 +0100
+++ b/Beremiz_service.py Tue Dec 01 13:41:29 2009 +0100
@@ -415,7 +415,7 @@
def UpdateIcon(self, plcstatus):
if plcstatus is "Started" :
currenticon = self.MakeIcon(starticon.GetImage())
- elif plcstatus is "Stopped" or plcstatus is "Starting":
+ elif plcstatus is "Stopped": currenticon = self.MakeIcon(stopicon.GetImage())
currenticon = self.MakeIcon(defaulticon.GetImage())
--- a/connectors/PYRO/__init__.py Sun Nov 29 18:57:49 2009 +0100
+++ b/connectors/PYRO/__init__.py Tue Dec 01 13:41:29 2009 +0100
@@ -112,19 +112,13 @@
for safe use in from debug thread, must use the copy
- if self.RemotePLCObjectProxyCopy is not None and self.RemotePLCObjectProxyCopy.GetPLCstatus() == "Started":
- return self.RemotePLCObjectProxyCopy.GetTraceVariables()
- GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,(None,None))
+ return self.RemotePLCObjectProxyCopy.GetTraceVariables() + GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,("Broken",None,None)) - def _PyroPLCIsStarting(self):
- for safe use in from debug thread, must use the copy
- return self.RemotePLCObjectProxyCopy is not None and self.RemotePLCObjectProxyCopy.GetPLCstatus() == "Starting"
- PLCIsStarting = PyroCatcher(_PyroPLCIsStarting,False)
+ def _PyroGetPLCstatus(self): + return RemotePLCObjectProxy.GetPLCstatus() + GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, "Broken") def __getattr__(self, attrName):
member = self.__dict__.get(attrName, None)
--- a/plugger.py Sun Nov 29 18:57:49 2009 +0100
+++ b/plugger.py Tue Dec 01 13:41:29 2009 +0100
@@ -779,8 +779,6 @@
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]
@@ -1529,43 +1527,38 @@
status = self._connector.GetPLCstatus()
- "Starting" : [("_Run", True),
- "Started" : [("_Run", False),
- "Stopped" : [("_Run", True),
- "Empty" : [("_Run", False),
- "Broken" : [("_Run", True),
- "Disconnected" :[("_Run", False),
- ("_Disconnect", False)],
+ if(self.previous_plcstate != status): + "Started" : [("_Run", False), + "Stopped" : [("_Run", True), + "Empty" : [("_Run", False), + "Disconnected" :[("_Run", False), + ("_Disconnect", False)], + self.previous_plcstate = status - def PullPLCStatusProc(self, event):
+ def PullPLCStatusProc(self, event): if self._connector is None:
- current_status = self.UpdateMethodsFromPLCStatus()
- if current_status != self.previous_plcstate:
- self.previous_plcstate = current_status
- if current_status is not None:
- status = _(current_status)
- self.StatusPrint.get(current_status, self.logger.write)(_("PLC is %s\n")%status)
+ if self.UpdateMethodsFromPLCStatus(): + status = _(self.previous_plcstate) + {"Broken": self.logger.write_error, + None: lambda x: None}.get( + self.previous_plcstate, self.logger.write)(_("PLC is %s\n")%status) self.AppFrame.RefreshAll()
@@ -1681,23 +1674,21 @@
# This lock is used to avoid flooding wx event stack calling callafter
while (not self.debug_break) and (self._connector is not None):
- debug_tick, debug_vars = self._connector.GetTraceVariables()
+ plc_status, debug_tick, debug_vars = self._connector.GetTraceVariables() #print debug_tick, debug_vars
self.IECdebug_lock.acquire()
- if debug_vars is not None and \
- len(debug_vars) == len(self.TracedIECPath):
- for IECPath,value in zip(self.TracedIECPath, debug_vars):
- self.CallWeakcallables(IECPath, "NewValue", debug_tick, value)
- self.CallWeakcallables("__tick__", "NewDataAvailable")
- elif debug_vars is not None:
- wx.CallAfter(self.logger.write_warning,
- _("Debug data not coherent %d != %d\n")%(len(debug_vars), len(self.TracedIECPath)))
- #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
+ if debug_vars is not None: + if len(debug_vars) == len(self.TracedIECPath): + for IECPath,value in zip(self.TracedIECPath, debug_vars): + self.CallWeakcallables(IECPath, "NewValue", debug_tick, value) + self.CallWeakcallables("__tick__", "NewDataAvailable") + wx.CallAfter(self.logger.write_warning, + _("Debug data do not match requested variable count %d != %d\n")%(len(debug_vars), len(self.TracedIECPath))) - if self._connector.PLCIsStarting():
+ if plc_status == "Started": + # Be patient, tollerate PLC to come up before debugging wx.CallAfter(self.logger.write, _("Debugger disabled\n"))
@@ -1804,7 +1795,7 @@
self.CompareLocalAndRemotePLC()
# Init with actual PLC status and print it
- self.previous_plcstate = self.UpdateMethodsFromPLCStatus()
+ self.UpdateMethodsFromPLCStatus() if self.previous_plcstate is not None:
status = _(self.previous_plcstate)
--- a/runtime/PLCObject.py Sun Nov 29 18:57:49 2009 +0100
+++ b/runtime/PLCObject.py Tue Dec 01 13:41:29 2009 +0100
@@ -256,7 +256,7 @@
def StartPLC(self, debug=False):
if self.CurrentPLCFilename is not None:
- self.PLCStatus = "Starting"
+ self.PLCStatus = "Started" self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug])
self.PythonThread.start()
@@ -378,16 +378,12 @@
if self.PLCStatus == "Started":
self.PLClibraryLock.acquire()
- tick = self._WaitDebugData()
#PLCprint("Debug tick : %d"%tick)
+ if self._WaitDebugData(ctypes.byref(tick)) != 0: typename = ctypes.c_char_p()
for given_idx in self._Idxs:
buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename))
c_type,unpack_func = self.TypeTranslator.get(typename.value, (None,None))
@@ -399,6 +395,6 @@
self.PLClibraryLock.release()
+ return self.PLCStatus, tick, res + return self.PLCStatus, None, None --- a/targets/Linux/plc_Linux_main.c Sun Nov 29 18:57:49 2009 +0100
+++ b/targets/Linux/plc_Linux_main.c Tue Dec 01 13:41:29 2009 +0100
@@ -131,12 +131,12 @@
extern unsigned long __tick;
-/* from plc_debugger.c */
-unsigned long WaitDebugData()
+int WaitDebugData(unsigned long *tick) /* Wait signal from PLC thread */
- if(pthread_mutex_lock(&debug_wait_mutex)) return -1;
+ return pthread_mutex_lock(&debug_wait_mutex); /* Called by PLC thread when debug_publish finished
--- a/targets/Win32/plc_Win32_main.c Sun Nov 29 18:57:49 2009 +0100
+++ b/targets/Win32/plc_Win32_main.c Tue Dec 01 13:41:29 2009 +0100
@@ -170,10 +170,12 @@
/* from plc_debugger.c */
+int WaitDebugData(unsigned long *tick) unsigned long WaitDebugData()
- if(WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0) return -1;
+ /* Wait signal from PLC thread */ + return WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0; /* Called by PLC thread when debug_publish finished
--- a/targets/Xenomai/plc_Xenomai_main.c Sun Nov 29 18:57:49 2009 +0100
+++ b/targets/Xenomai/plc_Xenomai_main.c Tue Dec 01 13:41:29 2009 +0100
@@ -205,15 +205,16 @@
extern unsigned long __tick;
/* from plc_debugger.c */
-unsigned long WaitDebugData()
+int WaitDebugData(unsigned long *tick) /* Wait signal from PLC thread */
if (PLC_state & PLC_STATE_DEBUG_FILE_OPENED) {
res = read(WaitDebug_pipe_fd, &message, sizeof(char));
--- a/targets/plc_common_main.c Sun Nov 29 18:57:49 2009 +0100
+++ b/targets/plc_common_main.c Tue Dec 01 13:41:29 2009 +0100
@@ -23,7 +23,7 @@
-unsigned long __tick = -1;
+unsigned long __tick = 0; * Variable generated by C softPLC and plugins