runtime/PLCObject.py
changeset 446 1edde533db19
parent 411 8261c8f1e365
child 450 18583d13f0fa
equal deleted inserted replaced
441:379c66468cf6 446:1edde533db19
   254         PLCprint("PythonThreadProc interrupted")
   254         PLCprint("PythonThreadProc interrupted")
   255     
   255     
   256     def StartPLC(self, debug=False):
   256     def StartPLC(self, debug=False):
   257         PLCprint("StartPLC")
   257         PLCprint("StartPLC")
   258         if self.CurrentPLCFilename is not None:
   258         if self.CurrentPLCFilename is not None:
   259             self.PLCStatus = "Starting"
   259             self.PLCStatus = "Started"
   260             self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug])
   260             self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug])
   261             self.PythonThread.start()
   261             self.PythonThread.start()
   262             
   262             
   263     def StopPLC(self):
   263     def StopPLC(self):
   264         PLCprint("StopPLC")
   264         PLCprint("StopPLC")
   376         """
   376         """
   377         Return a list of variables, corresponding to the list of required idx
   377         Return a list of variables, corresponding to the list of required idx
   378         """
   378         """
   379         if self.PLCStatus == "Started":
   379         if self.PLCStatus == "Started":
   380             self.PLClibraryLock.acquire()
   380             self.PLClibraryLock.acquire()
   381             tick = self._WaitDebugData()
   381             tick = ctypes.c_int()
   382             #PLCprint("Debug tick : %d"%tick)
   382             #PLCprint("Debug tick : %d"%tick)
   383             if tick == 2**32 - 1:
   383             if self._WaitDebugData(ctypes.byref(tick)) != 0:
   384                 tick = -1
       
   385                 res = None
       
   386             else:
       
   387                 idx = ctypes.c_int()
   384                 idx = ctypes.c_int()
   388                 typename = ctypes.c_char_p()
   385                 typename = ctypes.c_char_p()
   389                 res = []
   386                 res = []
   390         
       
   391                 for given_idx in self._Idxs:
   387                 for given_idx in self._Idxs:
   392                     buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename))
   388                     buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename))
   393                     c_type,unpack_func = self.TypeTranslator.get(typename.value, (None,None))
   389                     c_type,unpack_func = self.TypeTranslator.get(typename.value, (None,None))
   394                     if c_type is not None and given_idx == idx.value:
   390                     if c_type is not None and given_idx == idx.value:
   395                         res.append(unpack_func(ctypes.cast(buffer,
   391                         res.append(unpack_func(ctypes.cast(buffer,
   397                     else:
   393                     else:
   398                         PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value))
   394                         PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value))
   399                         res.append(None)
   395                         res.append(None)
   400             self._FreeDebugData()
   396             self._FreeDebugData()
   401             self.PLClibraryLock.release()
   397             self.PLClibraryLock.release()
   402             return tick, res
   398             return self.PLCStatus, tick, res
   403         return -1, None
   399         return self.PLCStatus, None, None
   404 
   400