runtime/PLCObject.py
changeset 593 726f58cf97e3
parent 592 c6408f92da0a
child 614 eed1dcf311a1
equal deleted inserted replaced
592:c6408f92da0a 593:726f58cf97e3
    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
    26 from threading import Timer, Thread, Lock
    27 import ctypes, os, commands, types, sys
    27 import ctypes, os, commands, types, sys
    28 from datetime import timedelta as td
       
    29 from targets.typemapping import SameEndianessTypeTranslator as TypeTranslator
    28 from targets.typemapping import SameEndianessTypeTranslator as TypeTranslator
    30 
    29 
    31 if os.name in ("nt", "ce"):
    30 if os.name in ("nt", "ce"):
    32     from _ctypes import LoadLibrary as dlopen
    31     from _ctypes import LoadLibrary as dlopen
    33     from _ctypes import FreeLibrary as dlclose
    32     from _ctypes import FreeLibrary as dlclose
   335             self._Idxs = idxs[:]
   334             self._Idxs = idxs[:]
   336             self._ResetDebugVariables()
   335             self._ResetDebugVariables()
   337             for idx,iectype,force in idxs:
   336             for idx,iectype,force in idxs:
   338                 if force !=None:
   337                 if force !=None:
   339                     c_type,unpack_func, pack_func = \
   338                     c_type,unpack_func, pack_func = \
   340                         self.TypeTranslator.get(iectype,
   339                         TypeTranslator.get(iectype,
   341                                                 (None,None,None))
   340                                                 (None,None,None))
   342                     force = ctypes.byref(pack_func(c_type,force)) 
   341                     force = ctypes.byref(pack_func(c_type,force)) 
   343                 self._RegisterDebugVariable(idx, force)
   342                 self._RegisterDebugVariable(idx, force)
   344             self._resumeDebug()
   343             self._resumeDebug()
   345         else:
   344         else:
   362                                   ctypes.byref(buffer)) == 0 :
   361                                   ctypes.byref(buffer)) == 0 :
   363                 if size.value:
   362                 if size.value:
   364                     for idx, iectype, forced in self._Idxs:
   363                     for idx, iectype, forced in self._Idxs:
   365                         cursor = ctypes.c_void_p(buffer.value + offset)
   364                         cursor = ctypes.c_void_p(buffer.value + offset)
   366                         c_type,unpack_func, pack_func = \
   365                         c_type,unpack_func, pack_func = \
   367                             self.TypeTranslator.get(iectype,
   366                             TypeTranslator.get(iectype,
   368                                                     (None,None,None))
   367                                                     (None,None,None))
   369                         if c_type is not None and offset < size.value:
   368                         if c_type is not None and offset < size.value:
   370                             res.append(unpack_func(
   369                             res.append(unpack_func(
   371                                         ctypes.cast(cursor,
   370                                         ctypes.cast(cursor,
   372                                          ctypes.POINTER(c_type)).contents))
   371                                          ctypes.POINTER(c_type)).contents))