2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-21 09:26:29 +08:00
artiq/artiq/frontend/thorlabs_tcube_controller.py
Yann Sionneau d7ef885d9e controllers: print+exit instead of raising exception for argparse error, better doc for --simulation
As long as you use --simulation, the driver will be in simulation mode.
Even if you specify a --device or --channels.

That can allow you to just switch to simulation mode by adding
--simulation in the device database without having to
remove the serial number or device path/name.
2015-07-01 11:54:28 +02:00

54 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import sys
from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
from artiq.protocols.pc_rpc import simple_server_loop
from artiq.tools import verbosity_args, simple_network_args, init_logger
def get_argparser():
parser = argparse.ArgumentParser()
parser.add_argument("-P", "--product", required=True,
help="type of the Thorlabs T-Cube device to control",
choices=["TDC001", "TPZ001"])
parser.add_argument("-d", "--device", default=None,
help="serial device. See documentation for how to "
"specify a USB Serial Number.")
parser.add_argument("--simulation", action="store_true",
help="Put the driver in simulation mode, even if "
"--device is used.")
simple_network_args(parser, 3255)
verbosity_args(parser)
return parser
def main():
args = get_argparser().parse_args()
init_logger(args)
if not args.simulation and args.device is None:
print("You need to specify either --simulation or -d/--device "
"argument. Use --help for more information.")
sys.exit(1)
if args.simulation:
if args.product == "TDC001":
dev = TdcSim()
elif args.product == "TPZ001":
dev = TpzSim()
else:
if args.product == "TDC001":
dev = Tdc(args.device)
elif args.product == "TPZ001":
dev = Tpz(args.device)
try:
simple_server_loop({args.product.lower(): dev}, args.bind, args.port)
finally:
dev.close()
if __name__ == "__main__":
main()