23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import Pyro.core as pyro |
25 import Pyro.core as pyro |
26 from threading import Timer, Thread, Lock, Semaphore |
26 from threading import Timer, Thread, Lock, Semaphore |
27 import ctypes, os, commands, types, sys |
27 import ctypes, os, commands, types, sys |
28 from targets.typemapping import LogLevelsDefault, LogLevelsCount, SameEndianessTypeTranslator as TypeTranslator |
28 from targets.typemapping import LogLevelsDefault, LogLevelsCount, TypeTranslator, UnpackDebugBuffer |
29 |
29 |
30 |
30 |
31 if os.name in ("nt", "ce"): |
31 if os.name in ("nt", "ce"): |
32 from _ctypes import LoadLibrary as dlopen |
32 from _ctypes import LoadLibrary as dlopen |
33 from _ctypes import FreeLibrary as dlclose |
33 from _ctypes import FreeLibrary as dlclose |
450 def GetTraceVariables(self): |
450 def GetTraceVariables(self): |
451 """ |
451 """ |
452 Return a list of variables, corresponding to the list of required idx |
452 Return a list of variables, corresponding to the list of required idx |
453 """ |
453 """ |
454 if self.PLCStatus == "Started": |
454 if self.PLCStatus == "Started": |
455 res=[] |
|
456 tick = ctypes.c_uint32() |
455 tick = ctypes.c_uint32() |
457 size = ctypes.c_uint32() |
456 size = ctypes.c_uint32() |
458 buffer = ctypes.c_void_p() |
457 buff = ctypes.c_void_p() |
459 offset = 0 |
458 TraceVariables = None |
460 if self.PLClibraryLock.acquire(False): |
459 if self.PLClibraryLock.acquire(False): |
461 if self._GetDebugData(ctypes.byref(tick), |
460 if self._GetDebugData(ctypes.byref(tick), |
462 ctypes.byref(size), |
461 ctypes.byref(size), |
463 ctypes.byref(buffer)) == 0: |
462 ctypes.byref(buff)) == 0: |
464 if size.value: |
463 if size.value: |
465 for idx, iectype, forced in self._Idxs: |
464 TraceVariables = UnpackDebugBuffer(buff, size.value, self._Idxs) |
466 cursor = ctypes.c_void_p(buffer.value + offset) |
|
467 c_type,unpack_func, pack_func = \ |
|
468 TypeTranslator.get(iectype, |
|
469 (None,None,None)) |
|
470 if c_type is not None and offset < size.value: |
|
471 res.append(unpack_func( |
|
472 ctypes.cast(cursor, |
|
473 ctypes.POINTER(c_type)).contents)) |
|
474 offset += ctypes.sizeof(c_type) if iectype != "STRING" else len(res[-1])+1 |
|
475 else: |
|
476 if c_type is None: |
|
477 PLCprint("Debug error - " + iectype + |
|
478 " not supported !") |
|
479 #if offset >= size.value: |
|
480 #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value)) |
|
481 break |
|
482 self._FreeDebugData() |
465 self._FreeDebugData() |
483 self.PLClibraryLock.release() |
466 self.PLClibraryLock.release() |
484 if offset and offset == size.value: |
467 if TraceVariables is not None: |
485 return self.PLCStatus, tick.value, res |
468 return self.PLCStatus, tick.value, TraceVariables |
486 #elif size.value: |
|
487 #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value)) |
|
488 return self.PLCStatus, None, [] |
469 return self.PLCStatus, None, [] |
489 |
470 |
490 def RemoteExec(self, script, **kwargs): |
471 def RemoteExec(self, script, **kwargs): |
491 try: |
472 try: |
492 exec script in kwargs |
473 exec script in kwargs |