equal
deleted
inserted
replaced
95 self.mutex = Lock() |
95 self.mutex = Lock() |
96 self.todo = Condition(self.mutex) |
96 self.todo = Condition(self.mutex) |
97 self.done = Condition(self.mutex) |
97 self.done = Condition(self.mutex) |
98 self.job = None |
98 self.job = None |
99 |
99 |
100 def runloop(self): |
100 def runloop(self,*args,**kwargs): |
101 """ |
101 """ |
102 meant to be called by worker thread (blocking) |
102 meant to be called by worker thread (blocking) |
103 """ |
103 """ |
104 self._threadID = thread.get_ident() |
104 self._threadID = thread.get_ident() |
|
105 if args or kwargs: |
|
106 job(*args,**kwargs).do() |
|
107 # result is ignored |
105 self.mutex.acquire() |
108 self.mutex.acquire() |
106 while not self._finish: |
109 while not self._finish: |
107 self.todo.wait() |
110 self.todo.wait() |
108 if self.job is not None: |
111 if self.job is not None: |
109 self.job.do() |
112 self.job.do() |
184 self.python_runtime_vars = None |
187 self.python_runtime_vars = None |
185 self.TraceThread = None |
188 self.TraceThread = None |
186 self.TraceLock = Lock() |
189 self.TraceLock = Lock() |
187 self.TraceWakeup = Event() |
190 self.TraceWakeup = Event() |
188 self.Traces = [] |
191 self.Traces = [] |
189 server.RegisterPLCObject(self) |
|
190 |
192 |
191 def AutoLoad(self): |
193 def AutoLoad(self): |
192 # Get the last transfered PLC if connector must be restart |
194 # Get the last transfered PLC if connector must be restart |
193 try: |
195 try: |
194 self.CurrentPLCFilename = open( |
196 self.CurrentPLCFilename = open( |
271 |
273 |
272 self._stopPLC_real = self.PLClibraryHandle.stopPLC |
274 self._stopPLC_real = self.PLClibraryHandle.stopPLC |
273 self._stopPLC_real.restype = None |
275 self._stopPLC_real.restype = None |
274 |
276 |
275 self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None) |
277 self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None) |
|
278 print(self._PythonIterator) |
276 if self._PythonIterator is not None: |
279 if self._PythonIterator is not None: |
277 self._PythonIterator.restype = ctypes.c_char_p |
280 self._PythonIterator.restype = ctypes.c_char_p |
278 self._PythonIterator.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p)] |
281 self._PythonIterator.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p)] |
279 |
282 |
280 self._stopPLC = self._stopPLC_real |
283 self._stopPLC = self._stopPLC_real |
478 self.python_runtime_vars["FBID"] = None |
481 self.python_runtime_vars["FBID"] = None |
479 except Exception, e: |
482 except Exception, e: |
480 res = "#EXCEPTION : "+str(e) |
483 res = "#EXCEPTION : "+str(e) |
481 self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e))) |
484 self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e))) |
482 |
485 |
|
486 @RunInMain |
483 def StartPLC(self): |
487 def StartPLC(self): |
484 if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped": |
488 if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped": |
485 c_argv = ctypes.c_char_p * len(self.argv) |
489 c_argv = ctypes.c_char_p * len(self.argv) |
486 res = self._startPLC(len(self.argv), c_argv(*self.argv)) |
490 res = self._startPLC(len(self.argv), c_argv(*self.argv)) |
487 if res == 0: |
491 if res == 0: |
496 else: |
500 else: |
497 self.LogMessage(0, _("Problem starting PLC : error %d" % res)) |
501 self.LogMessage(0, _("Problem starting PLC : error %d" % res)) |
498 self.PLCStatus = "Broken" |
502 self.PLCStatus = "Broken" |
499 self.StatusChange() |
503 self.StatusChange() |
500 |
504 |
|
505 @RunInMain |
501 def StopPLC(self): |
506 def StopPLC(self): |
502 if self.PLCStatus == "Started": |
507 if self.PLCStatus == "Started": |
503 self.LogMessage("PLC stopped") |
508 self.LogMessage("PLC stopped") |
504 self._stopPLC() |
509 self._stopPLC() |
505 self.PythonThread.join() |
510 self.PythonThread.join() |
514 return False |
519 return False |
515 |
520 |
516 def GetPLCstatus(self): |
521 def GetPLCstatus(self): |
517 return self.PLCStatus, map(self.GetLogCount, xrange(LogLevelsCount)) |
522 return self.PLCStatus, map(self.GetLogCount, xrange(LogLevelsCount)) |
518 |
523 |
|
524 @RunInMain |
519 def NewPLC(self, md5sum, data, extrafiles): |
525 def NewPLC(self, md5sum, data, extrafiles): |
520 if self.PLCStatus in ["Stopped", "Empty", "Broken"]: |
526 if self.PLCStatus in ["Stopped", "Empty", "Broken"]: |
521 NewFileName = md5sum + lib_ext |
527 NewFileName = md5sum + lib_ext |
522 extra_files_log = os.path.join(self.workingdir, "extra_files.txt") |
528 extra_files_log = os.path.join(self.workingdir, "extra_files.txt") |
523 |
529 |