Zurich Instruments Core Python API

26.1.3.9 · active · verified Fri Apr 17

zhinst-core is the core Python API for communicating with Zurich Instruments devices, providing low-level control and data acquisition capabilities. It is currently at version 26.1.3.9 and typically releases new versions in sync with Zurich Instruments LabOne software and device firmware updates, often multiple times a year, ensuring compatibility with the latest features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to the Zurich Instruments LabOne Data Acquisition (DAQ) server using `zhinst-core`, ping the server, list connected devices, and attempt to read a basic property from the first device. It includes error handling for common connection and API issues. The DAQ server, part of the LabOne software, must be running for this code to connect successfully.

import zhinst.core
import os

# Configuration for connecting to the DAQ server
# The LabOne Data Acquisition (DAQ) server must be running on your system.
# Use environment variables or modify these values if your server is not on localhost:8004.
DAQ_SERVER_HOST = os.getenv('ZHINST_DAQLOGIN', 'localhost')
DAQ_SERVER_PORT = int(os.getenv('ZHINST_DAQPORT', '8004'))
API_LEVEL = 6 # zhinst-core typically uses API level 6

try:
    # Establish a connection to the DAQ server
    daq = zhinst.core.ziDAQServer(DAQ_SERVER_HOST, DAQ_SERVER_PORT, API_LEVEL)
    print(f"Successfully connected to DAQ server at {DAQ_SERVER_HOST}:{DAQ_SERVER_PORT}.")

    # Ping the server to confirm active communication
    daq.ping()
    print("DAQ server ping successful.")

    # List all devices currently connected to the DAQ server
    devices = daq.listDevices()
    if devices:
        print(f"Connected Zurich Instruments devices: {devices}")
        # Example: Read a property from the first connected device
        # Note: Replace 'first_device' and the node path with actual values if needed
        first_device = devices[0]
        try:
            device_model = daq.getString(f'/{first_device}/type')
            print(f"Model of first device ({first_device}): {device_model}")
        except zhinst.core.errors.CoreError as e:
            print(f"Warning: Could not read device type for {first_device}. Error: {e}")
            print("Ensure the device is online and the node path is valid for your device.")
    else:
        print("No Zurich Instruments devices are currently connected to the DAQ server.")
        print("Ensure devices are powered on, connected, and recognized by LabOne.")

except ConnectionRefusedError:
    print(f"Error: Connection refused. Please ensure the Zurich Instruments LabOne DAQ Server is running and accessible at {DAQ_SERVER_HOST}:{DAQ_SERVER_PORT}.")
    print("Refer to the LabOne documentation for starting the DAQ server.")
except zhinst.core.errors.CoreError as e:
    print(f"A zhinst.core API error occurred: {e}")
    print("This could be due to an API level mismatch, invalid node path, or a server issue.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →