Permalink
Browse files

Merge pull request #164 from jluebbe/pio-invert

driver&resource: add support for inverted PIOs
  • Loading branch information...
Emantor committed Dec 1, 2017
2 parents 031e49c + aeb2fbd commit 4af9cfa0b77f4a5cbf3ef3d48fa942fff1a5e4d9
View
@@ -143,6 +143,7 @@ The example describes the coil with the address 1 on the ModbusTCP device
- host (str): hostname of the Modbus TCP server e.g. "192.168.23.42:502"
- coil (int): index of the coil e.g. 3
- invert (bool): optional, whether the logic level is be inverted (active-low)
Used by:
- `ModbusCoilDriver`_
@@ -175,12 +176,14 @@ A OneWirePIO describes a onewire programmable I/O pin.
OneWirePIO:
host: example.computer
path: /29.7D6913000000/PIO.0
invert: false
The example describes a `PIO.0` at device address `29.7D6913000000` via the onewire
server on `example.computer`.
- host (str): hostname of the remote system running the onewire server
- path (str): path on the server to the programmable I/O pin
- invert (bool): optional, whether the logic level is be inverted (active-low)
Used by:
- `OneWirePIODriver`_
@@ -25,8 +25,13 @@ def __attrs_post_init__(self):
@Driver.check_active
def set(self, status):
if self.coil.invert:
status = not status
self.client.write_single_coil(self.coil.coil, bool(status))
@Driver.check_active
def get(self):
return self.client.read_coils(self.coil.coil)
status = self.client.read_coils(self.coil.coil)
if self.coil.invert:
status = not status
return status
@@ -20,6 +20,8 @@ def __attrs_post_init__(self):
@Driver.check_active
def set(self, status):
if self.port.invert:
status = not status
if status == True:
self.onewire.set(self.port.path, '1')
else:
@@ -28,4 +30,6 @@ def set(self, status):
@Driver.check_active
def get(self):
status = self.onewire.get(self.port.path)
if self.port.invert:
status = not status
return status == '1'
@@ -11,6 +11,8 @@ class ModbusTCPCoil(Resource):
Args:
host (str): hostname of the Modbus TCP server e.g. "192.168.23.42:502"
coil (int): index of the coil e.g. 3"""
coil (int): index of the coil e.g. 3
invert (bool): optional, whether the logic level is be inverted (active-low)"""
host = attr.ib(validator=attr.validators.instance_of(str))
coil = attr.ib(validator=attr.validators.instance_of(int))
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
@@ -11,6 +11,8 @@ class OneWirePIO(Resource):
Args:
host (str): hostname of the owserver e.g. localhost:4304
path (str): path to the port on the owserver e.g. 29.7D6913000000/PIO.0"""
path (str): path to the port on the owserver e.g. 29.7D6913000000/PIO.0
invert (bool): optional, whether the logic level is be inverted (active-low)"""
host = attr.ib(validator=attr.validators.instance_of(str))
path = attr.ib(validator=attr.validators.instance_of(str))
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))

0 comments on commit 4af9cfa

Please sign in to comment.