From 03b4a9e87e96ff5816f88f82d0b1ef37eebfdd99 Mon Sep 17 00:00:00 2001 From: Martin Teichmann <martin.teichmann@xfel.eu> Date: Thu, 18 Feb 2021 15:18:23 +0000 Subject: [PATCH] fix setting SDOs --- ebpfcat/ethercat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ebpfcat/ethercat.py b/ebpfcat/ethercat.py index 5c37a19..c50c428 100644 --- a/ebpfcat/ethercat.py +++ b/ebpfcat/ethercat.py @@ -116,7 +116,7 @@ class ObjectEntry: if self.dataType in (ECDataType.VISIBLE_STRING, ECDataType.UNICODE_STRING): return ret.decode("utf8") - elif self.dataType.fmt is None: + elif isinstance(self.dataType, int) or self.dataType.fmt is None: return ret else: return unpack("<" + self.dataType.fmt, ret)[0] @@ -125,7 +125,7 @@ class ObjectEntry: if self.dataType in (ECDataType.VISIBLE_STRING, ECDataType.UNICODE_STRING): d = data.encode("utf8") - elif self.dataType.fmt is None: + elif isinstance(self.dataType, int) or self.dataType.fmt is None: d = data else: d = pack("<" + self.dataType.fmt, data) @@ -569,9 +569,9 @@ class Terminal: async def sdo_write(self, data, index, subindex=None): if len(data) <= 4 and subindex is not None: await self.mbx_send( - MBXType.COE, "HBHB", CoECmd.SDOREQ.value << 12, - ODCmd.DOWN_EXP.value | ((4 - len(data)) << 2), - index, subindex, data=data) + MBXType.COE, "HBHB4s", CoECmd.SDOREQ.value << 12, + ODCmd.DOWN_EXP.value | (((4 - len(data)) << 2) & 0xc), + index, subindex, data) type, data = await self.mbx_recv() if type is not MBXType.COE: raise RuntimeError(f"expected CoE, got {type}") -- GitLab