runtime/PLCObject.py
changeset 795 afcc13faecd5
parent 734 5c42cafaee15
child 798 0d2423f283a6
equal deleted inserted replaced
794:5bbf57905011 795:afcc13faecd5
   363             res=[]
   363             res=[]
   364             tick = ctypes.c_uint32()
   364             tick = ctypes.c_uint32()
   365             size = ctypes.c_uint32()
   365             size = ctypes.c_uint32()
   366             buffer = ctypes.c_void_p()
   366             buffer = ctypes.c_void_p()
   367             offset = 0
   367             offset = 0
   368             if self.PLClibraryLock.acquire(False) and \
   368             if self.PLClibraryLock.acquire(False):
   369                self._GetDebugData(ctypes.byref(tick),
   369                 if self._GetDebugData(ctypes.byref(tick),
   370                                   ctypes.byref(size),
   370                                       ctypes.byref(size),
   371                                   ctypes.byref(buffer)) == 0 :
   371                                       ctypes.byref(buffer)) == 0:
   372                 if size.value:
   372                     if size.value:
   373                     for idx, iectype, forced in self._Idxs:
   373                         for idx, iectype, forced in self._Idxs:
   374                         cursor = ctypes.c_void_p(buffer.value + offset)
   374                             cursor = ctypes.c_void_p(buffer.value + offset)
   375                         c_type,unpack_func, pack_func = \
   375                             c_type,unpack_func, pack_func = \
   376                             TypeTranslator.get(iectype,
   376                                 TypeTranslator.get(iectype,
   377                                                     (None,None,None))
   377                                                         (None,None,None))
   378                         if c_type is not None and offset < size.value:
   378                             if c_type is not None and offset < size.value:
   379                             res.append(unpack_func(
   379                                 res.append(unpack_func(
   380                                         ctypes.cast(cursor,
   380                                             ctypes.cast(cursor,
   381                                          ctypes.POINTER(c_type)).contents))
   381                                              ctypes.POINTER(c_type)).contents))
   382                             offset += ctypes.sizeof(c_type)
   382                                 offset += ctypes.sizeof(c_type)
   383                         else:
   383                             else:
   384                             if c_type is None:
   384                                 if c_type is None:
   385                                 PLCprint("Debug error - " + iectype +
   385                                     PLCprint("Debug error - " + iectype +
   386                                          " not supported !")
   386                                              " not supported !")
   387                             #if offset >= size.value:
   387                                 #if offset >= size.value:
   388                                 #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value))
   388                                     #PLCprint("Debug error - buffer too small ! %d != %d"%(offset, size.value))
   389                             break
   389                                 break
   390                 self._FreeDebugData()
   390                     self._FreeDebugData()
   391                 self.PLClibraryLock.release()
   391                 self.PLClibraryLock.release()
   392             if offset and offset == size.value:
   392             if offset and offset == size.value:
   393                 return self.PLCStatus, tick.value, res
   393                 return self.PLCStatus, tick.value, res
   394             #elif size.value:
   394             #elif size.value:
   395                 #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value))
   395                 #PLCprint("Debug error - wrong buffer unpack ! %d != %d"%(offset, size.value))