diff --git a/CHANGELOG.md b/CHANGELOG.md index 06281c49..39a73c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # zhinst-labber Changelog +## Version 0.3.3 + +- Add `interface` option to cli to allow specifying the interface of the target device. + This is mostly necessary for the hf2, mf and uhf device family since they require an + interface to be explicitly specified, if the device it not already connected to the data + server. + ## Version 0.3.2 - Fixed issue where an empty command table was sent to the device when the node has no value defined in Labber UI, diff --git a/src/zhinst/labber/cli_script.py b/src/zhinst/labber/cli_script.py index cf7d0af7..a54fe96e 100644 --- a/src/zhinst/labber/cli_script.py +++ b/src/zhinst/labber/cli_script.py @@ -33,6 +33,12 @@ def main(): type=int, help="Zurich Instruments Data Server port", ) +@click.option( + "--interface", + required=False, + type=str, + help="Optional interface that should be used to connect to the device.", +) @click.option("--hf2", required=False, is_flag=True, help="HF2 Dataserver") @click.option( "--mode", @@ -62,7 +68,9 @@ def main(): functionality or nodes. """, ) -def setup(driver_directory, device_id, server_host, server_port, hf2, mode, upgrade): +def setup( + driver_directory, device_id, server_host, server_port, interface, hf2, mode, upgrade +): """Generate Zurich Instruments Labber drivers. This script generates the necessary files to control Zurich Instruments @@ -84,6 +92,7 @@ def setup(driver_directory, device_id, server_host, server_port, hf2, mode, upgr driver_directory=driver_directory, device_id=device_id, server_host=server_host, + interface=interface, mode=mode.upper(), upgrade=upgrade, server_port=server_port, diff --git a/src/zhinst/labber/generator/generator.py b/src/zhinst/labber/generator/generator.py index c3ef3d05..adb4accd 100644 --- a/src/zhinst/labber/generator/generator.py +++ b/src/zhinst/labber/generator/generator.py @@ -3,12 +3,10 @@ import json import typing as t from collections import OrderedDict -from pathlib import Path from distutils.dir_util import copy_tree +from pathlib import Path import natsort -from zhinst.toolkit import Session -from zhinst.toolkit.nodetree import Node from zhinst.labber import __version__ from zhinst.labber.code_generator.drivers import generate_labber_device_driver_code @@ -20,6 +18,9 @@ match_in_list, ) from zhinst.labber.generator.quants import NodeQuant, Quant, QuantGenerator +from zhinst.labber.helper import check_compatibility +from zhinst.toolkit import Session +from zhinst.toolkit.nodetree import Node class LabberConfig: @@ -487,6 +488,7 @@ def generate_labber_files( mode: str, device_id: str, server_host: str, + interface: t.Optional[str] = None, upgrade: bool = False, server_port: t.Optional[int] = None, hf2: t.Optional[bool] = None, @@ -500,13 +502,14 @@ def generate_labber_files( Advanced has most of the nodes available. device_id: Zurich Instruments device ID. (e.g: dev1234) server_host: DataServer host + interface: Interface the device should be connected to. upgrade: Overwrite existing drivers server_port: DataServer port hf2: If the device is HF2. """ session = Session(server_host=server_host, server_port=server_port, hf2=hf2) check_compatibility(session) - dev = session.connect_device(device_id) + dev = session.connect_device(device_id, interface=interface) # Files generated to echo generated_files = [] diff --git a/tests/generator/test_cli_script.py b/tests/generator/test_cli_script.py index 19b4d024..f46bf223 100644 --- a/tests/generator/test_cli_script.py +++ b/tests/generator/test_cli_script.py @@ -33,6 +33,19 @@ def test_cli_script_setup_help(): { "device_id": "dev1234", "server_host": "localhost", + "interface": None, + "mode": "NORMAL", + "upgrade": False, + "server_port": None, + "hf2": False, + }, + ), + ( + ["dev1234", "localhost", "--interface=USB"], + { + "device_id": "dev1234", + "server_host": "localhost", + "interface": "USB", "mode": "NORMAL", "upgrade": False, "server_port": None, @@ -51,6 +64,7 @@ def test_cli_script_setup_help(): { "device_id": "dev1234", "server_host": "localhost", + "interface": None, "mode": "ADVANCED", "upgrade": True, "server_port": 812, @@ -62,6 +76,7 @@ def test_cli_script_setup_help(): { "device_id": "dev1234", "server_host": "localhost", + "interface": None, "mode": "NORMAL", "upgrade": False, "server_port": 812,