Skip to content

Commit

Permalink
Add interface option to generator script in the cli
Browse files Browse the repository at this point in the history
This commit adds a new option `interface` to the cli. This allows
specifying the interface when connecting to a device.

This option is necessary for hf2, mf and uhf device if not already
connected to the data server
  • Loading branch information
tobiasah committed Sep 24, 2024
1 parent 5948e2a commit ebb1ace
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 10 additions & 1 deletion src/zhinst/labber/cli_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/zhinst/labber/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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 = []
Expand Down
15 changes: 15 additions & 0 deletions tests/generator/test_cli_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit ebb1ace

Please sign in to comment.