Skip to content

Commit a9d2d1c

Browse files
committed
util/agents/usb_hid_relay: add support for the LCTech USB HID relay
Signed-off-by: Jan Luebbe <[email protected]>
1 parent c9fc5bf commit a9d2d1c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ HIDRelay
480480
++++++++
481481
An :any:`HIDRelay` resource describes a single output of an HID protocol based
482482
USB relays.
483-
It currently supports the widely used *dcttech USBRelay*.
483+
It currently supports the widely used *dcttech USBRelay* and *lctech LCUS*
484484

485485
.. code-block:: yaml
486486

labgrid/resource/udev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ def filter_match(self, device):
675675
match = (device.properties.get('ID_VENDOR_ID'), device.properties.get('ID_MODEL_ID'))
676676

677677
if match not in [("16c0", "05df"), # dcttech USBRelay2
678+
("5131", "2007"), # LC-US8
678679
]:
679680
return False
680681

labgrid/util/agents/usb_hid_relay.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def __init__(self, **args):
2828
if self._dev.idVendor == 0x16C0:
2929
self.set_output = self.set_output_dcttech
3030
self.get_output = self.get_output_dcttech
31+
elif self._dev.idVendor == 0x5131:
32+
self.set_output = self.set_output_lcus
33+
self.get_output = self.get_output_lcus
3134
else:
3235
raise ValueError(f"Unknown vendor/protocol for VID {self._dev.idVendor:x}")
3336

@@ -56,6 +59,20 @@ def get_output_dcttech(self, number):
5659
)
5760
return bool(resp[7] & (1 << (number - 1)))
5861

62+
def set_output_lcus(self, number, status):
63+
assert 1 <= number <= 8
64+
ep_in = self._dev[0][(0, 0)][0]
65+
ep_out = self._dev[0][(0, 0)][1]
66+
req = [0xA0, number, 0x01 if status else 0x00, 0x00]
67+
req[3] = sum(req) & 0xFF
68+
ep_out.write(req)
69+
ep_in.read(64)
70+
71+
def get_output_lcus(self, number):
72+
assert 1 <= number <= 8
73+
# we have no information on how to read the current value
74+
return False
75+
5976
def __del__(self):
6077
usb.util.release_interface(self._dev, 0)
6178

0 commit comments

Comments
 (0)