runtime/PLCObject.py
changeset 353 c68fc75ebb06
parent 352 81777d4e379c
child 361 331d698e1118
equal deleted inserted replaced
352:81777d4e379c 353:c68fc75ebb06
    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 import time
       
    29 
    28 
    30 if os.name in ("nt", "ce"):
    29 if os.name in ("nt", "ce"):
    31     from _ctypes import LoadLibrary as dlopen
    30     from _ctypes import LoadLibrary as dlopen
    32     from _ctypes import FreeLibrary as dlclose
    31     from _ctypes import FreeLibrary as dlclose
    33 elif os.name == "posix":
    32 elif os.name == "posix":
   403     def GetTraceVariables(self):
   402     def GetTraceVariables(self):
   404         """
   403         """
   405         Return a list of variables, corresponding to the list of required idx
   404         Return a list of variables, corresponding to the list of required idx
   406         """
   405         """
   407         if self.PLCStatus == "Started":
   406         if self.PLCStatus == "Started":
       
   407             self.PLClibraryLock.acquire()
   408             tick = self._WaitDebugData()
   408             tick = self._WaitDebugData()
       
   409             #PLCprint("Debug tick : %d"%tick)
   409             if tick == -1:
   410             if tick == -1:
   410                 res = None
   411                 res = None
   411             else:
   412             else:
   412                 idx = ctypes.c_int()
   413                 idx = ctypes.c_int()
   413                 typename = ctypes.c_char_p()
   414                 typename = ctypes.c_char_p()
   420                         res.append(unpack_func(ctypes.cast(buffer,
   421                         res.append(unpack_func(ctypes.cast(buffer,
   421                                                            ctypes.POINTER(c_type)).contents))
   422                                                            ctypes.POINTER(c_type)).contents))
   422                     else:
   423                     else:
   423                         PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value))
   424                         PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value))
   424                         res.append(None)
   425                         res.append(None)
   425             time.sleep(0.1)
       
   426             self._FreeDebugData()
   426             self._FreeDebugData()
       
   427             self.PLClibraryLock.release()
   427             return tick, res
   428             return tick, res
   428         return -1, None
   429         return -1, None
   429         
   430 
   430 
       
   431