Skip to content

Commit

Permalink
Extend device interface autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
markheik committed Apr 19, 2024
1 parent 02bf589 commit 3bec387
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 0.6.4
* Function `wait_for_state_change` now works with zero timeout; the node value is always checked at least once.
* Improved the stability of device interface auto-detection when it is not supplied while connecting to a device.

## Version 0.6.3
* Adapt `write_integration_weights` function in the readout module to be callable within transactions.
Expand Down
7 changes: 4 additions & 3 deletions src/zhinst/toolkit/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,12 @@ def connect_device(
dev_info = json.loads(self.daq_server.getString("/zi/devices"))[
serial.upper()
]
interface = dev_info["INTERFACE"]
if interface == "none":
interface = t.cast(str, dev_info["INTERFACE"])
undefined_interfaces = ("none", "", "unknown")
if interface.lower() in undefined_interfaces:
interface = (
"1GbE"
if "1GbE" in dev_info["INTERFACES"]
if "1gbe" in dev_info["INTERFACES"].lower()
else dev_info["INTERFACES"].split(",")[0]
)
self._daq_server.connectDevice(serial, interface)
Expand Down
22 changes: 12 additions & 10 deletions tests/test_data_server_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,23 @@ def connect_device_side_effect(serial, interface):
connected_devices = ""
selected_interface = ""

zi_devices = json.loads(zi_devices_json)
zi_devices["DEV1234"]["INTERFACE"] = "none"
zi_devices_json = json.dumps(zi_devices)
for none_interface in ("none", "", "unknown"):
zi_devices = json.loads(zi_devices_json)
zi_devices["DEV1234"]["INTERFACE"] = none_interface
zi_devices_json = json.dumps(zi_devices)

session.connect_device("dev1234")
assert selected_interface == "1GbE"
session.connect_device("dev1234")
assert selected_interface == "1GbE"
connected_devices = ""
selected_interface = ""

zi_devices = json.loads(zi_devices_json)
zi_devices["DEV1234"]["INTERFACES"] = "1GbE,USB"
zi_devices_json = json.dumps(zi_devices)
for gbe_interface in ("1GBE", "1GbE"):
zi_devices = json.loads(zi_devices_json)
zi_devices["DEV1234"]["INTERFACES"] = f"{gbe_interface},USB"
zi_devices_json = json.dumps(zi_devices)

session.connect_device("dev1234")
assert selected_interface == "1GbE"
session.connect_device("dev1234")
assert selected_interface == "1GbE"
connected_devices = ""
selected_interface = ""

Expand Down

0 comments on commit 3bec387

Please sign in to comment.