346 class IEC_STRING(ctypes.Structure): |
346 class IEC_STRING(ctypes.Structure): |
347 """ |
347 """ |
348 Must be changed according to changes in iec_types.h |
348 Must be changed according to changes in iec_types.h |
349 """ |
349 """ |
350 _fields_ = [("len", ctypes.c_uint8), |
350 _fields_ = [("len", ctypes.c_uint8), |
351 ("body", ctypes.c_char * 127)] |
351 ("body", ctypes.c_char * 126)] |
352 |
352 |
353 TypeTranslator = {"BOOL" : (ctypes.c_uint8, lambda x:x.value!=0), |
353 TypeTranslator = {"BOOL" : (ctypes.c_uint8, lambda x:x.value!=0), |
354 "STEP" : (ctypes.c_uint8, lambda x:x.value), |
354 "STEP" : (ctypes.c_uint8, lambda x:x.value), |
355 "TRANSITION" : (ctypes.c_uint8, lambda x:x.value), |
355 "TRANSITION" : (ctypes.c_uint8, lambda x:x.value), |
356 "ACTION" : (ctypes.c_uint8, lambda x:x.value), |
356 "ACTION" : (ctypes.c_uint8, lambda x:x.value), |
388 cursor = ctypes.c_void_p(buffer.value + offset) |
388 cursor = ctypes.c_void_p(buffer.value + offset) |
389 c_type,unpack_func = self.TypeTranslator.get(iectype, (None,None)) |
389 c_type,unpack_func = self.TypeTranslator.get(iectype, (None,None)) |
390 if c_type is not None and offset < size: |
390 if c_type is not None and offset < size: |
391 res.append(unpack_func(ctypes.cast(cursor, |
391 res.append(unpack_func(ctypes.cast(cursor, |
392 ctypes.POINTER(c_type)).contents)) |
392 ctypes.POINTER(c_type)).contents)) |
393 offset += ctypes.sizeof(c_type) |
393 offset += ctypes.sizeof(c_type) |
394 else: |
394 else: |
395 PLCprint("Debug error !") |
395 PLCprint("Debug error !") |
396 break |
396 break |
397 self._FreeDebugData() |
397 self._FreeDebugData() |
398 self.PLClibraryLock.release() |
398 self.PLClibraryLock.release() |
399 return self.PLCStatus, tick, res |
399 return self.PLCStatus, tick.value, res |
400 return self.PLCStatus, None, None |
400 return self.PLCStatus, None, None |
401 |
401 |