Skip to content

Commit e8fdd87

Browse files
authored
Merge pull request #1275 from BasicServicePeople/eth008_driver
power: add eth008 power backend
2 parents 54f4229 + 5a8acba commit e8fdd87

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

doc/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ Currently available are:
174174
interface, this module deliberately uses the standard password '1' and is
175175
not compatible with a different password.
176176

177+
``eth008``
178+
Controls a Robot-Electronics eth008 via a simple HTTP API.
179+
177180
``gude``
178181
Controls a Gude PDU via a simple HTTP API.
179182

labgrid/driver/power/eth008.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
This driver implements a power port for the robot electronics 8 relay
3+
outputs board.
4+
5+
Driver has been tested with:
6+
* ETH008 - 8 relay outputs
7+
"""
8+
9+
import requests
10+
from ..exception import ExecutionError
11+
12+
PORT = 80
13+
14+
def power_set(host, port, index, value):
15+
index = int(index)
16+
assert 1 <= index <= 8
17+
# access the web interface...
18+
value_str = "A" if value else "I"
19+
response = requests.get(
20+
f"http://{host}:{port}/io.cgi?DO{value_str}{index}"
21+
)
22+
response.raise_for_status()
23+
24+
# Check, that the port is in the desired state
25+
state = get_state(response, index)
26+
if state != value:
27+
raise ExecutionError(f"failed to set port {index} to status {value}")
28+
29+
def power_get(host, port, index):
30+
index = int(index)
31+
assert 1 <= index <= 8
32+
# get the contents of the main page
33+
response = requests.get(f"http://{host}:{port}/io.cgi?relay")
34+
35+
response.raise_for_status()
36+
state = get_state(response, index)
37+
return state
38+
39+
def get_state(request, index):
40+
value = request.text.split()[1][index-1]
41+
return bool(int(value))

tests/test_powerdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def test_import_backends(self):
244244
import labgrid.driver.power.apc
245245
import labgrid.driver.power.digipower
246246
import labgrid.driver.power.digitalloggers_http
247+
import labgrid.driver.power.eth008
247248
import labgrid.driver.power.gude
248249
import labgrid.driver.power.gude24
249250
import labgrid.driver.power.netio

0 commit comments

Comments
 (0)