This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controller, unittest, documentation, packaging
- Loading branch information
Showing
6 changed files
with
153 additions
and
21 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,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
import asyncio | ||
|
||
from . import HUT2 | ||
|
||
from artiq.protocols.pc_rpc import Server | ||
from artiq.tools import (verbosity_args, simple_network_args, init_logger, | ||
bind_address_from_args) | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_argparser(): | ||
parser = argparse.ArgumentParser( | ||
description="""HUT2 controller. | ||
Use this controller for Anel HUT2 power distribution devices.""") | ||
parser.add_argument( | ||
"-d", "--device", default=None, | ||
help="Device host name or IP address.") | ||
simple_network_args(parser, 3271) | ||
verbosity_args(parser) | ||
return parser | ||
|
||
|
||
def main(): | ||
args = get_argparser().parse_args() | ||
init_logger(args) | ||
|
||
if args.device is None: | ||
print("You need to supply a -d/--device " | ||
"argument. Use --help for more information.") | ||
sys.exit(1) | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
async def run(): | ||
with await HUT2.connect(args.device, loop=loop) as dev: | ||
server = Server({"hut2": dev}, None, True) | ||
await server.start(bind_address_from_args(args), args.port) | ||
try: | ||
await server.wait_terminate() | ||
finally: | ||
await server.stop() | ||
|
||
try: | ||
loop.run_until_complete(run()) | ||
finally: | ||
loop.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,59 @@ | ||
import asyncio | ||
import unittest | ||
import os | ||
|
||
from .protocol import HUT2 | ||
|
||
|
||
target = os.getenv("HUT2") | ||
@unittest.skipIf(not target, "HUT2 environment variable not defined") | ||
class HUT2Test(unittest.TestCase): | ||
def with_device(self, f): | ||
loop = asyncio.get_event_loop() | ||
async def run(): | ||
with await HUT2.connect(target, loop=loop) as dev: | ||
return await f(dev) | ||
return loop.run_until_complete(run()) | ||
|
||
def test_connect(self): | ||
async def run(dev): | ||
pass | ||
self.with_device(run) | ||
|
||
def test_status(self): | ||
async def run(dev): | ||
st = await dev.get_status() | ||
self.assertGreater(st.temp, 0.) | ||
self.assertLess(st.temp, 100.) | ||
self.with_device(run) | ||
|
||
def test_sw(self): | ||
async def run(dev): | ||
for s in 0, 1: | ||
dev.sw(0x7f | (s << 7)) | ||
await asyncio.sleep(.2) | ||
self.assertEqual((await dev.get_status()).port_states[7], s) | ||
self.with_device(run) | ||
|
||
def test_sw_onoff(self): | ||
async def run(dev): | ||
dev.sw_off(8) | ||
await asyncio.sleep(.2) | ||
self.assertEqual((await dev.get_status()).port_states[7], 0) | ||
dev.sw_on(8) | ||
await asyncio.sleep(.2) | ||
self.assertEqual((await dev.get_status()).port_states[7], 1) | ||
self.with_device(run) | ||
|
||
def test_st(self): | ||
async def run(dev): | ||
dev.sw_on(8) | ||
await asyncio.sleep(.2) | ||
dev.st_off(8, 1) | ||
await asyncio.sleep(.2) | ||
self.assertEqual((await dev.get_status()).port_states[7], 1) | ||
await asyncio.sleep(1) | ||
self.assertEqual((await dev.get_status()).port_states[7], 0) | ||
dev.sw_on(8) | ||
await asyncio.sleep(.2) | ||
self.with_device(run) |
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