93 |
93 |
94 self._startPLC = self.PLClibraryHandle.startPLC |
94 self._startPLC = self.PLClibraryHandle.startPLC |
95 self._startPLC.restype = ctypes.c_int |
95 self._startPLC.restype = ctypes.c_int |
96 self._startPLC.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)] |
96 self._startPLC.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)] |
97 |
97 |
98 self.DummyIteratorLock = Lock() |
98 self._stopPLC_real = self.PLClibraryHandle.stopPLC |
99 self.DummyIteratorLock.acquire() |
99 self._stopPLC_real.restype = None |
100 |
100 |
101 self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None) |
101 self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None) |
102 if self._PythonIterator is not None: |
102 if self._PythonIterator is not None: |
103 self._PythonIterator.restype = ctypes.c_char_p |
103 self._PythonIterator.restype = ctypes.c_char_p |
104 self._PythonIterator.argtypes = [ctypes.c_char_p] |
104 self._PythonIterator.argtypes = [ctypes.c_char_p] |
105 |
105 |
106 def StopPLCLock(): |
106 def StopPLCLock(): |
107 self.PLClibraryLock.acquire() |
107 self.PLClibraryLock.acquire() |
108 self.PLClibraryHandle.stopPLC() |
108 self._stopPLC_real() |
109 self.PLClibraryLock.release() |
109 self.PLClibraryLock.release() |
110 |
110 |
111 else: |
111 else: |
112 def DummyIterator(res): |
112 # If python plugin is not enabled, we reuse _PythonIterator |
113 self.DummyIteratorLock.acquire() |
113 # as a call that block pythonthread until StopPLC |
114 self.DummyIteratorLock.release() |
114 self.PythonIteratorLock = Lock() |
|
115 self.PythonIteratorLock.acquire() |
|
116 def PythonIterator(res): |
|
117 self.PythonIteratorLock.acquire() |
|
118 self.PythonIteratorLock.release() |
115 return None |
119 return None |
116 self._PythonIterator = DummyIterator |
120 self._PythonIterator = PythonIterator |
117 |
121 |
118 def StopPLCLock(): |
122 def StopPLCLock(): |
119 self.PLClibraryLock.acquire() |
123 self.PLClibraryLock.acquire() |
120 self.PLClibraryHandle.stopPLC() |
124 self._stopPLC_real() |
121 self.DummyIteratorLock.release() |
125 self.PythonIteratorLock.release() |
122 self.PLClibraryLock.release() |
126 self.PLClibraryLock.release() |
123 |
127 |
124 self._stopPLC = StopPLCLock |
128 self._stopPLC = StopPLCLock |
125 self._stopPLC.restype = None |
|
126 |
129 |
127 self._ResetDebugVariables = self.PLClibraryHandle.ResetDebugVariables |
130 self._ResetDebugVariables = self.PLClibraryHandle.ResetDebugVariables |
128 self._ResetDebugVariables.restype = None |
131 self._ResetDebugVariables.restype = None |
129 |
132 |
130 self._RegisterDebugVariable = self.PLClibraryHandle.RegisterDebugVariable |
133 self._RegisterDebugVariable = self.PLClibraryHandle.RegisterDebugVariable |
372 def GetTraceVariables(self): |
375 def GetTraceVariables(self): |
373 """ |
376 """ |
374 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 |
375 """ |
378 """ |
376 if self.PLCStatus == "Started": |
379 if self.PLCStatus == "Started": |
|
380 res=[] |
377 self.PLClibraryLock.acquire() |
381 self.PLClibraryLock.acquire() |
378 tick = ctypes.c_uint32() |
382 tick = ctypes.c_uint32() |
379 size = ctypes.c_uint32() |
383 size = ctypes.c_uint32() |
380 buffer = ctypes.c_void_p() |
384 buffer = ctypes.c_void_p() |
381 if self._GetDebugData(ctypes.byref(tick),ctypes.byref(size),ctypes.byref(buffer)) == 0 : |
385 if self._GetDebugData(ctypes.byref(tick),ctypes.byref(size),ctypes.byref(buffer)) == 0 : |