264 self._ResetDebugVariables() |
264 self._ResetDebugVariables() |
265 for idx in idxs: |
265 for idx in idxs: |
266 self._RegisterDebugVariable(idx) |
266 self._RegisterDebugVariable(idx) |
267 self._resumeDebug() |
267 self._resumeDebug() |
268 |
268 |
269 TypeTranslator = {"BOOL" : ctypes.c_uint8, |
269 TypeTranslator = {"BOOL" : (ctypes.c_uint8, lambda x:x.value!=0), |
270 "STEP" : ctypes.c_uint8, |
270 "STEP" : (ctypes.c_uint8, lambda x:x.value), |
271 "TRANSITION" : ctypes.c_uint8, |
271 "TRANSITION" : (ctypes.c_uint8, lambda x:x.value), |
272 "ACTION" : ctypes.c_uint8, |
272 "ACTION" : (ctypes.c_uint8, lambda x:x.value), |
273 "SINT" : ctypes.c_int8, |
273 "SINT" : (ctypes.c_int8, lambda x:x.value), |
274 "USINT" : ctypes.c_uint8, |
274 "USINT" : (ctypes.c_uint8, lambda x:x.value), |
275 "BYTE" : ctypes.c_uint8, |
275 "BYTE" : (ctypes.c_uint8, lambda x:x.value), |
276 "STRING" : None, #TODO |
276 "STRING" : (None, None),#TODO |
277 "INT" : ctypes.c_int16, |
277 "INT" : (ctypes.c_int16, lambda x:x.value), |
278 "UINT" : ctypes.c_uint16, |
278 "UINT" : (ctypes.c_uint16, lambda x:x.value), |
279 "WORD" : ctypes.c_uint16, |
279 "WORD" : (ctypes.c_uint16, lambda x:x.value), |
280 "WSTRING" : None, #TODO |
280 "WSTRING" : (None, None),#TODO |
281 "DINT" : ctypes.c_int32, |
281 "DINT" : (ctypes.c_int32, lambda x:x.value), |
282 "UDINT" : ctypes.c_uint32, |
282 "UDINT" : (ctypes.c_uint32, lambda x:x.value), |
283 "DWORD" : ctypes.c_uint32, |
283 "DWORD" : (ctypes.c_uint32, lambda x:x.value), |
284 "LINT" : ctypes.c_int64, |
284 "LINT" : (ctypes.c_int64, lambda x:x.value), |
285 "ULINT" : ctypes.c_uint64, |
285 "ULINT" : (ctypes.c_uint64, lambda x:x.value), |
286 "LWORD" : ctypes.c_uint64, |
286 "LWORD" : (ctypes.c_uint64, lambda x:x.value), |
287 "REAL" : ctypes.c_float, |
287 "REAL" : (ctypes.c_float, lambda x:x.value), |
288 "LREAL" : ctypes.c_double, |
288 "LREAL" : (ctypes.c_double, lambda x:x.value), |
289 } |
289 } |
290 |
290 |
291 def GetTraceVariables(self): |
291 def GetTraceVariables(self): |
292 """ |
292 """ |
293 Return a list of variables, corresponding to the list of requiered idx |
293 Return a list of variables, corresponding to the list of requiered idx |
300 typename = ctypes.c_char_p() |
300 typename = ctypes.c_char_p() |
301 res = [] |
301 res = [] |
302 |
302 |
303 for given_idx in self._Idxs: |
303 for given_idx in self._Idxs: |
304 buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename)) |
304 buffer=self._IterDebugData(ctypes.byref(idx), ctypes.byref(typename)) |
305 c_type = self.TypeTranslator.get(typename.value, None) |
305 c_type,unpack_func = self.TypeTranslator.get(typename.value, None) |
306 if c_type is not None and given_idx == idx.value: |
306 if c_type is not None and given_idx == idx.value: |
307 res.append(ctypes.cast(buffer, |
307 res.append(unpack_func(ctypes.cast(buffer, |
308 ctypes.POINTER(c_type)).contents.value) |
308 ctypes.POINTER(c_type)).contents)) |
309 else: |
309 else: |
310 print "Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value) |
310 print "Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value) |
311 res.append(None) |
311 res.append(None) |
312 self._FreeDebugData() |
312 self._FreeDebugData() |
313 return tick, res |
313 return tick, res |