129 |
129 |
130 self._RegisterDebugVariable = self.PLClibraryHandle.RegisterDebugVariable |
130 self._RegisterDebugVariable = self.PLClibraryHandle.RegisterDebugVariable |
131 self._RegisterDebugVariable.restype = None |
131 self._RegisterDebugVariable.restype = None |
132 self._RegisterDebugVariable.argtypes = [ctypes.c_int] |
132 self._RegisterDebugVariable.argtypes = [ctypes.c_int] |
133 |
133 |
134 self._IterDebugData = self.PLClibraryHandle.IterDebugData |
|
135 self._IterDebugData.restype = ctypes.c_void_p |
|
136 self._IterDebugData.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_char_p)] |
|
137 |
|
138 self._FreeDebugData = self.PLClibraryHandle.FreeDebugData |
134 self._FreeDebugData = self.PLClibraryHandle.FreeDebugData |
139 self._FreeDebugData.restype = None |
135 self._FreeDebugData.restype = None |
140 |
136 |
141 self._WaitDebugData = self.PLClibraryHandle.WaitDebugData |
137 self._GetDebugData = self.PLClibraryHandle.GetDebugData |
142 self._WaitDebugData.restype = ctypes.c_int |
138 self._GetDebugData.restype = ctypes.c_int |
|
139 self._GetDebugData.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_void_p)] |
143 |
140 |
144 self._suspendDebug = self.PLClibraryHandle.suspendDebug |
141 self._suspendDebug = self.PLClibraryHandle.suspendDebug |
145 self._suspendDebug.restype = None |
142 self._suspendDebug.restype = None |
146 |
143 |
147 self._resumeDebug = self.PLClibraryHandle.resumeDebug |
144 self._resumeDebug = self.PLClibraryHandle.resumeDebug |
163 self._stopPLC = lambda:None |
160 self._stopPLC = lambda:None |
164 self._ResetDebugVariables = lambda:None |
161 self._ResetDebugVariables = lambda:None |
165 self._RegisterDebugVariable = lambda x:None |
162 self._RegisterDebugVariable = lambda x:None |
166 self._IterDebugData = lambda x,y:None |
163 self._IterDebugData = lambda x,y:None |
167 self._FreeDebugData = lambda:None |
164 self._FreeDebugData = lambda:None |
168 self._WaitDebugData = lambda:-1 |
165 self._GetDebugData = lambda:-1 |
169 self._suspendDebug = lambda:None |
166 self._suspendDebug = lambda:None |
170 self._resumeDebug = lambda:None |
167 self._resumeDebug = lambda:None |
171 self._PythonIterator = lambda:"" |
168 self._PythonIterator = lambda:"" |
172 self.PLClibraryHandle = None |
169 self.PLClibraryHandle = None |
173 # Unload library explicitely |
170 # Unload library explicitely |
376 """ |
373 """ |
377 Return a list of variables, corresponding to the list of required idx |
374 Return a list of variables, corresponding to the list of required idx |
378 """ |
375 """ |
379 if self.PLCStatus == "Started": |
376 if self.PLCStatus == "Started": |
380 self.PLClibraryLock.acquire() |
377 self.PLClibraryLock.acquire() |
381 tick = ctypes.c_int() |
378 tick = ctypes.c_uint32() |
382 #PLCprint("Debug tick : %d"%tick) |
379 size = ctypes.c_uint32() |
383 if self._WaitDebugData(ctypes.byref(tick)) != 0: |
380 buffer = ctypes.c_void_p() |
384 idx = ctypes.c_int() |
381 if self._GetDebugData(ctypes.byref(tick),ctypes.byref(size),ctypes.byref(buffer)) == 0 : |
385 typename = ctypes.c_char_p() |
382 offset = 0 |
386 res = [] |
383 for idx, iectype in self._Idxs: |
387 for given_idx in self._Idxs: |
384 cursor = ctypes.c_void_p(buffer.value + offset) |
388 buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename)) |
385 c_type,unpack_func = self.TypeTranslator.get(iectype, (None,None)) |
389 c_type,unpack_func = self.TypeTranslator.get(typename.value, (None,None)) |
386 if c_type is not None and offset < size: |
390 if c_type is not None and given_idx == idx.value: |
387 res.append(unpack_func(ctypes.cast(cursor, |
391 res.append(unpack_func(ctypes.cast(buffer, |
|
392 ctypes.POINTER(c_type)).contents)) |
388 ctypes.POINTER(c_type)).contents)) |
|
389 offset += ctypes.sizeof(c_type) |
393 else: |
390 else: |
394 PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value)) |
391 PLCprint("Debug error !") |
395 res.append(None) |
392 break |
396 self._FreeDebugData() |
393 self._FreeDebugData() |
397 self.PLClibraryLock.release() |
394 self.PLClibraryLock.release() |
398 return self.PLCStatus, tick, res |
395 return self.PLCStatus, tick, res |
399 return self.PLCStatus, None, None |
396 return self.PLCStatus, None, None |
400 |
397 |