Command Line Interface¶
Functions related to CLI for PSLab.
Example
>>> from pslab import cli
>>> parser, subparser = cli.get_parser()
>>> cli.add_collect_args(subparser)
>>> cli.add_wave_args(subparser)
>>> cli.add_pwm_args(subparser)
>>> parser.parse_args(["collect","-i","logic_analyzer"])
Namespace(channels=1, duration=1, file_path=None, function='collect',
instrument='logic_analyzer', json=False, port=None)
- pslab.cli.add_collect_args(subparser: argparse._SubParsersAction)[source]¶
Add arguments for collect function to ArgumentParser.
- Parameters
subparser (
argparse._SubParsersAction) – SubParser to add other arguments related to collect function.
- pslab.cli.add_install_args(subparser: argparse._SubParsersAction)[source]¶
Add arguments for install function to ArgumentParser.
- Parameters
subparser (
argparse._SubParsersAction) – SubParser to add other arguments related to install function.
- pslab.cli.add_pwm_args(subparser: argparse._SubParsersAction)[source]¶
Add arguments for pwm {gen,map,set} function to ArgumentParser.
- Parameters
subparser (
argparse._SubParsersAction) – SubParser to add other arguments related to pwm_gen function.
- pslab.cli.add_wave_args(subparser: argparse._SubParsersAction)[source]¶
Add arguments for wave {gen,load} function to ArgumentParser.
- Parameters
subparser (
argparse._SubParsersAction) – SubParser to add other arguments related to wave_gen function.
- pslab.cli.cmdline(args: Optional[List[str]] = None)[source]¶
Command line for pslab.
- Parameters
args (list of strings.) – Arguments to parse.
- pslab.cli.collect(handler: pslab.serial_handler.SerialHandler, args: argparse.Namespace)[source]¶
Collect data from instruments, and write it in file or stdout.
- Parameters
handler (
Handler) – Serial interface for communicating with the PSLab device.args (
argparse.Namespace) – Parsed arguments.
- Raises
LookupError – If the given instrument not available.
- pslab.cli.get_parser() → Tuple[argparse.ArgumentParser, argparse._SubParsersAction][source]¶
Parser for CLI.
- Returns
parser (
argparse.ArgumentParser) – Arqument parser for CLI.functions (
argparse._SubParsersAction) – SubParser to add other arguments related to different function.
- pslab.cli.install(args: argparse.Namespace)[source]¶
Install udev rule on Linux.
- Parameters
args (
argparse.Namespace) – Parsed arguments.
- pslab.cli.logic_analyzer(device: pslab.serial_handler.SerialHandler, channels: int, duration: float) → Tuple[List[str], List[numpy.ndarray]][source]¶
Capture logic events on up to four channels simultaneously.
- Parameters
device (
Handler) – Serial interface for communicating with the PSLab device.channels ({1, 2, 3, 4}) – Number of channels to capture events on. Events will be captured on LA1, LA2, LA3, and LA4, in that order.
duration (float) – Duration in seconds up to which events will be captured.
- Returns
list of str – Name of active channels.
list of numpy.ndarray – List of numpy.ndarrays holding timestamps in microseconds when logic events were detected. The length of the list is equal to the number of channels that were used to capture events, and each list element corresponds to a channel.
Warning
This cannot be used at the same time as the oscilloscope.
- pslab.cli.main(args: argparse.Namespace)[source]¶
Perform the given function on PSLab.
- Parameters
args (
argparse.Namespace) – Parsed arguments.
- pslab.cli.oscilloscope(device: pslab.serial_handler.SerialHandler, channels: int, duration: float) → Tuple[List[str], List[numpy.ndarray]][source]¶
Capture varying voltage signals on up to four channels simultaneously.
- Parameters
device (
Handler) – Serial interface for communicating with the PSLab device.channels ({1, 2, 4}) – Number of channels to sample from simultaneously. By default, samples are captured from CH1, CH2, CH3 and MIC.
duration (float) – Duration in seconds up to which samples will be captured.
- Returns
list of str – “Timestamp”, Name of active channels.
list of numpy.ndarray – List of numpy.ndarrays with timestamps in the first index and corresponding voltages in the following index. The length of the list is equal to one additional to the number of channels that were used to capture samples.
- pslab.cli.pwm(handler: pslab.serial_handler.SerialHandler, args: argparse.Namespace)[source]¶
Generate PWM.
- Parameters
handler (
Handler) – Serial interface for communicating with the PSLab device.args (
argparse.Namespace) – Parsed arguments.
- pslab.cli.wave(handler: pslab.serial_handler.SerialHandler, args: argparse.Namespace)[source]¶
Generate or load wave.
- Parameters
handler (
Handler) – Serial interface for communicating with the PSLab device.args (
argparse.Namespace) – Parsed arguments.