runtime/PLCObject.py
changeset 1847 6198190bc121
parent 1846 14b40afccd69
child 1850 614396cbffbf
equal deleted inserted replaced
1846:14b40afccd69 1847:6198190bc121
   269         """
   269         """
   270         Calls init, start, stop or cleanup method provided by
   270         Calls init, start, stop or cleanup method provided by
   271         runtime python files, loaded when new PLC uploaded
   271         runtime python files, loaded when new PLC uploaded
   272         """
   272         """
   273         for method in self.python_runtime_vars.get("_runtime_%s" % methodname, []):
   273         for method in self.python_runtime_vars.get("_runtime_%s" % methodname, []):
   274             res, exp = self.evaluator(method)
   274             _res, exp = self.evaluator(method)
   275             if exp is not None:
   275             if exp is not None:
   276                 self.LogMessage(0, '\n'.join(traceback.format_exception(*exp)))
   276                 self.LogMessage(0, '\n'.join(traceback.format_exception(*exp)))
   277 
   277 
   278     def PythonRuntimeInit(self):
   278     def PythonRuntimeInit(self):
   279         MethodNames = ["init", "start", "stop", "cleanup"]
   279         MethodNames = ["init", "start", "stop", "cleanup"]
   480             if self._suspendDebug(False) == 0:
   480             if self._suspendDebug(False) == 0:
   481                 # keep a copy of requested idx
   481                 # keep a copy of requested idx
   482                 self._ResetDebugVariables()
   482                 self._ResetDebugVariables()
   483                 for idx, iectype, force in idxs:
   483                 for idx, iectype, force in idxs:
   484                     if force is not None:
   484                     if force is not None:
   485                         c_type, unpack_func, pack_func = \
   485                         c_type, _unpack_func, pack_func = \
   486                             TypeTranslator.get(iectype,
   486                             TypeTranslator.get(iectype,
   487                                                (None, None, None))
   487                                                (None, None, None))
   488                         force = ctypes.byref(pack_func(c_type, force))
   488                         force = ctypes.byref(pack_func(c_type, force))
   489                     self._RegisterDebugVariable(idx, force)
   489                     self._RegisterDebugVariable(idx, force)
   490                 self._TracesSwap()
   490                 self._TracesSwap()
   556 
   556 
   557     def RemoteExec(self, script, *kwargs):
   557     def RemoteExec(self, script, *kwargs):
   558         try:
   558         try:
   559             exec script in kwargs
   559             exec script in kwargs
   560         except Exception:
   560         except Exception:
   561             e_type, e_value, e_traceback = sys.exc_info()
   561             _e_type, e_value, e_traceback = sys.exc_info()
   562             line_no = traceback.tb_lineno(get_last_traceback(e_traceback))
   562             line_no = traceback.tb_lineno(get_last_traceback(e_traceback))
   563             return (-1, "RemoteExec script failed!\n\nLine %d: %s\n\t%s" %
   563             return (-1, "RemoteExec script failed!\n\nLine %d: %s\n\t%s" %
   564                         (line_no, e_value, script.splitlines()[line_no - 1]))
   564                         (line_no, e_value, script.splitlines()[line_no - 1]))
   565         return (0, kwargs.get("returnVal", None))
   565         return (0, kwargs.get("returnVal", None))