-
Notifications
You must be signed in to change notification settings - Fork 174
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 #1275 from BasicServicePeople/eth008_driver
power: add eth008 power backend
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 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
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,41 @@ | ||
""" | ||
This driver implements a power port for the robot electronics 8 relay | ||
outputs board. | ||
Driver has been tested with: | ||
* ETH008 - 8 relay outputs | ||
""" | ||
|
||
import requests | ||
from ..exception import ExecutionError | ||
|
||
PORT = 80 | ||
|
||
def power_set(host, port, index, value): | ||
index = int(index) | ||
assert 1 <= index <= 8 | ||
# access the web interface... | ||
value_str = "A" if value else "I" | ||
response = requests.get( | ||
f"http://{host}:{port}/io.cgi?DO{value_str}{index}" | ||
) | ||
response.raise_for_status() | ||
|
||
# Check, that the port is in the desired state | ||
state = get_state(response, index) | ||
if state != value: | ||
raise ExecutionError(f"failed to set port {index} to status {value}") | ||
|
||
def power_get(host, port, index): | ||
index = int(index) | ||
assert 1 <= index <= 8 | ||
# get the contents of the main page | ||
response = requests.get(f"http://{host}:{port}/io.cgi?relay") | ||
|
||
response.raise_for_status() | ||
state = get_state(response, index) | ||
return state | ||
|
||
def get_state(request, index): | ||
value = request.text.split()[1][index-1] | ||
return bool(int(value)) |
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