Merged
authorLaurent Bessard
Wed, 24 Apr 2013 17:37:46 +0200
changeset 1062 fd7c9a7cf882
parent 1053 b0ac30ba7eaf (diff)
parent 1061 02f371f3e063 (current diff)
child 1063 9b5995303db1
Merged
ProjectController.py
wxglade_hmi/wxglade_hmi.py
--- a/Beremiz_service.py	Wed Apr 24 17:27:08 2013 +0200
+++ b/Beremiz_service.py	Wed Apr 24 17:37:46 2013 +0200
@@ -385,7 +385,7 @@
             
             def _LiveShellLocals(self):
                 if self.pyroserver.plcobj is not None:
-                    return {"locals":self.pyroserver.plcobj.python_threads_vars}
+                    return {"locals":self.pyroserver.plcobj.python_runtime_vars}
                 else:
                     return {}
             
@@ -425,8 +425,8 @@
 def default_evaluator(tocall, *args, **kwargs):
     try:
         res=(tocall(*args,**kwargs), None)
-    except Exception,exp:
-        res=(None, exp)
+    except Exception:
+        res=(None, sys.exc_info())
     return res
 
 class Server():
--- a/NativeLib.xml	Wed Apr 24 17:27:08 2013 +0200
+++ b/NativeLib.xml	Wed Apr 24 17:37:46 2013 +0200
@@ -74,8 +74,7 @@
           <ST>
 <![CDATA[IF TRIG AND NOT TRIG0 THEN
 {{
- extern int LogMessage(uint8_t, uint8_t*, uint32_t);
- LogMessage(GetFbVar(LEVEL),GetFbVar(MSG, .body),GetFbVar(MSG, .len));
+ LogMessage(GetFbVar(LEVEL),(char*)GetFbVar(MSG, .body),GetFbVar(MSG, .len));
 }}
 END_IF;
 TRIG0:=TRIG;
--- a/ProjectController.py	Wed Apr 24 17:27:08 2013 +0200
+++ b/ProjectController.py	Wed Apr 24 17:37:46 2013 +0200
@@ -608,6 +608,15 @@
             return False
         # transform those base names to full names with path
         C_files = map(lambda filename:os.path.join(buildpath, filename), C_files)
+
+        # prepend beremiz include to configuration header
+        H_files = [ fname for fname in result.splitlines() if fname[-2:]==".h" or fname[-2:]==".H" ]
+        H_files.remove("LOCATED_VARIABLES.h")
+        H_files = map(lambda filename:os.path.join(buildpath, filename), H_files)
+        for H_file in H_files:
+            with file(H_file, 'r') as original: data = original.read()
+            with file(H_file, 'w') as modified: modified.write('#include "beremiz.h"\n' + data)
+
         self.logger.write(_("Extracting Located Variables...\n"))
         # Keep track of generated located variables for later use by self._Generate_C
         self.PLCGeneratedLocatedVars = self.GetLocations()
--- a/runtime/PLCObject.py	Wed Apr 24 17:27:08 2013 +0200
+++ b/runtime/PLCObject.py	Wed Apr 24 17:37:46 2013 +0200
@@ -243,13 +243,10 @@
         Calls init, start, stop or cleanup method provided by 
         runtime python files, loaded when new PLC uploaded
         """
-        try :
-            for method in self.python_runtime_vars.get("_runtime_%s"%methodname, []):
-                res,exp = self.evaluator(method)
-                if exp is not None: raise(exp)
-        except:
-            self.LogMessage(0,traceback.format_exc())
-            raise
+        for method in self.python_runtime_vars.get("_runtime_%s"%methodname, []):
+            res,exp = self.evaluator(method)
+            if exp is not None: 
+                self.LogMessage(0,'\n'.join(traceback.format_exception(*exp)))
 
     def PythonRuntimeInit(self):
         MethodNames = ["init", "start", "stop", "cleanup"]
@@ -312,7 +309,9 @@
                     compile_cache[FBID]=(cmd,AST)
                 result,exp = self.evaluator(eval,cmd,self.python_runtime_vars)
                 if exp is not None: 
-                    raise(exp)
+                    res = "#EXCEPTION : "+str(exp[1])
+                    self.LogMessage(1,('PyEval@0x%x(Code="%s") Exception "%s"')%(FBID,cmd,
+                        '\n'.join(traceback.format_exception(*exp))))
                 else:
                     res=str(result)
                 self.python_runtime_vars["FBID"]=None
--- a/targets/beremiz.h	Wed Apr 24 17:27:08 2013 +0200
+++ b/targets/beremiz.h	Wed Apr 24 17:37:46 2013 +0200
@@ -10,4 +10,5 @@
 
 extern unsigned long long common_ticktime__;
 int LogMessage(uint8_t level, char* buf, uint32_t size);
+long AtomicCompareExchange(long* atomicvar,long compared, long exchange);
 
--- a/wxglade_hmi/wxglade_hmi.py	Wed Apr 24 17:27:08 2013 +0200
+++ b/wxglade_hmi/wxglade_hmi.py	Wed Apr 24 17:37:46 2013 +0200
@@ -102,7 +102,7 @@
     %(name)s.Show()
 """ % {"name": x[0], "class": x[1]},
                              hmi_frames.items())),
-       "cleanup": "\n    ".join(map(lambda x:"%s.Destroy()" % x, hmi_frames.keys()))})
+       "cleanup": "\n    ".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys()))})
         runtimefile.close()
         
         return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb"))