forked from labgrid-project/labgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request labgrid-project#432 from jluebbe/topic/relais8
Add agent module, resource and driver for Dedidec Relais 8 device
- Loading branch information
Showing
14 changed files
with
360 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
import labgrid | ||
import logging | ||
import time | ||
|
||
from labgrid import Environment, StepReporter | ||
from labgrid.strategy.bareboxstrategy import Status | ||
from labgrid.driver.deditecrelaisdriver import DeditecRelaisDriver | ||
|
||
# enable debug logging | ||
logging.basicConfig( | ||
level=logging.DEBUG, | ||
format='%(levelname)7s: %(message)s', | ||
stream=sys.stderr, | ||
) | ||
|
||
# show labgrid steps on the console | ||
StepReporter() | ||
|
||
t = labgrid.Target('main') | ||
r = labgrid.resource.udev.DeditecRelais8(t, name=None, index=1) | ||
d = DeditecRelaisDriver(t, name=None) | ||
|
||
p = t.get_driver("DigitalOutputProtocol") | ||
print(t.resources) | ||
p.set(True) | ||
print(p.get()) | ||
time.sleep(2) | ||
p.set(False) | ||
print(p.get()) | ||
time.sleep(2) | ||
p.set(True) | ||
print(p.get()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
import labgrid | ||
import logging | ||
import time | ||
|
||
from labgrid import Environment, StepReporter | ||
from labgrid.strategy.bareboxstrategy import Status | ||
from labgrid.driver.deditecrelaisdriver import DeditecRelaisDriver | ||
|
||
# enable debug logging | ||
logging.basicConfig( | ||
level=logging.DEBUG, | ||
format='%(levelname)7s: %(message)s', | ||
stream=sys.stderr, | ||
) | ||
|
||
# show labgrid steps on the console | ||
StepReporter() | ||
|
||
e = labgrid.Environment('import-dedicontrol.yaml') | ||
t = e.get_target() | ||
|
||
p = t.get_driver("DigitalOutputProtocol") | ||
print(t.resources) | ||
p.set(True) | ||
print(p.get()) | ||
time.sleep(2) | ||
p.set(False) | ||
print(p.get()) | ||
time.sleep(2) | ||
p.set(True) | ||
print(p.get()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
desk: | ||
DeditecRelais8: | ||
index: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
targets: | ||
main: | ||
resources: | ||
RemotePlace: | ||
name: dedi | ||
drivers: | ||
DeditecRelaisDriver: {} | ||
options: | ||
crossbar_url: 'ws://labgrid:20408/ws' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# pylint: disable=no-member | ||
import subprocess | ||
import attr | ||
|
||
from .common import Driver | ||
from ..factory import target_factory | ||
from ..resource.udev import DeditecRelais8 | ||
from ..resource.remote import NetworkDeditecRelais8 | ||
from ..step import step | ||
from ..protocol import DigitalOutputProtocol | ||
from ..util.agentwrapper import AgentWrapper | ||
|
||
|
||
@target_factory.reg_driver | ||
@attr.s(cmp=False) | ||
class DeditecRelaisDriver(Driver, DigitalOutputProtocol): | ||
bindings = { | ||
"relais": {DeditecRelais8, NetworkDeditecRelais8}, | ||
} | ||
|
||
def __attrs_post_init__(self): | ||
super().__attrs_post_init__() | ||
self.wrapper = None | ||
|
||
def on_activate(self): | ||
if isinstance(self.relais, NetworkDeditecRelais8): | ||
host = self.relais.host | ||
else: | ||
host = None | ||
self.wrapper = AgentWrapper(host) | ||
self.proxy = self.wrapper.load('deditec_relais8') | ||
|
||
def on_deactivate(self): | ||
self.wrapper.close() | ||
self.wrapper = None | ||
self.proxy = None | ||
|
||
@Driver.check_active | ||
@step(args=['status']) | ||
def set(self, status): | ||
self.proxy.set(self.relais.busnum, self.relais.devnum, self.relais.index, status) | ||
|
||
@Driver.check_active | ||
@step(result=True) | ||
def get(self): | ||
return self.proxy.get(self.relais.busnum, self.relais.devnum, self.relais.index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.