From 94d8a79ab3359498f8438a78968a0ef464260515 Mon Sep 17 00:00:00 2001
From: Martin Teichmann <martin.teichmann@xfel.eu>
Date: Sat, 11 Feb 2023 15:03:45 +0100
Subject: [PATCH] ignore Ethernet-over-Ethercat

somehow the anybus thing wants to return a EoE frame when
asked for a CoE frame. We can just ignore it, then it works
fine.
---
 ebpfcat/ethercat.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ebpfcat/ethercat.py b/ebpfcat/ethercat.py
index 0b6efae..4b703e2 100644
--- a/ebpfcat/ethercat.py
+++ b/ebpfcat/ethercat.py
@@ -664,9 +664,11 @@ class Terminal:
             offset = 8  # skip header in first packet
 
             while fragments:
-                type, data = await self.mbx_recv()
-                if type is not MBXType.COE:
-                    raise EtherCatError(f"expected CoE package, got {type}")
+                type = None
+                while type is not MBXType.COE:
+                    type, data = await self.mbx_recv()
+                    if type is not MBXType.COE:
+                        print(f"expected CoE package, got {type}")
                 coecmd, rodcmd, fragments = unpack("<HBxH", data[:6])
                 if rodcmd & 0x7f != odcmd.value + 1:
                     raise EtherCatError(f"expected {odcmd.value}, got {odcmd}")
@@ -681,9 +683,11 @@ class Terminal:
                     ODCmd.UP_REQ_CA.value if subindex is None
                     else ODCmd.UP_REQ.value,
                     index, 1 if subindex is None else subindex)
-            type, data = await self.mbx_recv()
-            if type is not MBXType.COE:
-                raise EtherCatError(f"expected CoE, got {type}")
+            type = None
+            while type is not MBXType.COE:
+                type, data = await self.mbx_recv()
+                if type is not MBXType.COE:
+                    print(f"got {type}")
             coecmd, sdocmd, idx, subidx, size = unpack("<HBHBI", data[:10])
             if coecmd >> 12 != CoECmd.SDORES.value:
                 if subindex is None and coecmd >> 12 == CoECmd.SDOREQ.value:
-- 
GitLab