Skip to content

Commit

Permalink
Merge pull request #164 from jluebbe/pio-invert
Browse files Browse the repository at this point in the history
driver&resource: add support for inverted PIOs
  • Loading branch information
Emantor committed Dec 1, 2017
2 parents 031e49c + aeb2fbd commit 4af9cfa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/configuration.rst
Expand Up @@ -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" - 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)


Used by: Used by:
- `ModbusCoilDriver`_ - `ModbusCoilDriver`_
Expand Down Expand Up @@ -175,12 +176,14 @@ A OneWirePIO describes a onewire programmable I/O pin.
OneWirePIO: OneWirePIO:
host: example.computer host: example.computer
path: /29.7D6913000000/PIO.0 path: /29.7D6913000000/PIO.0
invert: false
The example describes a `PIO.0` at device address `29.7D6913000000` via the onewire The example describes a `PIO.0` at device address `29.7D6913000000` via the onewire
server on `example.computer`. server on `example.computer`.


- host (str): hostname of the remote system running the onewire server - host (str): hostname of the remote system running the onewire server
- path (str): path on the server to the programmable I/O pin - 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: Used by:
- `OneWirePIODriver`_ - `OneWirePIODriver`_
Expand Down
7 changes: 6 additions & 1 deletion labgrid/driver/modbusdriver.py
Expand Up @@ -25,8 +25,13 @@ def __attrs_post_init__(self):


@Driver.check_active @Driver.check_active
def set(self, status): def set(self, status):
if self.coil.invert:
status = not status
self.client.write_single_coil(self.coil.coil, bool(status)) self.client.write_single_coil(self.coil.coil, bool(status))


@Driver.check_active @Driver.check_active
def get(self): 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
4 changes: 4 additions & 0 deletions labgrid/driver/onewiredriver.py
Expand Up @@ -20,6 +20,8 @@ def __attrs_post_init__(self):


@Driver.check_active @Driver.check_active
def set(self, status): def set(self, status):
if self.port.invert:
status = not status
if status == True: if status == True:
self.onewire.set(self.port.path, '1') self.onewire.set(self.port.path, '1')
else: else:
Expand All @@ -28,4 +30,6 @@ def set(self, status):
@Driver.check_active @Driver.check_active
def get(self): def get(self):
status = self.onewire.get(self.port.path) status = self.onewire.get(self.port.path)
if self.port.invert:
status = not status
return status == '1' return status == '1'
4 changes: 3 additions & 1 deletion labgrid/resource/modbus.py
Expand Up @@ -11,6 +11,8 @@ class ModbusTCPCoil(Resource):
Args: Args:
host (str): hostname of the Modbus TCP server e.g. "192.168.23.42:502" 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)) host = attr.ib(validator=attr.validators.instance_of(str))
coil = attr.ib(validator=attr.validators.instance_of(int)) coil = attr.ib(validator=attr.validators.instance_of(int))
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
4 changes: 3 additions & 1 deletion labgrid/resource/onewireport.py
Expand Up @@ -11,6 +11,8 @@ class OneWirePIO(Resource):
Args: Args:
host (str): hostname of the owserver e.g. localhost:4304 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)) host = attr.ib(validator=attr.validators.instance_of(str))
path = 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.