runtime/PLCObject.py
changeset 592 c6408f92da0a
parent 504 688e84df3408
child 593 726f58cf97e3
--- a/runtime/PLCObject.py	Thu Mar 31 19:04:03 2011 +0200
+++ b/runtime/PLCObject.py	Thu Mar 31 19:09:49 2011 +0200
@@ -25,6 +25,8 @@
 import Pyro.core as pyro
 from threading import Timer, Thread, Lock
 import ctypes, os, commands, types, sys
+from datetime import timedelta as td
+from targets.typemapping import SameEndianessTypeTranslator as TypeTranslator
 
 if os.name in ("nt", "ce"):
     from _ctypes import LoadLibrary as dlopen
@@ -320,35 +322,7 @@
             return False
     
 
-    class IEC_STRING(ctypes.Structure):
-        """
-        Must be changed according to changes in iec_types.h
-        """
-        _fields_ = [("len", ctypes.c_uint8),
-                    ("body", ctypes.c_char * 126)] 
-    
-    TypeTranslator = {"BOOL" :       (ctypes.c_uint8,  lambda x:x.value!=0,     lambda t,x:t(x)),
-                      "STEP" :       (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
-                      "TRANSITION" : (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
-                      "ACTION" :     (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
-                      "SINT" :       (ctypes.c_int8,   lambda x:x.value,        lambda t,x:t(x)),
-                      "USINT" :      (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
-                      "BYTE" :       (ctypes.c_uint8,  lambda x:x.value,        lambda t,x:t(x)),
-                      "STRING" :     (IEC_STRING,      lambda x:x.body[:x.len], lambda t,x:t(len(x),x)),
-                      "INT" :        (ctypes.c_int16,  lambda x:x.value,        lambda t,x:t(x)),
-                      "UINT" :       (ctypes.c_uint16, lambda x:x.value,        lambda t,x:t(x)),
-                      "WORD" :       (ctypes.c_uint16, lambda x:x.value,        lambda t,x:t(x)),
-                      "WSTRING" :    (None,            None,                    None),#TODO
-                      "DINT" :       (ctypes.c_int32,  lambda x:x.value,        lambda t,x:t(x)),
-                      "UDINT" :      (ctypes.c_uint32, lambda x:x.value,        lambda t,x:t(x)),
-                      "DWORD" :      (ctypes.c_uint32, lambda x:x.value,        lambda t,x:t(x)),
-                      "LINT" :       (ctypes.c_int64,  lambda x:x.value,        lambda t,x:t(x)),
-                      "ULINT" :      (ctypes.c_uint64, lambda x:x.value,        lambda t,x:t(x)),
-                      "LWORD" :      (ctypes.c_uint64, lambda x:x.value,        lambda t,x:t(x)),
-                      "REAL" :       (ctypes.c_float,  lambda x:x.value,        lambda t,x:t(x)),
-                      "LREAL" :      (ctypes.c_double, lambda x:x.value,        lambda t,x:t(x)),
-                      } 
-
+    
     def SetTraceVariablesList(self, idxs):
         """
         Call ctype imported function to append 
@@ -392,7 +366,7 @@
                         c_type,unpack_func, pack_func = \
                             self.TypeTranslator.get(iectype,
                                                     (None,None,None))
-                        if c_type is not None and offset < size:
+                        if c_type is not None and offset < size.value:
                             res.append(unpack_func(
                                         ctypes.cast(cursor,
                                          ctypes.POINTER(c_type)).contents))
@@ -401,14 +375,14 @@
                             if c_type is None:
                                 PLCprint("Debug error - " + iectype +
                                          " not supported !")
-                            if offset >= size:
-                                PLCprint("Debug error - buffer too small !")
+                            #if offset >= size.value:
+                                #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value))
                             break
                 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 !")
-        return self.PLCStatus, None, None
-
+            #elif size.value:
+                #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value))
+        return self.PLCStatus, None, []
+