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