Skip to main content

Python3 AsyncIO HP3478A driver

Project description

pylint PyPI PyPI - Python Version PyPI - Status code style

hp3478a_async

Python3 AsyncIO HP3478A driver. This library requires Python asyncio and 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 :heavy_check_mark: :heavy_check_mark:
AsyncIO linux-gpib wrapper :heavy_check_mark: :heavy_check_mark:

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

Usage

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

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

or download the source code from the git repository and copy it to the root folder yourself.

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.

Authors

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hp3478a_async-1.4.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hp3478a_async-1.4.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file hp3478a_async-1.4.0.tar.gz.

File metadata

  • Download URL: hp3478a_async-1.4.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for hp3478a_async-1.4.0.tar.gz
Algorithm Hash digest
SHA256 31d299db098f013fa0304f075d8a4c993f1558480e03b0fd92e39c6ea0339d83
MD5 6518733972ec3304187a73510f253bd5
BLAKE2b-256 e4f7f5403ea0c3f87eb5f860ff316b945eb6e46ed8c0e2202a2ab0589a9668a4

See more details on using hashes here.

File details

Details for the file hp3478a_async-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: hp3478a_async-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for hp3478a_async-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af03fe02d285eb170fe1174946c29d7e3ce1ea72030d6d23191433ccd0d7f87c
MD5 86f43608c1c5a97a20cb80f142e613c9
BLAKE2b-256 78b0363457790ec67ca235650a9733fa20e76958f98247ba2a82b4003977c657

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page