Skip to content

Commit

Permalink
controllers: print+exit instead of raising exception for argparse err…
Browse files Browse the repository at this point in the history
…or, 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.
fallen committed Jul 1, 2015
1 parent 652f335 commit d7ef885
Showing 4 changed files with 22 additions and 16 deletions.
9 changes: 5 additions & 4 deletions artiq/frontend/novatech409b_controller.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

import argparse
import logging
import sys

from artiq.devices.novatech409b.driver import Novatech409B
from artiq.protocols.pc_rpc import simple_server_loop
@@ -22,7 +23,7 @@ def get_argparser():
help="serial port.")
parser.add_argument(
"--simulation", action="store_true",
help="Put the driver in simulation mode.")
help="Put the driver in simulation mode, even if --device is used.")
verbosity_args(parser)
return parser

@@ -32,9 +33,9 @@ def main():
init_logger(args)

if not args.simulation and args.device is None:
raise ValueError("You need to specify either --simulation or "
"-d/--device argument. Use --help for more "
"information.")
print("You need to specify either --simulation or -d/--device "
"argument. Use --help for more information.")
sys.exit(1)

dev = Novatech409B(args.device if not args.simulation else None)
try:
9 changes: 5 additions & 4 deletions artiq/frontend/pdq2_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import sys

from artiq.devices.pdq2.driver import Pdq2
from artiq.protocols.pc_rpc import simple_server_loop
@@ -15,7 +16,7 @@ def get_argparser():
help="serial port.")
parser.add_argument(
"--simulation", action="store_true",
help="Put the driver in simulation mode.")
help="Put the driver in simulation mode, even if --device is used.")
parser.add_argument(
"--dump", default="pdq2_dump.bin",
help="file to dump pdq2 data into, for later simulation")
@@ -29,9 +30,9 @@ def main():
port = None

if not args.simulation and args.device is None:
raise ValueError("You need to specify either --simulation or "
"-d/--device argument. Use --help for more "
"information.")
print("You need to specify either --simulation or -d/--device "
"argument. Use --help for more information.")
sys.exit(1)

if args.simulation:
port = open(args.dump, "wb")
10 changes: 6 additions & 4 deletions artiq/frontend/pxi6733_controller.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
# Yann Sionneau <ys@m-labs.hk>, 2015

import argparse
import sys

from artiq.protocols.pc_rpc import simple_server_loop
from artiq.devices.pxi6733.driver import DAQmx, DAQmxSim
@@ -16,7 +17,8 @@ def get_argparser():
parser.add_argument("-c", "--clock", default="PFI5",
help="Input clock pin name (default: PFI5)")
parser.add_argument("--simulation", action='store_true',
help="Put the driver in simulation mode.")
help="Put the driver in simulation mode, even if "
"--channels is used.")
verbosity_args(parser)
return parser

@@ -26,9 +28,9 @@ def main():
init_logger(args)

if not args.simulation and args.channels is None:
raise ValueError("You need to specify either --simulation or "
"-C/--channels argument. Use --help for more "
"information.")
print("You need to specify either --simulation or -C/--channels "
"argument. Use --help for more information.")
sys.exit(1)

if args.simulation:
daq = DAQmxSim()
10 changes: 6 additions & 4 deletions artiq/frontend/thorlabs_tcube_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/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
@@ -16,7 +17,8 @@ def get_argparser():
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.")
help="Put the driver in simulation mode, even if "
"--device is used.")
simple_network_args(parser, 3255)
verbosity_args(parser)
return parser
@@ -27,9 +29,9 @@ def main():
init_logger(args)

if not args.simulation and args.device is None:
raise ValueError("You need to specify either --simulation or "
"-d/--device argument. Use --help for more "
"information.")
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":

0 comments on commit d7ef885

Please sign in to comment.