Skip to content

Commit 7e97856

Browse files
committed
kmtronic: get status using read all
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.
1 parent 88928b8 commit 7e97856

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

doc/configuration.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,13 @@ A :any:`KMTronicRelay` resource describes a single output of an USB Relay Contro
597597
598598
KMTronicRelay:
599599
index: 2
600+
ports: 4
600601
match:
601602
ID_SERIAL_SHORT: 'AB0LBF2U'
602603
603604
Arguments:
604-
- index (int): number of the relay to use.
605+
- index (int): number on the relay to use.
606+
- ports: (int): number of ports on the relay. defaults to 8
605607
- match (dict): key and value pairs for a udev match, see `udev Matching`_
606608

607609
NetworkKMTronicRelay

labgrid/driver/kmtronicrelay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def set(self, status):
4040
@Driver.check_active
4141
@step(result=True)
4242
def get(self):
43-
status = self.proxy.get(self.relay.path, self.relay.index)
43+
status = self.proxy.get(self.relay.path, self.relay.index, self.relay.ports)
4444
return status

labgrid/remote/exporter.py

+1
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def _get_params(self):
534534
"vendor_id": self.local.vendor_id,
535535
"model_id": self.local.model_id,
536536
"index": self.local.index,
537+
"ports": self.local.ports,
537538
}
538539

539540
@attr.s(eq=False)

labgrid/resource/remote.py

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def __attrs_post_init__(self):
329329
class NetworkKMTronicRelay(RemoteUSBResource):
330330
"""The NetworkKMTronicRelay describes a remotely accessible USB relay port"""
331331
index = attr.ib(default=1, validator=attr.validators.instance_of(int))
332+
ports = attr.ib(default=8, validator=attr.validators.instance_of(int))
332333
def __attrs_post_init__(self):
333334
self.timeout = 10.0
334335
super().__attrs_post_init__()

labgrid/resource/udev.py

+1
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ def filter_match(self, device):
710710
@attr.s(eq=False)
711711
class KMTronicRelay(USBResource):
712712
index = attr.ib(default=1, validator=attr.validators.instance_of(int))
713+
ports = attr.ib(default=8, validator=attr.validators.instance_of(int))
713714

714715
def __attrs_post_init__(self):
715716
self.match['SUBSYSTEM'] = 'tty'

labgrid/util/agents/kmtronic_relay.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ def set_output(self, path, index, status):
99
with serial.Serial(path, 9600) as ser:
1010
ser.write(cmd)
1111

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

2021
_relays = {}
2122

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

31-
def handle_get(path, index):
32+
def handle_get(path, index, ports):
3233
relay = _get_relay(path)
33-
return relay.get_output(path, index)
34+
return relay.get_output(path, index, ports)
3435

3536
methods = {
3637
"set": handle_set,

tests/test_kmtronicrelay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_kmtronicrelay_driver(target):
1313

1414

1515
def test_kmtronicrelay_control(target):
16-
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"})
16+
r = KMTronicRelay(target, name=None, match={"ID_SERIAL_SHORT": "AB0LBF2U"}, index=2, ports=4)
1717
d = KMTronicRelayDriver(target, name=None)
1818
target.activate(d)
1919
d.set(1)

0 commit comments

Comments
 (0)