2015-11-07 18:39:39 +08:00
|
|
|
#!/usr/bin/env python3.5
|
2015-03-04 22:30:33 +08:00
|
|
|
|
|
|
|
import argparse
|
2015-07-01 17:54:15 +08:00
|
|
|
import sys
|
2015-03-04 22:30:33 +08:00
|
|
|
|
|
|
|
from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
|
|
|
|
from artiq.protocols.pc_rpc import simple_server_loop
|
2015-12-27 18:03:13 +08:00
|
|
|
from artiq.tools import *
|
2015-03-04 22:30:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_argparser():
|
|
|
|
parser = argparse.ArgumentParser()
|
2015-03-22 07:48:15 +08:00
|
|
|
parser.add_argument("-P", "--product", required=True,
|
2015-11-03 17:54:27 +08:00
|
|
|
help="type of the Thorlabs T-Cube device to control: "
|
|
|
|
"tdc001/tpz001")
|
2015-03-22 07:48:15 +08:00
|
|
|
parser.add_argument("-d", "--device", default=None,
|
2015-06-19 23:06:50 +08:00
|
|
|
help="serial device. See documentation for how to "
|
2015-06-29 18:59:52 +08:00
|
|
|
"specify a USB Serial Number.")
|
|
|
|
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-03-25 23:20:08 +08:00
|
|
|
simple_network_args(parser, 3255)
|
2015-03-04 22:30:33 +08:00
|
|
|
verbosity_args(parser)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
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-10-21 09:17:39 +08:00
|
|
|
product = args.product.lower()
|
2015-06-29 18:59:52 +08:00
|
|
|
if args.simulation:
|
2015-10-21 09:17:39 +08:00
|
|
|
if product == "tdc001":
|
2015-03-22 07:48:15 +08:00
|
|
|
dev = TdcSim()
|
2015-10-21 09:17:39 +08:00
|
|
|
elif product == "tpz001":
|
2015-03-22 07:48:15 +08:00
|
|
|
dev = TpzSim()
|
2015-11-03 17:54:27 +08:00
|
|
|
else:
|
|
|
|
print("Invalid product string (-P/--product), "
|
|
|
|
"choose from tdc001 or tpz001")
|
|
|
|
sys.exit(1)
|
2015-03-04 22:30:33 +08:00
|
|
|
else:
|
2015-10-21 09:17:39 +08:00
|
|
|
if product == "tdc001":
|
2015-03-22 07:48:15 +08:00
|
|
|
dev = Tdc(args.device)
|
2015-10-21 09:17:39 +08:00
|
|
|
elif product == "tpz001":
|
2015-03-22 07:48:15 +08:00
|
|
|
dev = Tpz(args.device)
|
2015-11-03 17:54:27 +08:00
|
|
|
else:
|
|
|
|
print("Invalid product string (-P/--product), "
|
|
|
|
"choose from tdc001 or tpz001")
|
|
|
|
sys.exit(1)
|
2015-03-04 22:30:33 +08:00
|
|
|
|
2015-03-23 15:58:20 +08:00
|
|
|
try:
|
2015-12-27 18:03:13 +08:00
|
|
|
simple_server_loop({product: dev},
|
|
|
|
bind_address_from_args(args), args.port)
|
2015-03-23 15:58:20 +08:00
|
|
|
finally:
|
|
|
|
dev.close()
|
2015-03-04 22:30:33 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|