forked from M-Labs/artiq
1
0
Fork 0

controllers: use --simulation for simulation

This commit is contained in:
Yann Sionneau 2015-06-29 12:59:52 +02:00
parent d39382eca0
commit 515aa96819
6 changed files with 23 additions and 14 deletions

View File

@ -19,8 +19,9 @@ def get_argparser():
"The serial number is written on a sticker under " "The serial number is written on a sticker under "
"the device, you should write for example " "the device, you should write for example "
"-d \"SN:03461\". You must prepend enough 0 for it " "-d \"SN:03461\". You must prepend enough 0 for it "
"to be 5 digits." "to be 5 digits.")
" Omit for simulation mode.") parser.add_argument("--simulation", action="store_true",
help="Put the driver in simulation mode.")
verbosity_args(parser) verbosity_args(parser)
return parser return parser
@ -28,7 +29,7 @@ def get_argparser():
def main(): def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
init_logger(args) init_logger(args)
if args.device is None: if args.simulation:
lda = Ldasim() lda = Ldasim()
else: else:
lda = Lda(args.device, args.product) lda = Lda(args.device, args.product)

View File

@ -19,7 +19,10 @@ def get_argparser():
simple_network_args(parser, 3254) simple_network_args(parser, 3254)
parser.add_argument( parser.add_argument(
"-d", "--device", default=None, "-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) verbosity_args(parser)
return parser return parser
@ -28,7 +31,7 @@ def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
init_logger(args) init_logger(args)
dev = Novatech409B(args.device) dev = Novatech409B(args.device if not args.simulation else None)
try: try:
simple_server_loop( simple_server_loop(
{"novatech409b": dev}, args.bind, args.port) {"novatech409b": dev}, args.bind, args.port)

View File

@ -12,7 +12,10 @@ def get_argparser():
simple_network_args(parser, 3252) simple_network_args(parser, 3252)
parser.add_argument( parser.add_argument(
"-d", "--device", default=None, "-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( parser.add_argument(
"--dump", default="pdq2_dump.bin", "--dump", default="pdq2_dump.bin",
help="file to dump pdq2 data into, for later simulation") help="file to dump pdq2 data into, for later simulation")
@ -24,7 +27,7 @@ def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
init_logger(args) init_logger(args)
port = None port = None
if args.device is None: if args.simulation:
port = open(args.dump, "wb") port = open(args.dump, "wb")
dev = Pdq2(url=args.device, dev=port) dev = Pdq2(url=args.device, dev=port)
try: try:

View File

@ -12,10 +12,11 @@ def get_argparser():
parser = argparse.ArgumentParser(description="NI PXI 6733 controller") parser = argparse.ArgumentParser(description="NI PXI 6733 controller")
simple_network_args(parser, 3256) simple_network_args(parser, 3256)
parser.add_argument("-C", "--channels", default=None, parser.add_argument("-C", "--channels", default=None,
help="List of channels (e.g. Dev1/ao0, Dev1/ao1:3)." help="List of channels (e.g. Dev1/ao0, Dev1/ao1:3).")
" Omit for simulation mode.")
parser.add_argument("-c", "--clock", default="PFI5", parser.add_argument("-c", "--clock", default="PFI5",
help="Input clock pin name (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) verbosity_args(parser)
return parser return parser
@ -24,7 +25,7 @@ def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
init_logger(args) init_logger(args)
if args.channels is None: if args.simulation:
daq = DAQmxSim() daq = DAQmxSim()
else: else:
daq = DAQmx(args.channels, daq = DAQmx(args.channels,

View File

@ -14,8 +14,9 @@ def get_argparser():
choices=["TDC001", "TPZ001"]) choices=["TDC001", "TPZ001"])
parser.add_argument("-d", "--device", default=None, parser.add_argument("-d", "--device", default=None,
help="serial device. See documentation for how to " help="serial device. See documentation for how to "
"specify a USB Serial Number. Omit for simulation " "specify a USB Serial Number.")
"mode.") parser.add_argument("--simulation", action="store_true",
help="Put the driver in simulation mode.")
simple_network_args(parser, 3255) simple_network_args(parser, 3255)
verbosity_args(parser) verbosity_args(parser)
return parser return parser
@ -25,7 +26,7 @@ def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
init_logger(args) init_logger(args)
if args.device is None: if args.simulation:
if args.product == "TDC001": if args.product == "TDC001":
dev = TdcSim() dev = TdcSim()
elif args.product == "TPZ001": elif args.product == "TPZ001":

View File

@ -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. * 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. * 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. * 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. * 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``). * 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. * Choose a free default TCP port and add it to the default port list in this manual.