Skip to content

Commit

Permalink
controllers: use --simulation for simulation
Browse files Browse the repository at this point in the history
fallen committed Jun 29, 2015
1 parent d39382e commit 515aa96
Showing 6 changed files with 23 additions and 14 deletions.
7 changes: 4 additions & 3 deletions artiq/frontend/lda_controller.py
Original file line number Diff line number Diff line change
@@ -19,16 +19,17 @@ 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


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)
7 changes: 5 additions & 2 deletions artiq/frontend/novatech409b_controller.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 5 additions & 2 deletions artiq/frontend/pdq2_controller.py
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 4 additions & 3 deletions artiq/frontend/pxi6733_controller.py
Original file line number Diff line number Diff line change
@@ -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,
7 changes: 4 additions & 3 deletions artiq/frontend/thorlabs_tcube_controller.py
Original file line number Diff line number Diff line change
@@ -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":
2 changes: 1 addition & 1 deletion doc/manual/developing_a_ndsp.rst
Original file line number Diff line number Diff line change
@@ -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.

1 comment on commit 515aa96

@sbourdeauducq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you run e.g. the PDQ controller without -d?

Please sign in to comment.