diff --git a/ebpfcat/ebpfcat.py b/ebpfcat/ebpfcat.py index 164794064edd99c5a49dccae11f91bdfc2133d08..74c0e8cb5628f41bb1558d466e14ab0a31e469f8 100644 --- a/ebpfcat/ebpfcat.py +++ b/ebpfcat/ebpfcat.py @@ -16,7 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """The high-level API for EtherCAT loops""" -from asyncio import ensure_future, gather, wait_for, TimeoutError +from asyncio import ensure_future, gather, sleep, wait_for, TimeoutError from contextlib import asynccontextmanager, contextmanager import os from struct import pack, unpack, calcsize, pack_into, unpack_from @@ -222,7 +222,7 @@ class EBPFTerminal(Terminal): raise RuntimeError( f"Incompatible Terminal: {self.vendorId}:{self.productCode} " f"({relative}, {absolute})") - await self.to_operational() + await self.to_operational(4) self.pdos = {} if self.has_mailbox(): await self.parse_pdos() @@ -388,12 +388,27 @@ 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: + print("stat", await t.get_state()) + await sleep(1) + except Exception: + import traceback + traceback.print_exc() + raise + def start(self): self.allocate() self.packet_index = SyncGroup.packet_index SyncGroup.packet_index += 1 self.asm_packet = self.packet.assemble(self.packet_index) - return ensure_future(self.run()) + ret = ensure_future(self.run()) + ensure_future(self.to_operational()) + return ret def allocate(self): self.packet = Packet()