2017-01-30 09:24:43 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-02-16 08:31:19 +08:00
|
|
|
|
|
|
|
# Written by Joe Britton, 2015
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
2015-07-01 17:54:15 +08:00
|
|
|
import sys
|
2016-12-12 11:38:02 +08:00
|
|
|
import os
|
2016-03-22 21:55:58 +08:00
|
|
|
import asyncio
|
2015-02-16 08:31:19 +08:00
|
|
|
|
|
|
|
from artiq.devices.novatech409b.driver import Novatech409B
|
|
|
|
from artiq.protocols.pc_rpc import simple_server_loop
|
2015-12-27 18:03:13 +08:00
|
|
|
from artiq.tools import *
|
2015-02-16 08:31:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def get_argparser():
|
|
|
|
parser = argparse.ArgumentParser(
|
2015-03-25 01:04:33 +08:00
|
|
|
description="ARTIQ controller for the Novatech 409B 4-channel DDS box")
|
2015-02-16 08:31:19 +08:00
|
|
|
simple_network_args(parser, 3254)
|
|
|
|
parser.add_argument(
|
2015-03-22 07:48:15 +08:00
|
|
|
"-d", "--device", default=None,
|
2015-06-29 18:59:52 +08:00
|
|
|
help="serial port.")
|
|
|
|
parser.add_argument(
|
|
|
|
"--simulation", action="store_true",
|
2015-07-01 17:54:15 +08:00
|
|
|
help="Put the driver in simulation mode, even if --device is used.")
|
2015-02-16 08:31:19 +08:00
|
|
|
verbosity_args(parser)
|
|
|
|
return parser
|
|
|
|
|
2015-03-25 01:04:33 +08:00
|
|
|
|
2015-02-16 08:31:19 +08:00
|
|
|
def main():
|
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
2016-12-12 11:38:02 +08:00
|
|
|
if os.name == "nt":
|
|
|
|
asyncio.set_event_loop(asyncio.ProactorEventLoop())
|
|
|
|
|
2015-06-30 01:21:32 +08:00
|
|
|
if not args.simulation and args.device is None:
|
2015-07-01 17:54:15 +08:00
|
|
|
print("You need to specify either --simulation or -d/--device "
|
|
|
|
"argument. Use --help for more information.")
|
|
|
|
sys.exit(1)
|
2015-06-30 01:21:32 +08:00
|
|
|
|
2015-06-29 18:59:52 +08:00
|
|
|
dev = Novatech409B(args.device if not args.simulation else None)
|
2016-03-22 21:55:58 +08:00
|
|
|
asyncio.get_event_loop().run_until_complete(dev.setup())
|
2015-02-16 08:31:19 +08:00
|
|
|
try:
|
|
|
|
simple_server_loop(
|
2015-12-27 18:03:13 +08:00
|
|
|
{"novatech409b": dev}, bind_address_from_args(args), args.port)
|
2015-02-16 08:31:19 +08:00
|
|
|
finally:
|
|
|
|
dev.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|