Skip to main content

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

prologix_gpib_async

Python3 AsyncIO Prologix GPIB Driver. This library requires Python 3.12 or newer and uses asyncio. In contrast to a synchronous implementation, this library makes it possible to control multiple GPIB controllers at once and work with large setups.

The library is fully type-hinted.

Supported Hardware

Device Supported Tested Comments
GPIB-ETHERNET Controller 1.2 ✔️ ✔️
GPIB-USB Controller 6.0 ❌ ❌ Need hardware

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

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
pip install prologix-gpib-async

Usage

This library makes use of asynchronous context managers to hide all connection related stuff and also handle cleanup. By the way: Context managers are great!

Initialize the GPIB adapter

from prologix_gpib_async import AsyncPrologixGpibEthernetController

# Create a controller and talk to device address 22
async with AsyncPrologixGpibEthernetController("127.0.0.1", pad=22) as gpib_device:
    # Add your code here
    ...

Sending a "my command" command to address 22 (as set up previously). Do note that strings have to be sent as bytes literals.

await gpib_device.write(b"my command")

Reading data from address 22

data = await gpib_device.read()

Example program, that queries the version string as can be found at examples/example.py

import asyncio

# Devices
from prologix_gpib_async import AsyncPrologixGpibEthernetController


async def main():
    try:
        async with AsyncPrologixGpibEthernetController("127.0.0.1", pad=22) as gpib_device:
            version = await gpib_device.version()
            print("Controller version:", version)
    except (ConnectionError, ConnectionRefusedError):
        print("Could not connect to remote target. Is the device connected?")


asyncio.run(main())

See examples/ for more working examples.

Support for Multiple Devices

The Prologix GPIB adapter supports talking to multiple devices, but there are (theoretical) hardware limits. The Prologix adapters do not have line drivers, so only a limited number of devices can be driven using one controller.

On the software side, there is full support for multiple devices and the driver will switch between different addresses transparently. The driver internally manages the connection and keeps track of the GPIB controller state and manages the state for each gpib object. It is important, that the driver is the only client editing the state of the GPIB controller. Otherwise, the driver state and the controller state may get out of sync.

⚠️ Concurrency with multiple devices: Note, that when using a single adapter to control multiple devices, there is no concurrency on the GPIB bus. Whenever reading or writing to a remote device, the driver will lock the GPIB controller to ensure that reading from a controller is synchronous. This means, there is no speed increase, when making asynchronous reads from multiple devices on the bus. Using a GPIB Group Execute Trigger (GET) by invoking the trigger() function, concurrent measurements can be triggered though. Some devices also allow asynchronous function calls, that signal status updates via the srq register.

Example:

import asyncio

# Devices
from prologix_gpib_async import AsyncPrologixGpibEthernetController

ip_address = "127.0.0.1"


async def main():
    """This example will print the IDs of the two different SCPI devices"""
    try:
        async with AsyncPrologixGpibEthernetController(
            ip_address, pad=22
        ) as gpib_device1, AsyncPrologixGpibEthernetController(ip_address, pad=10) as gpib_device2:
            await gpib_device1.write(b"*IDN?")  # Automatically changes address to device 22
            print(await gpib_device1.read())
            await gpib_device2.write(b"*IDN?")  # Automatically changes address to device 10
            print(await gpib_device2.read())
    except (ConnectionError, ConnectionRefusedError):
        print("Could not connect to remote target. Is the device connected?")


asyncio.run(main())

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.6.0. This builds the package as version 1.6.0 and uploads it to PyPI. Commits after a tag get a development version like 1.6.1.dev3.

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

pip install -e .[dev]

Documentation

I use the Numpydoc style for documentation.

Authors

License

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

Metadata

Release files for prologix-gpib-async 1.6.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 prologix-gpib-async 1.6.0
File Size Uploaded Provenance Actions
prologix_gpib_async-1.6.0.tar.gz 43.5 kB Without provenance Details for prologix_gpib_async-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prologix-gpib-async 1.6.0
File Interpreter ABI Platform Actions
prologix_gpib_async-1.6.0-py3-none-any.whl Python 3 none any Details for prologix_gpib_async-1.6.0-py3-none-any.whl

Total release size: 76.0 kB

Release files / prologix_gpib_async-1.6.0.tar.gz

Download URL prologix_gpib_async-1.6.0.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0e608d4bc8c7323ee63c04d5c67cf25ef5aa4adbd0324ad7faf0c80686de04f8
BLAKE2b-256 checksum
How to use checksums
31e3fd0ffe97db240efd935860482789c5c5fc546681a0f4ba6853d4b5faa7a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / prologix_gpib_async-1.6.0-py3-none-any.whl

Download URL prologix_gpib_async-1.6.0-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85adc260ffcf82e37e89ce92c9b3391cc3d0fb3176dbd5041bd31e5cf8c1bb97
BLAKE2b-256 checksum
How to use checksums
68ec9e0bad42bce691d123edea92184934417d1850974a50ba6368de4b5565b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for prologix-gpib-async 1.6.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