runtime/PLCObject.py
changeset 2669 be233279d179
parent 2649 db68cb0e6bdc
child 2678 45f1ff6a7f87
equal deleted inserted replaced
2668:cca3e5d7d6f3 2669:be233279d179
    97         self.python_runtime_vars = None
    97         self.python_runtime_vars = None
    98         self.TraceThread = None
    98         self.TraceThread = None
    99         self.TraceLock = Lock()
    99         self.TraceLock = Lock()
   100         self.Traces = []
   100         self.Traces = []
   101         self.DebugToken = 0
   101         self.DebugToken = 0
   102         # Callbacks used by web settings extensions (e.g.: BACnet_config.py, Modbus_config.py)
       
   103         self.LoadCallbacks   = {} # list of functions to call when PLC is   loaded
       
   104         self.UnLoadCallbacks = {} # list of functions to call when PLC is unloaded
       
   105 
   102 
   106         self._init_blobs()
   103         self._init_blobs()
   107 
   104 
   108     # First task of worker -> no @RunInMain
   105     # First task of worker -> no @RunInMain
   109     def AutoLoad(self, autostart):
   106     def AutoLoad(self, autostart):
   168                 return self._log_read_buffer.value, tick.value, tv_sec.value, tv_nsec.value
   165                 return self._log_read_buffer.value, tick.value, tv_sec.value, tv_nsec.value
   169         elif self._loading_error is not None and level == 0:
   166         elif self._loading_error is not None and level == 0:
   170             return self._loading_error, 0, 0, 0
   167             return self._loading_error, 0, 0, 0
   171         return None
   168         return None
   172 
   169 
   173     def RegisterCallbackLoad(self, ExtensionName, ExtensionCallback):
       
   174         """
       
   175         Register function to be called when PLC is loaded
       
   176         ExtensionName: a string with the name of the extension asking to register the callback 
       
   177         ExtensionCallback: the function to be called...
       
   178         """
       
   179         self.LoadCallbacks[ExtensionName] = ExtensionCallback
       
   180 
       
   181     def RegisterCallbackUnLoad(self, ExtensionName, ExtensionCallback):
       
   182         """
       
   183         Register function to be called when PLC is unloaded
       
   184         ExtensionName: a string with the name of the extension asking to register the callback 
       
   185         ExtensionCallback: the function to be called...
       
   186         """
       
   187         self.UnLoadCallbacks[ExtensionName] = ExtensionCallback
       
   188 
       
   189     def _GetMD5FileName(self):
   170     def _GetMD5FileName(self):
   190         return os.path.join(self.workingdir, "lasttransferedPLC.md5")
   171         return os.path.join(self.workingdir, "lasttransferedPLC.md5")
   191 
   172 
   192     def _GetLibFileName(self):
   173     def _GetLibFileName(self):
   193         return os.path.join(self.workingdir, self.CurrentPLCFilename)
   174         return os.path.join(self.workingdir, self.CurrentPLCFilename)
   287     @RunInMain
   268     @RunInMain
   288     def LoadPLC(self):
   269     def LoadPLC(self):
   289         res = self._LoadPLC()
   270         res = self._LoadPLC()
   290         if res:
   271         if res:
   291             self.PythonRuntimeInit()
   272             self.PythonRuntimeInit()
   292             for name, callbackFunc in self.LoadCallbacks.items():
       
   293                 callbackFunc()
       
   294         else:
   273         else:
   295             self._FreePLC()
   274             self._FreePLC()
   296 
   275 
   297         return res
   276         return res
   298 
   277 
   299     @RunInMain
   278     @RunInMain
   300     def UnLoadPLC(self):
   279     def UnLoadPLC(self):
   301         self.PythonRuntimeCleanup()
   280         self.PythonRuntimeCleanup()
   302         for name, callbackFunc in self.UnLoadCallbacks.items():
       
   303             callbackFunc()        
       
   304         self._FreePLC()
   281         self._FreePLC()
   305 
   282 
   306     def _InitPLCStubCalls(self):
   283     def _InitPLCStubCalls(self):
   307         """
   284         """
   308         create dummy C func proxies
   285         create dummy C func proxies