Skip to content

Commit

Permalink
labgrid/util/agents/usb_hid_relay: keep the USB device open
Browse files Browse the repository at this point in the history
This avoids device busy errors when accessing the device in a loop.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe committed Aug 8, 2024
1 parent e592a37 commit c9fc5bf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions labgrid/util/agents/usb_hid_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ def __del__(self):
usb.util.release_interface(self._dev, 0)


_relays = {}


def _get_relay(busnum, devnum):
if (busnum, devnum) not in _relays:
_relays[(busnum, devnum)] = USBHIDRelay(bus=busnum, address=devnum)
return _relays[(busnum, devnum)]


def handle_set(busnum, devnum, number, status):
relay = USBHIDRelay(bus=busnum, address=devnum)
relay = _get_relay(busnum, devnum)
relay.set_output(number, status)


def handle_get(busnum, devnum, number):
relay = USBHIDRelay(bus=busnum, address=devnum)
relay = _get_relay(busnum, devnum)
return relay.get_output(number)


Expand Down

0 comments on commit c9fc5bf

Please sign in to comment.