Skip to content

Commit d7ef885

Browse files
committedJul 1, 2015
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.
1 parent 652f335 commit d7ef885

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed
 

Diff for: ‎artiq/frontend/novatech409b_controller.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import argparse
66
import logging
7+
import sys
78

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

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

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

3940
dev = Novatech409B(args.device if not args.simulation else None)
4041
try:

Diff for: ‎artiq/frontend/pdq2_controller.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import sys
45

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

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

3637
if args.simulation:
3738
port = open(args.dump, "wb")

Diff for: ‎artiq/frontend/pxi6733_controller.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Yann Sionneau <ys@m-labs.hk>, 2015
33

44
import argparse
5+
import sys
56

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

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

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

3335
if args.simulation:
3436
daq = DAQmxSim()

Diff for: ‎artiq/frontend/thorlabs_tcube_controller.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import sys
45

56
from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
67
from artiq.protocols.pc_rpc import simple_server_loop
@@ -16,7 +17,8 @@ def get_argparser():
1617
help="serial device. See documentation for how to "
1718
"specify a USB Serial Number.")
1819
parser.add_argument("--simulation", action="store_true",
19-
help="Put the driver in simulation mode.")
20+
help="Put the driver in simulation mode, even if "
21+
"--device is used.")
2022
simple_network_args(parser, 3255)
2123
verbosity_args(parser)
2224
return parser
@@ -27,9 +29,9 @@ def main():
2729
init_logger(args)
2830

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

3436
if args.simulation:
3537
if args.product == "TDC001":

0 commit comments

Comments
 (0)
Please sign in to comment.