Skip to content

Commit

Permalink
do a smarter wait for acknowledgment
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Jun 24, 2024
1 parent b4cbd10 commit 3d6093e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions hardware/opentrons_hardware/sensors/sensor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import csv

from typing import Optional, AsyncIterator, Any, Sequence
from contextlib import asynccontextmanager
from contextlib import asynccontextmanager, suppress
from logging import getLogger

from opentrons_hardware.drivers.can_bus.can_messenger import (
CanMessenger,
Expand Down Expand Up @@ -46,6 +47,7 @@
from .sensor_abc import AbstractSensorDriver
from .scheduler import SensorScheduler

LOG = getLogger(__name__)

class SensorDriver(AbstractSensorDriver):
"""Generic Sensor Driver."""
Expand Down Expand Up @@ -256,14 +258,10 @@ async def wait_for_complete(
"""Wait for the data to stop, only use this with a send_accumulated_data_request."""
self.event = asyncio.Event()
self.expected_ack = message_index
start = time.time()
while True:
await asyncio.sleep(0.2)
if self.event.is_set():
self.event.clear()
break
if time.time() - start > wait_time:
break
with suppress(asyncio.TimeoutError):
await asyncio.wait_for(self.event.wait(), wait_time)
if not self.event.is_set():
LOG.error("Did not receive the full data set from the sensor")
self.event = None

def __call__(
Expand Down

0 comments on commit 3d6093e

Please sign in to comment.