Skip to main content

pylint Coverage PyPI PyPI - Python Version PyPI - Status License: GPL v3 code style

hp3478a_async

Python3 AsyncIO HP3478A driver. This library requires Python 3.12 or newer and uses asyncio and an AsyncIO library for the GPIB adapter. It also supports several undocumented functions for reading status registers and reading, modifying and writing the calibration memory.

The library is fully type-hinted.

Supported GPIB Hardware

Device Supported Tested Comments
AsyncIO Prologix GPIB library ✔️ ✔️
AsyncIO linux-gpib wrapper ✔️ ✔️

Tested using Linux, should work for Mac OSX, Windows and any OS with Python support.

Documentation

The full documentation can be found on GitHub Pages: https://patrickbaus.github.io/pyAsyncHP3478A/. I use the Numpydoc style for documentation and Sphinx for compiling it.

Setup

To install the library in a virtual environment (always use venvs with every project):

python3 -m venv env  # virtual environment, optional
source env/bin/activate  # only if the virtual environment is used
pip install hp3478a-async

All examples assume that a GPIB library is installed as well. Either run

pip install prologix-gpib-async    # or alternatively
# pip install async-gpib

Usage

The library uses an asynchronous context manager to make cleanup easier. You can use either the context manager syntax or invoke the calls manually:

async with HP_3478A(connection=gpib_device) as hp3478a:
    # Add your code here
    ...
try:
    hp3478a = HP_3478A(connection=gpib_device)
    await hp3478a.connect()
    # your code
finally:
    await hp3478a.disconnect()

A more complete example for reading voltages:

import asyncio
import logging

from hp3478a_async import HP_3478A, FunctionType, TriggerType, Range

from pyAsyncPrologixGpib import AsyncPrologixGpibEthernetController, EosMode

# The default GPIB address is 27. The ip address of the prologix controller needs to be changed.
ip_address = "127.0.0.1"
gpib_device = AsyncPrologixGpibEthernetController(ip_address, pad=27, timeout=1000, eos_mode=EosMode.APPEND_NONE)


async def main():
    """This example will print voltage data to the console"""
    try:
        # No need to explicitly bring up the GPIB connection. This will be done by the instrument.
        async with HP_3478A(connection=gpib_device) as hp3478a:
            await asyncio.gather(
                hp3478a.set_function(FunctionType.DCV),  # Set to 4-wire ohm
                hp3478a.set_range(Range.RANGE_30),  # Set to 30 kOhm range
                hp3478a.set_trigger(TriggerType.INTERNAL),  # Enable free running trigger
                hp3478a.set_autozero(True),  # Enable Autozero
                hp3478a.set_number_of_digits(6),  # Set the resolution to 5.5 digits
                hp3478a.connection.timeout(700),  # The maximum reading rate @ 50 Hz line freq. is 1.9 rds/s
            )

            # Take the measurements until Ctrl+C is pressed
            async for result in hp3478a.read_all():
                print(result)
    except (ConnectionError, ConnectionRefusedError):
        logging.getLogger(__name__).error(
            "Could not connect to remote target. Connection refused. Is the device connected?"
        )


try:
    asyncio.run(main(), debug=False)
except KeyboardInterrupt:
    # The loop will be canceled on a KeyboardInterrupt by the run() method, we just want to suppress the exception
    pass

See examples/ for more working examples.

Unit Tests

There are unit tests available for the calram encoder and decoder.

source env/bin/activate  # only if the virtual environment is used
pytest

Thanks

Special thanks goes to fenugrec and Steve Matos for their work on deciphering the calram function.

Versioning

I use SemVer for versioning. For the versions available, see the tags on this repository.

The version is not stored in the source code. It is taken from the git tag by setuptools-scm when the package is built. To release a new version, publish a GitHub release with a new tag, e.g. 1.5.0. This builds the package as version 1.5.0 and uploads it to PyPI. Commits after a tag get a development version like 1.5.1.dev3.

For development, install the package in editable mode, which also generates hp3478a_async/_version.py:

pip install -e .[dev]

Authors

License

This project is licensed under the GPL v3 license - see the LICENSE file for details

Metadata

Release files for hp3478a-async 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hp3478a-async 2.1.0
File Size Uploaded Provenance Actions
hp3478a_async-2.1.0.tar.gz 52.4 kB Without provenance Details for hp3478a_async-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hp3478a-async 2.1.0
File Interpreter ABI Platform Actions
hp3478a_async-2.1.0-py3-none-any.whl Python 3 none any Details for hp3478a_async-2.1.0-py3-none-any.whl

Total release size: 82.4 kB

Release files / hp3478a_async-2.1.0.tar.gz

Download URL hp3478a_async-2.1.0.tar.gz
Size 52.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d7c7b029e467449c858eae0b182cc585e731db84a068c9e43013106f74757a07
BLAKE2b-256 checksum
How to use checksums
3ecd81085909281f2de25a688a4d466f8c26ecf776419df04b99c3a02844e94b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / hp3478a_async-2.1.0-py3-none-any.whl

Download URL hp3478a_async-2.1.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
697a4af19706522ddef6591910e1719780e4dd9b2ffe8c4ab299950c49a22fa3
BLAKE2b-256 checksum
How to use checksums
c8782dc58ec4c2dd9dccd9bad52b4f45b30df231a9cbc7122e31d08581e015e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for hp3478a-async 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page