From f2622cf90dc514867ee6abde73c54efc5458be55 Mon Sep 17 00:00:00 2001
From: Martin Teichmann <martin.teichmann@gmail.com>
Date: Fri, 10 Feb 2023 19:42:10 +0000
Subject: [PATCH] support terminals that only read 4 eeprom bytes

some terminals do not support reading 8 bytes of the eeprom at
a time, we have to limit to 4 bytes at a time
---
 ebpfcat/ethercat.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ebpfcat/ethercat.py b/ebpfcat/ethercat.py
index 09f5c47..95c5187 100644
--- a/ebpfcat/ethercat.py
+++ b/ebpfcat/ethercat.py
@@ -584,7 +584,13 @@ class Terminal:
         busy = 0x8000
         while busy & 0x8000:
             busy, data = await self.read(0x502, "H4x8s")
-        return data
+        if busy & 0x40:  # otherwise we actually only read 4 bytes
+            return data
+        await self.write(0x502, "HI", 0x100, start + 2)
+        busy = 0x8000
+        while busy & 0x8000:
+            busy, data2 = await self.read(0x502, "H4x4s")
+        return data[:4] + data2
 
     async def eeprom_write_one(self, start, data):
         """read 2 bytes from the eeprom at `start`"""
-- 
GitLab