52 data = self.HandleSerialTransaction(GET_PLCIDTransaction()) |
52 data = self.HandleSerialTransaction(GET_PLCIDTransaction()) |
53 if data is not None: |
53 if data is not None: |
54 return data[:32] == MD5[:32] |
54 return data[:32] == MD5[:32] |
55 return False |
55 return False |
56 |
56 |
57 class IEC_STRING(ctypes.Structure): |
|
58 """ |
|
59 Must be changed according to changes in iec_types.h |
|
60 """ |
|
61 _fields_ = [("len", ctypes.c_uint8), |
|
62 ("body", ctypes.c_char * 126)] |
|
63 |
|
64 TypeTranslator = {"BOOL" : (ctypes.c_uint8, lambda x:x.value!=0, lambda t,x:t(x)), |
|
65 "STEP" : (ctypes.c_uint8, lambda x:x.value, lambda t,x:t(x)), |
|
66 "TRANSITION" : (ctypes.c_uint8, lambda x:x.value, lambda t,x:t(x)), |
|
67 "ACTION" : (ctypes.c_uint8, lambda x:x.value, lambda t,x:t(x)), |
|
68 "SINT" : (ctypes.c_int8, lambda x:x.value, lambda t,x:t(x)), |
|
69 "USINT" : (ctypes.c_uint8, lambda x:x.value, lambda t,x:t(x)), |
|
70 "BYTE" : (ctypes.c_uint8, lambda x:x.value, lambda t,x:t(x)), |
|
71 "STRING" : (IEC_STRING, lambda x:x.body[:x.len], lambda t,x:t(len(x),x)), |
|
72 "INT" : (ctypes.c_int16, lambda x:x.value, lambda t,x:t(x)), |
|
73 "UINT" : (ctypes.c_uint16, lambda x:x.value, lambda t,x:t(x)), |
|
74 "WORD" : (ctypes.c_uint16, lambda x:x.value, lambda t,x:t(x)), |
|
75 "WSTRING" : (None, None, None),#TODO |
|
76 "DINT" : (ctypes.c_int32, lambda x:x.value, lambda t,x:t(x)), |
|
77 "UDINT" : (ctypes.c_uint32, lambda x:x.value, lambda t,x:t(x)), |
|
78 "DWORD" : (ctypes.c_uint32, lambda x:x.value, lambda t,x:t(x)), |
|
79 "LINT" : (ctypes.c_int64, lambda x:x.value, lambda t,x:t(x)), |
|
80 "ULINT" : (ctypes.c_uint64, lambda x:x.value, lambda t,x:t(x)), |
|
81 "LWORD" : (ctypes.c_uint64, lambda x:x.value, lambda t,x:t(x)), |
|
82 "REAL" : (ctypes.c_float, lambda x:x.value, lambda t,x:t(x)), |
|
83 "LREAL" : (ctypes.c_double, lambda x:x.value, lambda t,x:t(x)), |
|
84 } |
|
85 |
|
86 def SetTraceVariablesList(self, idxs): |
57 def SetTraceVariablesList(self, idxs): |
87 """ |
58 """ |
88 Call ctype imported function to append |
59 Call ctype imported function to append |
89 these indexes to registred variables in PLC debugger |
60 these indexes to registred variables in PLC debugger |
90 """ |
61 """ |
95 for idx,iectype,force in idxs: |
66 for idx,iectype,force in idxs: |
96 idxstr = ctypes.string_at( |
67 idxstr = ctypes.string_at( |
97 ctypes.pointer( |
68 ctypes.pointer( |
98 ctypes.c_uint32(idx)),4) |
69 ctypes.c_uint32(idx)),4) |
99 if force !=None: |
70 if force !=None: |
100 c_type,unpack_func, pack_func = self.TypeTranslator.get(iectype, (None,None,None)) |
71 c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None)) |
101 forced_type_size = ctypes.sizeof(c_type) |
72 forced_type_size = ctypes.sizeof(c_type) |
102 forced_type_size_str = chr(forced_type_size) |
73 forced_type_size_str = chr(forced_type_size) |
103 forcestr = ctypes.string_at( |
74 forcestr = ctypes.string_at( |
104 ctypes.pointer( |
75 ctypes.pointer( |
105 pack_func(c_type,force)), |
76 pack_func(c_type,force)), |
129 buff = ctypes.cast( |
100 buff = ctypes.cast( |
130 ctypes.c_char_p(strbuf[4:]), |
101 ctypes.c_char_p(strbuf[4:]), |
131 ctypes.c_void_p) |
102 ctypes.c_void_p) |
132 for idx, iectype, forced in self._Idxs: |
103 for idx, iectype, forced in self._Idxs: |
133 cursor = ctypes.c_void_p(buff.value + offset) |
104 cursor = ctypes.c_void_p(buff.value + offset) |
134 c_type,unpack_func, pack_func = self.TypeTranslator.get(iectype, (None,None,None)) |
105 c_type,unpack_func, pack_func = TypeTranslator.get(iectype, (None,None,None)) |
135 if c_type is not None and offset < size: |
106 if c_type is not None and offset < size: |
136 res.append(unpack_func(ctypes.cast(cursor, |
107 res.append(unpack_func(ctypes.cast(cursor, |
137 ctypes.POINTER(c_type)).contents)) |
108 ctypes.POINTER(c_type)).contents)) |
138 offset += ctypes.sizeof(c_type) |
109 offset += ctypes.sizeof(c_type) |
139 else: |
110 else: |