-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QMI-102] Adding the Windows-version Bristol FOS QMI driver. Also add…
…ed respective unit-tests and a new CLI client (not yet tested). Also added on dependency list in `README.md` the `mcculw` module.
- Loading branch information
Henri Ervasti
committed
Sep 20, 2024
1 parent
16af880
commit dedba82
Showing
5 changed files
with
461 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#! /usr/bin/env python3 | ||
|
||
"""Command line client for the Bristol FOS Fiber-optic switch.""" | ||
|
||
import argparse | ||
from contextlib import nullcontext, AbstractContextManager | ||
import sys | ||
|
||
import qmi | ||
from qmi.instruments.bristol import Bristol_Fos | ||
from qmi.utils.context_managers import start_stop | ||
|
||
|
||
def main() -> int: | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.description = "Command line client for the Bristol FOS Fiber-optic switch." | ||
|
||
source = parser.add_mutually_exclusive_group(required=True) | ||
source.add_argument("--rpc", help="QMI RPC address of device.") | ||
source.add_argument("--unique_id", help="Unique ID of the device") | ||
|
||
parser.add_argument("--board_id", type=int, help="Board number for the device. Windows only!") | ||
parser.add_argument("--channel", type=int, help="Channel number to set") | ||
|
||
args = parser.parse_args() | ||
|
||
instr: Bristol_Fos | ||
with start_stop(qmi, "bristol_fos_client", console_loglevel="WARNING"), parse_source(args) as instr: | ||
if args.channel is None: | ||
print(f"Bristol FOS with unique ID {args.unique_id} found. No channel selected.") | ||
|
||
else: | ||
print(f"Selecting channel {args.channel} for Bristol FOS with unique ID {args.unique_id}.") | ||
instr.select_channel(args.channel) | ||
|
||
|
||
def parse_source(args) -> AbstractContextManager: | ||
# make the instrument | ||
if args.unique_id is not None and args.board_id is not None: | ||
with qmi.make_instrument( | ||
instrument_name="FOS", | ||
instrument_class=Bristol_Fos, | ||
unique_id=args.unique_id, | ||
board_id=int(args.board_id) | ||
) as fos: | ||
return fos | ||
|
||
if args.unique_id is not None: | ||
with qmi.make_instrument( | ||
instrument_name="FOS", | ||
instrument_class=Bristol_Fos, | ||
unique_id=args.unique_id | ||
) as fos: | ||
return fos | ||
|
||
if args.rpc is not None: | ||
# get the instrument | ||
qmi.context().connect_to_peer(args.rpc.split('.')[0]) | ||
return nullcontext(qmi.get_instrument(args.rpc)) | ||
|
||
raise ValueError("Expected an unique ID or RPC address for the instrument!") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.