Skip to content

Commit

Permalink
kmtronic: get status using read all
Browse files Browse the repository at this point in the history
8 port kmtronic board does not support
reading from one port.
reading all ports at ones is supporter on both
4 and 8 port boards.

Signed-off-by: Benjamin B. Frost <[email protected]>
  • Loading branch information
benjamin1313 committed Feb 4, 2025
1 parent 8f4aea4 commit 697c72e
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,13 @@ A :any:`KMTronicRelay` resource describes a single output of an USB Relay Contro
KMTronicRelay:
index: 2
ports: 4
match:
ID_SERIAL_SHORT: 'AB0LBF2U'
Arguments:
- index (int): number of the relay to use.
- index (int): number on the relay to use.
- ports: (int): number of ports on the relay.
- match (dict): key and value pairs for a udev match, see `udev Matching`_

NetworkKMTronicRelay
Expand Down
1 change: 1 addition & 0 deletions examples/kmtronic/kmtronic-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ main:
location: Work Desk
KMTronicRelay:
index: 3
ports: 8
match:
ID_SERIAL_SHORT: 'AB0LBF2U'
1 change: 1 addition & 0 deletions examples/kmtronic/kmtronic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ targets:
resources:
KMTronicRelay:
index: 3
ports: 4

drivers:
KMTronicRelayDriver: {}
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/kmtronicrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def set(self, status):
@Driver.check_active
@step(result=True)
def get(self):
status = self.proxy.get(self.relay.path, self.relay.index)
status = self.proxy.get(self.relay.path, self.relay.index, self.relay.ports)
return status
1 change: 1 addition & 0 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ def _get_params(self):
"vendor_id": self.local.vendor_id,
"model_id": self.local.model_id,
"index": self.local.index,
"ports": self.local.ports,
}

@attr.s(eq=False)
Expand Down
2 changes: 2 additions & 0 deletions labgrid/resource/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def __attrs_post_init__(self):
class NetworkKMTronicRelay(RemoteUSBResource):
"""The NetworkKMTronicRelay describes a remotely accessible USB relay port"""
index = attr.ib(default=1, validator=attr.validators.instance_of(int))
ports = attr.ib(default=None, validator=attr.validators.instance_of(int))

def __attrs_post_init__(self):
self.timeout = 10.0
super().__attrs_post_init__()
Expand Down
1 change: 1 addition & 0 deletions labgrid/resource/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ def filter_match(self, device):
@attr.s(eq=False)
class KMTronicRelay(USBResource):
index = attr.ib(default=1, validator=attr.validators.instance_of(int))
ports = attr.ib(default=None, validator=attr.validators.instance_of(int))

def __attrs_post_init__(self):
self.match['SUBSYSTEM'] = 'tty'
Expand Down
13 changes: 7 additions & 6 deletions labgrid/util/agents/kmtronic_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ def set_output(self, path, index, status):
with serial.Serial(path, 9600) as ser:
ser.write(cmd)

def get_output(self, path, index):
def get_output(self, path, index, ports):
# \xFF\x01\x03 will read relay 1 status
cmd = bytes([255, index, 3])
# \xFF\x09\x00 will read from all relays
cmd = bytes([255, 9, 0])
with serial.Serial(path, 9600) as ser:
ser.write(cmd)
data = ser.read(3)
return data[2]
data = ser.read(ports)
return data[index-1]

_relays = {}

Expand All @@ -28,9 +29,9 @@ def handle_set(path, index, status):
relay = _get_relay(path)
relay.set_output(path, index, status)

def handle_get(path, index):
def handle_get(path, index, ports):
relay = _get_relay(path)
return relay.get_output(path, index)
return relay.get_output(path, index, ports)

methods = {
"set": handle_set,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_kmtronicrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@


def test_kmtronicrelay_resource(target):
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"})
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"}, index=2, ports=4)


def test_kmtronicrelay_driver(target):
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"})
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"}, index=2, ports=4)
d = KMTronicRelayDriver(target, name=None)
target.activate(d)


def test_kmtronicrelay_control(target):
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"})
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"}, index=2, ports=4)
d = KMTronicRelayDriver(target, name=None)
target.activate(d)
d.set(1)
Expand Down

0 comments on commit 697c72e

Please sign in to comment.