runtime/PLCObject.py
changeset 1075 8078c01ae464
parent 1074 92a009dc5826
child 1093 b5f78cff4459
--- a/runtime/PLCObject.py	Sun Apr 28 17:26:22 2013 +0900
+++ b/runtime/PLCObject.py	Sun Apr 28 18:04:04 2013 +0900
@@ -25,7 +25,7 @@
 import Pyro.core as pyro
 from threading import Timer, Thread, Lock, Semaphore
 import ctypes, os, commands, types, sys
-from targets.typemapping import LogLevelsDefault, LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator
+from targets.typemapping import LogLevelsDefault, LogLevelsCount, TypeTranslator, UnpackDebugBuffer
 
 
 if os.name in ("nt", "ce"):
@@ -452,39 +452,20 @@
         Return a list of variables, corresponding to the list of required idx
         """
         if self.PLCStatus == "Started":
-            res=[]
             tick = ctypes.c_uint32()
             size = ctypes.c_uint32()
-            buffer = ctypes.c_void_p()
-            offset = 0
+            buff = ctypes.c_void_p()
+            TraceVariables = None
             if self.PLClibraryLock.acquire(False):
                 if self._GetDebugData(ctypes.byref(tick),
                                       ctypes.byref(size),
-                                      ctypes.byref(buffer)) == 0:
+                                      ctypes.byref(buff)) == 0:
                     if size.value:
-                        for idx, iectype, forced in self._Idxs:
-                            cursor = ctypes.c_void_p(buffer.value + offset)
-                            c_type,unpack_func, pack_func = \
-                                TypeTranslator.get(iectype,
-                                                        (None,None,None))
-                            if c_type is not None and offset < size.value:
-                                res.append(unpack_func(
-                                            ctypes.cast(cursor,
-                                             ctypes.POINTER(c_type)).contents))
-                                offset += ctypes.sizeof(c_type) if iectype != "STRING" else len(res[-1])+1
-                            else:
-                                if c_type is None:
-                                    PLCprint("Debug error - " + iectype +
-                                             " not supported !")
-                                #if offset >= size.value:
-                                    #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value))
-                                break
+                        TraceVariables = UnpackDebugBuffer(buff, size.value, self._Idxs)
                     self._FreeDebugData()
                 self.PLClibraryLock.release()
-            if offset and offset == size.value:
-                return self.PLCStatus, tick.value, res
-            #elif size.value:
-                #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value))
+            if TraceVariables is not None:
+                return self.PLCStatus, tick.value, TraceVariables
         return self.PLCStatus, None, []
 
     def RemoteExec(self, script, **kwargs):