Skip to content

Commit c050c73

Browse files
committed
driver: add invert to SerialDigitalOutputDriver
This allows the inversion of serial lines lines which are used as digital outputs. This is done on the driver level to not clutter the SerialPort resource, which is usually used for communication and not as a digital output. Signed-off-by: Rouven Czerwinski <[email protected]>
1 parent a5e67a8 commit c050c73

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

doc/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ Arguments:
13341334
bind against. This is only needed if you have multiple
13351335
SerialDriver in your environment (what is likely to be the case
13361336
if you are using this driver).
1337+
- invert (bool): whether to invert the signal
13371338

13381339
FileDigitalOutputDriver
13391340
~~~~~~~~~~~~~~~~~~~~~~~

labgrid/driver/serialdigitaloutput.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SerialPortDigitalOutputDriver(Driver, DigitalOutputProtocol):
2424

2525
bindings = {'serial': SerialDriver}
2626
signal = attr.ib(validator=attr.validators.instance_of(str))
27+
invert = attr.ib(validator=attr.validators.instance_of(bool))
2728

2829
def __attrs_post_init__(self):
2930
super().__attrs_post_init__()
@@ -39,15 +40,22 @@ def __attrs_post_init__(self):
3940
@step()
4041
def get(self):
4142
if self.signal == "dtr":
42-
return self._p.dtr
43+
val = self._p.dtr
4344
if self.signal == "rts":
44-
return self._p.rts
45+
val = self._p.rts
46+
else:
47+
raise ValueError("Expected signal to be dtr or rts")
4548

46-
raise ValueError("Expected signal to be dtr or rts")
49+
if self.invert:
50+
val = not val
51+
52+
return val
4753

4854
@Driver.check_active
4955
@step()
5056
def set(self, value):
57+
if self.invert:
58+
value = not value
5159
if self.signal == "dtr":
5260
self._p.dtr = value
5361
elif self.signal == "rts":

0 commit comments

Comments
 (0)