LPCconnector/LPCAppObject.py
changeset 41 b02a30880829
parent 35 cb9da964a178
child 42 30eae94f35f7
--- a/LPCconnector/LPCAppObject.py	Wed Apr 24 17:29:26 2013 +0200
+++ b/LPCconnector/LPCAppObject.py	Sun Apr 28 18:07:19 2013 +0900
@@ -25,7 +25,7 @@
 import ctypes
 from LPCAppProto import *
 from LPCObject import *
-from targets.typemapping import  LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator
+from targets.typemapping import  LogLevelsCount, TypeTranslator, UnpackDebugBuffer
 
 class LPCAppObject(LPCObject):
     def connect(self,comport):
@@ -94,7 +94,6 @@
         """
         Return a list of variables, corresponding to the list of required idx
         """
-        offset = 0
         strbuf = self.HandleSerialTransaction(
                                      GET_TRACE_VARIABLETransaction())
         if strbuf is not None and len(strbuf) > 4 and self.PLCStatus == "Started":
@@ -104,22 +103,9 @@
             tick = ctypes.cast(ctick, ctypes.POINTER(ctypes.c_int)).contents
             cbuff = ctypes.create_string_buffer(strbuf[4:])
             buff = ctypes.cast(cbuff, ctypes.c_void_p)
-            for idx, iectype, forced in self._Idxs:
-                cursor = ctypes.c_void_p(buff.value + offset)
-                c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None))
-                if c_type is not None and offset < size:
-                    res.append(unpack_func(ctypes.cast(cursor,
-                                                       ctypes.POINTER(c_type)).contents))
-                    offset += ctypes.sizeof(c_type)
-                else:
-                    #if c_type is None:
-                        #PLCprint("Debug error - " + iectype + " not supported !")
-                    #if offset >= size:
-                        #PLCprint("Debug error - buffer too small !")
-                    break
-            if offset and offset == size:
+            TraceVariables = UnpackDebugBuffer(buff, size,  self._Idxs)
+            if TraceVariables is not None:
                 return self.PLCStatus, tick.value, res
-            #PLCprint("Debug error - wrong buffer unpack !")
         return self.PLCStatus, None, [] 
 
     def GetLogMessage(self, level, msgid):