Skip to main content

A Python AsyncIO library for the Prologix GPIB (Ethernet) adapter

Project description

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

prologix_gpib_async

Python3 AsyncIO Prologix GPIB Driver. This library requires Python 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 :heavy_check_mark: :heavy_check_mark:
GPIB-USB Controller 6.0 :x: :x: 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.

:warning: 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.

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

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

prologix_gpib_async-1.5.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

prologix_gpib_async-1.5.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file prologix_gpib_async-1.5.0.tar.gz.

File metadata

  • Download URL: prologix_gpib_async-1.5.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for prologix_gpib_async-1.5.0.tar.gz
Algorithm Hash digest
SHA256 e742bbadf3138865198998a5b6541a201b92da81710bfe5709f6baefe7780ea7
MD5 f6c2ffb6eea4c1b26df8428324d263ca
BLAKE2b-256 26d639a01287a2a3bedbd6bb2a1355e08ffface6cfee5f2efb0687b7acd6b483

See more details on using hashes here.

File details

Details for the file prologix_gpib_async-1.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prologix_gpib_async-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b525e44dfc639967148f2a2fb2957f7e3b6addaf83db973d6818280561de9223
MD5 9b56dae575727309a92079ae26c3d5d2
BLAKE2b-256 c3943b3b0468c7ac0b53698d59024c0e2ca955057ded65cdfc0639d92a3f7fd4

See more details on using hashes here.

Supported by

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