From 515aa968194f7e7578ebec518d5a41371cef341e Mon Sep 17 00:00:00 2001 From: Yann Sionneau Date: Mon, 29 Jun 2015 12:59:52 +0200 Subject: [PATCH] controllers: use --simulation for simulation --- artiq/frontend/lda_controller.py | 7 ++++--- artiq/frontend/novatech409b_controller.py | 7 +++++-- artiq/frontend/pdq2_controller.py | 7 +++++-- artiq/frontend/pxi6733_controller.py | 7 ++++--- artiq/frontend/thorlabs_tcube_controller.py | 7 ++++--- doc/manual/developing_a_ndsp.rst | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/artiq/frontend/lda_controller.py b/artiq/frontend/lda_controller.py index cc70038e9..0f3a0ab32 100755 --- a/artiq/frontend/lda_controller.py +++ b/artiq/frontend/lda_controller.py @@ -19,8 +19,9 @@ def get_argparser(): "The serial number is written on a sticker under " "the device, you should write for example " "-d \"SN:03461\". You must prepend enough 0 for it " - "to be 5 digits." - " Omit for simulation mode.") + "to be 5 digits.") + parser.add_argument("--simulation", action="store_true", + help="Put the driver in simulation mode.") verbosity_args(parser) return parser @@ -28,7 +29,7 @@ def get_argparser(): def main(): args = get_argparser().parse_args() init_logger(args) - if args.device is None: + if args.simulation: lda = Ldasim() else: lda = Lda(args.device, args.product) diff --git a/artiq/frontend/novatech409b_controller.py b/artiq/frontend/novatech409b_controller.py index 30dcd75f7..8eb6b280a 100755 --- a/artiq/frontend/novatech409b_controller.py +++ b/artiq/frontend/novatech409b_controller.py @@ -19,7 +19,10 @@ def get_argparser(): simple_network_args(parser, 3254) parser.add_argument( "-d", "--device", default=None, - help="serial port. Omit for simulation mode.") + help="serial port.") + parser.add_argument( + "--simulation", action="store_true", + help="Put the driver in simulation mode.") verbosity_args(parser) return parser @@ -28,7 +31,7 @@ def main(): args = get_argparser().parse_args() init_logger(args) - dev = Novatech409B(args.device) + dev = Novatech409B(args.device if not args.simulation else None) try: simple_server_loop( {"novatech409b": dev}, args.bind, args.port) diff --git a/artiq/frontend/pdq2_controller.py b/artiq/frontend/pdq2_controller.py index 6404d7d7f..9a9885565 100755 --- a/artiq/frontend/pdq2_controller.py +++ b/artiq/frontend/pdq2_controller.py @@ -12,7 +12,10 @@ def get_argparser(): simple_network_args(parser, 3252) parser.add_argument( "-d", "--device", default=None, - help="serial port. Omit for simulation mode.") + help="serial port.") + parser.add_argument( + "--simulation", action="store_true", + help="Put the driver in simulation mode.") parser.add_argument( "--dump", default="pdq2_dump.bin", help="file to dump pdq2 data into, for later simulation") @@ -24,7 +27,7 @@ def main(): args = get_argparser().parse_args() init_logger(args) port = None - if args.device is None: + if args.simulation: port = open(args.dump, "wb") dev = Pdq2(url=args.device, dev=port) try: diff --git a/artiq/frontend/pxi6733_controller.py b/artiq/frontend/pxi6733_controller.py index 33948d02d..1c4a5ce64 100755 --- a/artiq/frontend/pxi6733_controller.py +++ b/artiq/frontend/pxi6733_controller.py @@ -12,10 +12,11 @@ def get_argparser(): parser = argparse.ArgumentParser(description="NI PXI 6733 controller") simple_network_args(parser, 3256) parser.add_argument("-C", "--channels", default=None, - help="List of channels (e.g. Dev1/ao0, Dev1/ao1:3)." - " Omit for simulation mode.") + help="List of channels (e.g. Dev1/ao0, Dev1/ao1:3).") 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.") verbosity_args(parser) return parser @@ -24,7 +25,7 @@ def main(): args = get_argparser().parse_args() init_logger(args) - if args.channels is None: + if args.simulation: daq = DAQmxSim() else: daq = DAQmx(args.channels, diff --git a/artiq/frontend/thorlabs_tcube_controller.py b/artiq/frontend/thorlabs_tcube_controller.py index d6aea8cbf..c8766dd6c 100755 --- a/artiq/frontend/thorlabs_tcube_controller.py +++ b/artiq/frontend/thorlabs_tcube_controller.py @@ -14,8 +14,9 @@ def get_argparser(): choices=["TDC001", "TPZ001"]) parser.add_argument("-d", "--device", default=None, help="serial device. See documentation for how to " - "specify a USB Serial Number. Omit for simulation " - "mode.") + "specify a USB Serial Number.") + parser.add_argument("--simulation", action="store_true", + help="Put the driver in simulation mode.") simple_network_args(parser, 3255) verbosity_args(parser) return parser @@ -25,7 +26,7 @@ def main(): args = get_argparser().parse_args() init_logger(args) - if args.device is None: + if args.simulation: if args.product == "TDC001": dev = TdcSim() elif args.product == "TPZ001": diff --git a/doc/manual/developing_a_ndsp.rst b/doc/manual/developing_a_ndsp.rst index 98e24e15e..0bc867892 100644 --- a/doc/manual/developing_a_ndsp.rst +++ b/doc/manual/developing_a_ndsp.rst @@ -177,7 +177,7 @@ General guidelines * Use new-style formatting (``str.format``) except for logging where it is not well supported, and double quotes for strings. * The device identification (e.g. serial number, or entry in ``/dev``) to attach to must be passed as a command-line parameter to the controller. We suggest using ``-d`` and ``--device`` as parameter name. * Controllers must be able to operate in "simulation" mode, where they behave properly even if the associated hardware is not connected. For example, they can print the data to the console instead of sending it to the device, or dump it into a file. -* We suggest that the simulation mode is entered whenever the ``-d/--device`` option is omitted. +* The simulation mode is entered whenever the ``--simulation`` option is specified. * Keep command line parameters consistent across clients/controllers. When adding new command line options, look for a client/controller that does a similar thing and follow its use of ``argparse``. If the original client/controller could use ``argparse`` in a better way, improve it. * Use docstrings for all public methods of the driver (note that those will be retrieved by ``artiq_rpctool``). * Choose a free default TCP port and add it to the default port list in this manual.