2015-11-07 18:39:39 +08:00
|
|
|
#!/usr/bin/env python3.5
|
2014-12-11 14:10:15 +08:00
|
|
|
|
|
|
|
import argparse
|
2015-07-01 17:54:15 +08:00
|
|
|
import sys
|
2016-02-22 01:13:20 +08:00
|
|
|
import time
|
2014-12-11 14:10:15 +08:00
|
|
|
|
|
|
|
from artiq.devices.pdq2.driver import Pdq2
|
2015-01-17 19:38:20 +08:00
|
|
|
from artiq.protocols.pc_rpc import simple_server_loop
|
2015-12-27 18:03:13 +08:00
|
|
|
from artiq.tools import *
|
2014-12-11 14:10:15 +08:00
|
|
|
|
|
|
|
|
2015-01-23 00:52:13 +08:00
|
|
|
def get_argparser():
|
2014-12-11 14:10:15 +08:00
|
|
|
parser = argparse.ArgumentParser(description="PDQ2 controller")
|
2015-02-16 05:55:43 +08:00
|
|
|
simple_network_args(parser, 3252)
|
2016-02-22 01:13:20 +08:00
|
|
|
parser.add_argument("-d", "--device", default=None, help="serial port")
|
|
|
|
parser.add_argument("--simulation", action="store_true",
|
|
|
|
help="do not open any device but dump data")
|
|
|
|
parser.add_argument("--dump", default="pdq2_dump.bin",
|
|
|
|
help="file to dump simulation data into")
|
|
|
|
parser.add_argument("-r", "--reset", default=False,
|
|
|
|
action="store_true", help="reset device [%(default)s]")
|
|
|
|
parser.add_argument("-b", "--boards", default=3, type=int,
|
|
|
|
help="number of boards [%(default)s]")
|
2015-01-28 21:44:15 +08:00
|
|
|
verbosity_args(parser)
|
2015-01-23 00:52:13 +08:00
|
|
|
return parser
|
2014-12-11 14:10:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2015-01-23 00:52:13 +08:00
|
|
|
args = get_argparser().parse_args()
|
2015-01-28 21:44:15 +08:00
|
|
|
init_logger(args)
|
2015-03-20 11:38:46 +08:00
|
|
|
port = None
|
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
|
|
|
if args.simulation:
|
2015-03-20 11:38:46 +08:00
|
|
|
port = open(args.dump, "wb")
|
2016-02-22 01:13:20 +08:00
|
|
|
dev = Pdq2(url=args.device, dev=port, num_boards=args.boards)
|
2014-12-11 14:10:15 +08:00
|
|
|
try:
|
2016-02-22 01:13:20 +08:00
|
|
|
if args.reset:
|
|
|
|
dev.write(b"\x00\x00") # flush any escape
|
|
|
|
dev.cmd("RESET", True)
|
|
|
|
dev.flush()
|
|
|
|
time.sleep(.1)
|
|
|
|
dev.cmd("ARM", True)
|
|
|
|
dev.park()
|
2016-02-22 00:35:10 +08:00
|
|
|
simple_server_loop({"pdq2": dev}, bind_address_from_args(args),
|
|
|
|
args.port, description="device=" + str(args.device))
|
2014-12-11 14:10:15 +08:00
|
|
|
finally:
|
|
|
|
dev.close()
|
|
|
|
|
2015-03-20 11:38:46 +08:00
|
|
|
|
2014-12-11 14:10:15 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|