Permalink
Browse files

add ModbusCoilDriver and corresponding resource

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information...
jluebbe committed Nov 30, 2017
1 parent 33f4cde commit 7caa7391cbb6f13bb143fe307e89a308a958534f
View
@@ -2,6 +2,7 @@ PyYAML
attrs>=16.3.0,<17.3.0
crossbar==17.8.1.post1
pexpect
pyModbusTCP
pyserial>=3.3
pysnmp
pysnmp-mibs
View
@@ -128,6 +128,25 @@ serial "YK12345".
Used by:
- `YKUSHPowerDriver`_
ModbusTCPCoil
~~~~~~~~~~~~~
A ModbusTCPCoil describes a coil accessible via ModbusTCP.
.. code-block:: yaml
ModbusTCPCoil:
host: "192.168.23.42"
coil: 1
The example describes the coil with the address 1 on the ModbusTCP device
`192.168.23.42`.
- host (str): hostname of the Modbus TCP server e.g. "192.168.23.42:502"
- coil (int): index of the coil e.g. 3
Used by:
- `ModbusCoilDriver`_
NetworkService
~~~~~~~~~~~~~~
A NetworkService describes a remote SSH connection.
@@ -723,6 +742,24 @@ Arguments:
- cmd_off (str): command to turn power to the board off
- delay (float): configurable delay in seconds between off and on
ModbusCoilDriver
~~~~~~~~~~~~~~~~
A ModbusCoilDriver controls a `ModbusTCPCoil` resource.
It can set and get the current state of the resource.
Binds to:
- `ModbusTCPCoil`_
Implements:
- :any:`DigitalOutputProtocol`
.. code-block:: yaml
ModbusCoilDriver: {}
Arguments:
- None
MXSUSBDriver
~~~~~~~~~~~~
A MXUSBDriver is used to upload an image into a device in the mxs USB loader
@@ -14,3 +14,4 @@
from .infodriver import InfoDriver
from .common import Driver
from .qemudriver import QEMUDriver
from .modbusdriver import ModbusCoilDriver
@@ -0,0 +1,32 @@
import logging
from importlib import import_module
import attr
from ..factory import target_factory
from ..resource import ModbusTCPCoil
from ..protocol import DigitalOutputProtocol
from .common import Driver
@target_factory.reg_driver
@attr.s(cmp=False)
class ModbusCoilDriver(Driver, DigitalOutputProtocol):
bindings = {"coil": ModbusTCPCoil, }
def __attrs_post_init__(self):
super().__attrs_post_init__()
self._module = import_module('pyModbusTCP.client')
port = "502"
host = self.coil.host
if ':' in host:
host, port = host.split(':', 1)
self.client = self._module.ModbusClient(host=host,
port=int(port), auto_open=True, auto_close=True)
@Driver.check_active
def set(self, 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)
@@ -1,6 +1,7 @@
from .base import SerialPort, EthernetInterface, EthernetPort
from .ethernetport import SNMPEthernetPort
from .serialport import RawSerialPort, NetworkSerialPort
from .modbus import ModbusTCPCoil
from .networkservice import NetworkService
from .onewireport import OneWirePIO
from .power import NetworkPowerPort
View
@@ -0,0 +1,16 @@
import attr
from ..factory import target_factory
from .common import Resource
@target_factory.reg_resource
@attr.s(cmp=False)
class ModbusTCPCoil(Resource):
"""This resource describes Modbus TCP coil.
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"""
host = attr.ib(validator=attr.validators.instance_of(str))
coil = attr.ib(validator=attr.validators.instance_of(int))
View
@@ -19,6 +19,7 @@
'onewire': ['onewire>=0.2'],
'coordinator': ['crossbar', 'idna==2.5'],
'snmp': ['pysnmp', 'pysnmp-mibs'],
'modbus': ['pyModbusTCP'],
},
setup_requires=['pytest-runner', 'setuptools_scm'],
tests_require=['pytest-mock', ],

0 comments on commit 7caa739

Please sign in to comment.