Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module name #8

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
52bab7d
Complete rework to make the library work with the ugPlus
PatrickBaus May 11, 2020
d79a0d4
Cleaned up example
PatrickBaus May 11, 2020
ce284ef
Fixed firmware quirks in a more readable way
PatrickBaus May 18, 2020
3c52546
Fixed firmware bug when detecting GPIB devices
PatrickBaus May 19, 2020
3158f49
Trying to fix readout of the GPIB data
PatrickBaus May 19, 2020
039dc42
Fixed more firmware bugs
PatrickBaus May 19, 2020
d090868
Code cleanup
PatrickBaus Jun 2, 2022
d5b3fc0
Renamed the library to match Python naming conventions
PatrickBaus Jun 5, 2022
e39b3b7
Added installation files
PatrickBaus Jun 5, 2022
fac6a47
Added mechanical infos about the connector used
PatrickBaus Jun 5, 2022
44e9460
Added pylint file
PatrickBaus Jun 5, 2022
4e2e645
Code cleanup.
PatrickBaus Jun 5, 2022
6e1892d
Added type hints and more documentation
PatrickBaus Jun 5, 2022
f1bb0d2
Updated readme and examples
PatrickBaus Jun 5, 2022
b7bbf1a
Updated documentation
PatrickBaus Jun 5, 2022
6a80bb4
Changed timeout parameter from milliseconds to seconds to align with …
PatrickBaus Jun 12, 2022
be5fe52
Fixed typo
PatrickBaus Jun 12, 2022
070d4ca
Code cleanup
PatrickBaus Mar 10, 2023
537d162
More code cleanup
PatrickBaus Mar 10, 2023
8d90368
Added Github workflows
PatrickBaus Mar 10, 2023
ed2985b
Fix multiple package warning
PatrickBaus Mar 10, 2023
761e39e
Added missing build dependency
PatrickBaus Mar 10, 2023
5279dab
Prepare for new release
PatrickBaus Mar 10, 2023
4c7e879
Fixed build
PatrickBaus Mar 10, 2023
ae9e441
Release of version 1.2
PatrickBaus Mar 10, 2023
7787359
Updated readme
PatrickBaus Mar 10, 2023
fb41aef
Updated workflows
PatrickBaus Sep 14, 2023
9e62c3f
Add GPL badge
PatrickBaus Sep 21, 2023
cd0fd18
Create dependabot.yml
PatrickBaus Sep 21, 2023
44667fa
Cleanup
PatrickBaus Sep 21, 2023
d2221dd
Added more pre-commit hooks
PatrickBaus Jun 22, 2024
3482185
Drop Python 3.7 support
PatrickBaus Jun 22, 2024
659709b
Updated pyproject.toml to fix the changes made in pypa/setuptools#4159
PatrickBaus Jun 22, 2024
a6ca4fb
Add missing dependecy
PatrickBaus Jun 22, 2024
4287d5d
Blacked files
PatrickBaus Jun 22, 2024
4399063
Removed pylintrc as it is no longer needed
PatrickBaus Jun 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "daily"
commit-message:
# Prefix all commit messages with "[gha] "
prefix: "[gha] "

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
commit-message:
# Prefix all commit messages with "[pip] "
prefix: "[pip] "
19 changes: 19 additions & 0 deletions .github/workflows/.pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: pre-commit

on:
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.10" ]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: pre-commit/[email protected]
35 changes: 35 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Upload to pypi.org

on:
# Triggers the workflow when a release is created
release:
types: [created]

workflow_dispatch:

jobs:
upload:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.10" ]

steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install and update pip and the build dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[dev]
- name: Build and Upload to PyPI
run: |
python3 -m build
python3 -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/publish-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Upload to test.pypi.org

on:
# Triggers the workflow on push to the master branch
push:
branches: [ "master" ]

workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.10" ]

steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install and update pip and the build dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[dev]
- name: Build and upload to PyPI
continue-on-error: true
run: |
python3 -m build
python3 -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TEST_TOKEN }}
TWINE_REPOSITORY: testpypi
35 changes: 35 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: pylint

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
name: Run Pylint
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.10", "3.11" ]

steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for testing
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[test]
- name: Run Pylint
run: |
# stop the build if there are Python syntax errors or undefined names
pylint --reports n ug_gpib
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-executables-have-shebangs
# Check for invalid files
- id: check-toml
# Check Python files
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
args: [--fix=lf]
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: [--line-length=120]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
require_serial: true
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
hooks:
- id: mypy
1 change: 0 additions & 1 deletion 98-ugsimple.rules
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# UGSimple USB GPIB Adapter
SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="000c", MODE:="0666"

1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

88 changes: 65 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,99 @@
# ugsimple-usb-gpib
Python3 libusb UGSimple GPIB Driver
[![pylint](../../actions/workflows/pylint.yml/badge.svg)](../../actions/workflows/pylint.yml)
[![PyPI](https://img.shields.io/pypi/v/ug-gpib)](https://pypi.org/project/ug-gpib/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ug-gpib)
![PyPI - Status](https://img.shields.io/pypi/status/ug-gpib)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](LICENSE)
[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
# ug_gpib
A Python3 pyUSB driver for the LQ Electronics Corp UGPlus USB to GPIB Controller.

Tested using Linux, should work for Mac OSX, Windows and any OS with Python libusb support.
Tested using Linux, should work for Mac OSX, Windows and any OS with Python [pyUSB](https://github.com/pyusb/pyusb)
support.

:warning: **The device must be IEEE 488.1 compliant. It must assert the EOI line to signal the end of a line. If this is
not the case, the controller cannot be used. Older devices, typically only send CR, LF, or CR-LF.**

The [UGPlus](http://lqelectronics.com/Products/USBUG/UGPlus/UGPlus.html) is a fairly cheap controller, that supports
simple GPIB read and write operations only. It does not support advanced GPIB features like serial polling for example,
and it does not have line drivers to support long cables and lots of devices on the bus.

The UGPlus does have several firmware bugs, I have tried to mitigate them to the best of my knowledge. See
[below](#firmware-bugs) for details.

If you are looking for advanced features I suggest buying either a Prologix GPIB adapter or one of the NI USB adapters.
I can recommend the following libraries for both
[Prologix GPIB adapter](https://github.com/PatrickBaus/pyAsyncPrologixGpib) and
[Linux GPIB](https://github.com/PatrickBaus/pyAsyncGpib).

The library is fully type-hinted.

## Setup

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

```bash
virtualenv env # virtual environment, optional
source env/bin/activate
pip install ug-gpib
```

It is recommended to add the udev rule so root isn't required.
### Linux
To access the raw usb port in Linux, root privileges are required. It is possible to use udev to change ownership of the
usb port on creation. This can be done via a rules file.

```bash
sudo cp 98-ugsimple.rules /etc/udev/rules.d/.
sudo udevadm control --reload-rules
```


## Usage

Initialize UGSimpleGPIB

```python
from ugsimple.GPIB import UGSimpleGPIB
mygpib = UGSimpleGPIB()
from ug_gpib import UGPlusGpib

gpib_controller = UGPlusGpib()
```

Writing "my command" a command to address 0x02
Writing "*IDN?" a command to address 0x02. Do note the GPIB commands must be byte strings.
```python
mygpib.write( 0x02, "my command" )
gpib_controller.write(2, b"*IDN?\n")
```

Reading from address 0x02
Reading from address 0x02 and decoding the byte string to a unicode string.
```python
data = mygpib.read( 0x02 )
print ( data )
data = gpib_controller.read(2)
print(data.decode())
```

Writting and reading the returned result using the ask() method
```python
device_id = mygpib.ask( 0x02, 'ID?' )
print ( device_id )
```
See [examples/](examples/) for more working examples. Including an example that shows how to use the library from the
command line.

## Firmware Bugs
There are several bugs in the firmware of the UGPlus most of those are off-by-one errors and consequently out-of-bounds
reads. I documented them
[here](https://github.com/PatrickBaus/pyUgGpib/blob/f1bb0d2244304b3e3f9776606918eaa270d0e9dc/ug_gpib/ug_gpib.py#L152).
Some of these bugs are also evident when using the software supplied by the manufacturer.
The most obvious ones are the following:

* Out-of-bounds read when reading the firmware version. The controller sends one more byte than requested.
* Out-of-bounds read when discovering GPIB devices. The controller sends one more byte than requested.
* Out-of-bounds read when the GPIB device does not return any data. The controller sends one more byte than requested.

See ugsimple/GPIB.py for further documentation.
## Versioning

I use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](../../tags).

## Notes
## Documentation
I use the [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) style for documentation.

Currently not well tested.
The USB command set for the UGSimple GPIB adapter should be complete but hasn't been tested with many devices yet.
## Authors

* **Jacob Alexander** - *Initial work for the UGSimple* [Jacob Alexander](https://github.com/haata)
* **Patrick Baus** - *Complete rewrite for the UGPlus* - [PatrickBaus](https://github.com/PatrickBaus)

Comments/Bug Reports/Patches welcome :D
## License


This project is licensed under the GPL v3 license - see the [LICENSE](LICENSE) file for details
54 changes: 0 additions & 54 deletions example.py

This file was deleted.

Loading