runtime/PLCObject.py
changeset 462 274e83a5534e
parent 461 bcbc472c0ba8
child 465 67d32a91d70b
equal deleted inserted replaced
461:bcbc472c0ba8 462:274e83a5534e
   141             self._GetDebugData.restype = ctypes.c_int  
   141             self._GetDebugData.restype = ctypes.c_int  
   142             self._GetDebugData.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_void_p)]
   142             self._GetDebugData.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_void_p)]
   143 
   143 
   144             self._suspendDebug = self.PLClibraryHandle.suspendDebug
   144             self._suspendDebug = self.PLClibraryHandle.suspendDebug
   145             self._suspendDebug.restype = None
   145             self._suspendDebug.restype = None
       
   146             self._suspendDebug.argtypes = [ctypes.c_int]
   146 
   147 
   147             self._resumeDebug = self.PLClibraryHandle.resumeDebug
   148             self._resumeDebug = self.PLClibraryHandle.resumeDebug
   148             self._resumeDebug.restype = None
   149             self._resumeDebug.restype = None
   149             
   150             
   150             return True
   151             return True
   213             runtime_cleanup()    
   214             runtime_cleanup()    
   214         if self.website is not None:
   215         if self.website is not None:
   215             self.website.PLCStopped()
   216             self.website.PLCStopped()
   216         self.python_threads_vars = None
   217         self.python_threads_vars = None
   217 
   218 
   218     def PythonThreadProc(self, debug):
   219     def PythonThreadProc(self):
   219         PLCprint("PythonThreadProc started")
   220         PLCprint("PythonThreadProc started")
   220         c_argv = ctypes.c_char_p * len(self.argv)
   221         c_argv = ctypes.c_char_p * len(self.argv)
   221         error = None
   222         error = None
   222         if self._LoadNewPLC():
   223         if self._LoadNewPLC():
   223             if self._startPLC(len(self.argv),c_argv(*self.argv)) == 0:
   224             if self._startPLC(len(self.argv),c_argv(*self.argv)) == 0:
   224                 if debug:
       
   225                     for idx in self._Idxs:
       
   226                         self._RegisterDebugVariable(idx)
       
   227                     self._resumeDebug()
       
   228                 self.PLCStatus = "Started"
   225                 self.PLCStatus = "Started"
   229                 self.StatusChange()
   226                 self.StatusChange()
   230                 self.evaluator(self.PrepareRuntimePy)
   227                 self.evaluator(self.PrepareRuntimePy)
   231                 res,cmd = "None","None"
   228                 res,cmd = "None","None"
   232                 while True:
   229                 while True:
   251             PLCprint("Problem %s PLC"%error)
   248             PLCprint("Problem %s PLC"%error)
   252             self.PLCStatus = "Broken"
   249             self.PLCStatus = "Broken"
   253         self._FreePLC()
   250         self._FreePLC()
   254         PLCprint("PythonThreadProc interrupted")
   251         PLCprint("PythonThreadProc interrupted")
   255     
   252     
   256     def StartPLC(self, debug=False):
   253     def StartPLC(self):
   257         PLCprint("StartPLC")
   254         PLCprint("StartPLC")
   258         if self.CurrentPLCFilename is not None:
   255         if self.CurrentPLCFilename is not None:
   259             self.PLCStatus = "Started"
   256             self.PLCStatus = "Started"
   260             self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug])
   257             self.PythonThread = Thread(target=self.PythonThreadProc)
   261             self.PythonThread.start()
   258             self.PythonThread.start()
   262             
   259             
   263     def StopPLC(self):
   260     def StopPLC(self):
   264         PLCprint("StopPLC")
   261         PLCprint("StopPLC")
   265         if self.PLCStatus == "Started":
   262         if self.PLCStatus == "Started":
   333     def SetTraceVariablesList(self, idxs):
   330     def SetTraceVariablesList(self, idxs):
   334         """
   331         """
   335         Call ctype imported function to append 
   332         Call ctype imported function to append 
   336         these indexes to registred variables in PLC debugger
   333         these indexes to registred variables in PLC debugger
   337         """
   334         """
   338         self._suspendDebug()
   335         if idxs:
   339         # keep a copy of requested idx
   336             # suspend but dont disable
   340         self._Idxs = idxs[:]
   337             self._suspendDebug(False)
   341         self._ResetDebugVariables()
   338             # keep a copy of requested idx
   342         for idx,iectype in idxs:
   339             self._Idxs = idxs[:]
   343             self._RegisterDebugVariable(idx)
   340             self._ResetDebugVariables()
   344         self._resumeDebug()
   341             for idx,iectype in idxs:
       
   342                 self._RegisterDebugVariable(idx)
       
   343             self._resumeDebug()
       
   344         else:
       
   345             self._suspendDebug(True)
       
   346             self._Idxs =  []
   345 
   347 
   346     class IEC_STRING(ctypes.Structure):
   348     class IEC_STRING(ctypes.Structure):
   347         """
   349         """
   348         Must be changed according to changes in iec_types.h
   350         Must be changed according to changes in iec_types.h
   349         """
   351         """