--- 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 @@
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":
- buffer = ctypes.c_void_p()
+ buff = ctypes.c_void_p() if self.PLClibraryLock.acquire(False):
if self._GetDebugData(ctypes.byref(tick),
- ctypes.byref(buffer)) == 0:
+ ctypes.byref(buff)) == 0: - for idx, iectype, forced in self._Idxs:
- cursor = ctypes.c_void_p(buffer.value + offset)
- c_type,unpack_func, pack_func = \
- TypeTranslator.get(iectype,
- if c_type is not None and offset < size.value:
- res.append(unpack_func(
- ctypes.POINTER(c_type)).contents))
- offset += ctypes.sizeof(c_type) if iectype != "STRING" else len(res[-1])+1
- PLCprint("Debug error - " + iectype +
- #if offset >= size.value:
- #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value))
+ TraceVariables = UnpackDebugBuffer(buff, size.value, self._Idxs) self.PLClibraryLock.release()
- if offset and offset == size.value:
- return self.PLCStatus, tick.value, res
- #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):
--- a/targets/typemapping.py Sun Apr 28 17:26:22 2013 +0900
+++ b/targets/typemapping.py Sun Apr 28 18:04:04 2013 +0900
@@ -73,9 +73,37 @@
+TypeTranslator=SameEndianessTypeTranslator # Construct debugger natively supported types
DebugTypesSize = dict([(key,sizeof(t)) for key,(t,p,u) in SameEndianessTypeTranslator.iteritems() if t is not None])
+def UnpackDebugBuffer(buff, size, indexes): + for idx, iectype, forced in indexes: + cursor = c_void_p(buff.value + offset) + c_type,unpack_func, pack_func = \ + TypeTranslator.get(iectype, + if c_type is not None and offset < size: + res.append(unpack_func( + POINTER(c_type)).contents)) + offset += sizeof(c_type) if iectype != "STRING" else len(res[-1])+1 + # PLCprint("Debug error - " + iectype + + # PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size)) + if offset and offset == size: LogLevels = ["CRITICAL","WARNING","INFO","DEBUG"]
LogLevelsCount = len(LogLevels)
LogLevelsDict = dict(zip(LogLevels,range(LogLevelsCount)))