diff --git a/ebpfcat/ebpfcat.py b/ebpfcat/ebpfcat.py index b4d3af1f7d675705d9ef94b5c6710b555e02437d..f5d688f15b4902e35bdcbe6e4e5ba6de665b8c51 100644 --- a/ebpfcat/ebpfcat.py +++ b/ebpfcat/ebpfcat.py @@ -504,6 +504,22 @@ class SyncGroup(SyncGroupBase): dev.update() return self.current_data + async def to_operational(self): + try: + r = await gather(*[t.to_operational() for t in self.terminals]) + + while True: + for t in self.terminals: + state, error = await t.get_state() + if state != 8: # operational + print(f"ERROR AL register {error}") + await t.to_operational() + await sleep(1) + except Exception: + import traceback + traceback.print_exc() + raise + def start(self): self.allocate() self.packet_index = SyncGroup.packet_index diff --git a/ebpfcat/ethercat.py b/ebpfcat/ethercat.py index f82e9f4ded0c4ad692d70aa95a2902faf139744b..aa1b477528fad3b0c12d85f9c26fcddb09738683 100644 --- a/ebpfcat/ethercat.py +++ b/ebpfcat/ethercat.py @@ -546,9 +546,10 @@ class Terminal: return ret async def get_state(self): - """get the current state""" - ret, = await self.ec.roundtrip(ECCmd.FPRD, self.position, 0x0130, "H") - return ret + """get the current state and error flags""" + state, error = await self.ec.roundtrip(ECCmd.FPRD, self.position, + 0x0130, "H2xH") + return state, error async def to_operational(self, target=8): """try to bring the terminal to operational state