runtime/PLCObject.py
changeset 1052 fa7c5034c1d2
parent 1051 847d68c3e7ff
child 1074 92a009dc5826
equal deleted inserted replaced
1051:847d68c3e7ff 1052:fa7c5034c1d2
   244         runtime python files, loaded when new PLC uploaded
   244         runtime python files, loaded when new PLC uploaded
   245         """
   245         """
   246         for method in self.python_runtime_vars.get("_runtime_%s"%methodname, []):
   246         for method in self.python_runtime_vars.get("_runtime_%s"%methodname, []):
   247             res,exp = self.evaluator(method)
   247             res,exp = self.evaluator(method)
   248             if exp is not None: 
   248             if exp is not None: 
   249                 self.LogMessage(0,traceback.format_exception(*exp))
   249                 self.LogMessage(0,'\n'.join(traceback.format_exception(*exp)))
   250 
   250 
   251     def PythonRuntimeInit(self):
   251     def PythonRuntimeInit(self):
   252         MethodNames = ["init", "start", "stop", "cleanup"]
   252         MethodNames = ["init", "start", "stop", "cleanup"]
   253         self.python_runtime_vars = globals().copy()
   253         self.python_runtime_vars = globals().copy()
   254         self.python_runtime_vars["WorkingDir"] = self.workingdir
   254         self.python_runtime_vars["WorkingDir"] = self.workingdir
   307                 if ccmd is None or ccmd!=cmd:
   307                 if ccmd is None or ccmd!=cmd:
   308                     AST = compile(cmd, '<plc>', 'eval')
   308                     AST = compile(cmd, '<plc>', 'eval')
   309                     compile_cache[FBID]=(cmd,AST)
   309                     compile_cache[FBID]=(cmd,AST)
   310                 result,exp = self.evaluator(eval,cmd,self.python_runtime_vars)
   310                 result,exp = self.evaluator(eval,cmd,self.python_runtime_vars)
   311                 if exp is not None: 
   311                 if exp is not None: 
   312                     raise(exp[1])
   312                     res = "#EXCEPTION : "+str(exp[1])
       
   313                     self.LogMessage(1,('PyEval@0x%x(Code="%s") Exception "%s"')%(FBID,cmd,
       
   314                         '\n'.join(traceback.format_exception(*exp))))
   313                 else:
   315                 else:
   314                     res=str(result)
   316                     res=str(result)
   315                 self.python_runtime_vars["FBID"]=None
   317                 self.python_runtime_vars["FBID"]=None
   316             except Exception,e:
   318             except Exception,e:
   317                 res = "#EXCEPTION : "+str(e)
   319                 res = "#EXCEPTION : "+str(e)