py-opc-ng


Namepy-opc-ng JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/fargiolas/py-opc-ng
SummaryPython library to operate Alphasense OPC particle counters
upload_time2023-01-30 18:40:44
maintainer
docs_urlNone
authorFilippo Argiolas
requires_python
licenseLGPLv3
keywords alphasense opc particulates sensors air quality optical particle counter opc-n2 opc-n3 opc-r1 opc-r2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # py-opc-ng

A small python library to operate Alphasense OPC devices.

Supports most modern OPC devices: OPC-N2, OPC-N3, OPC-R1 and OPC-R2.

## Installation

    $ pip install py-opc-ng

## Dependencies

The devices work with SPI interface. You can either connect them
directly to a SPI bus using
[`py-spidev`](https://github.com/doceme/py-spidev) (e.g. with the GPIO
pins of a RaspberryPi) or use a SPI to USB device, like the one
Alphasense provides, using the
[`pyusbiss`](https://github.com/dancingquanta/pyusbiss) library.

## Getting help

You can find full documentation, including API references, at http://py-opc-ng.readthedocs.io/

## Usage

With a direct SPI connection:

```python
from time import sleep
import spidev
import opcng as opc

spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
spi.max_speed_hz = 500000
spi.lsbfirst = False

dev = opc.detect(spi)

print(f'device information: {dev.info()}')
print(f'serial: {dev.serial()}')
print(f'firmware version: {dev.serial()}')

# power on fan and laser
dev.on()

for i in range(10):
    # query particle mass readings
    sleep(1)
    print(dev.pm())

# power off fan and laser
dev.off()
```

or with a SPI to USB bridge:

```python
from time import sleep
from usbiss.spi import SPI
import opcng as opc

spi = SPI('/dev/ttyACM0')
spi.mode = 1
spi.max_speed_hz = 500000
spi.lsbfirst = False

dev = opc.detect(spi)

print(f'device information: {dev.info()}')
print(f'serial: {dev.serial()}')
print(f'firmware version: {dev.serial()}')

# power on fan and laser
dev.on()

for i in range(10):
    # query particle mass readings
    sleep(1)
    print(dev.pm())

# power off fan and laser
dev.off()
```

## Known issues

OPC N2 and N3 have a so-called *autonomous mode* where the device
operates on its own saving data in the included sd-card. When you
power on the devices and don't do anything for some time (about 65s
for N3) the automatically enter this standalone mode and start
acquiring data. See e.g. Chapter 9 in OPC N3 manual.

When this happens the device still listens for SPI commands but
sometimes (most of the time?) fails to respond and behaves erratically.

When you try to access the device while in this mode you may get
errors like:

```
>>> opc.detect()
ERROR:opcng:Error while reading bytes from the device: Received unexpected response 0x00 for command: 0x3F
ERROR:opcng:Something failed while reading byte sequence, expected size: 60, received: 0
ERROR:opcng:Could not detect a valid OPC device
```

I don't have a solution yet, see discussion in issue #1. The solution
is do not let the device enter this mode. As soon as you power up your
host or connect the OPC send some SPI command to prevent this
autonomous mode. If it enters it before you have the chance to
interact with it the best way out is to power cycle the device or
reboot the host.

Not much of an issue as these are devices that should be operated
continously so you should start them as soon as you boot your host.

Nonetheless, if you know a way to disable this mode please do let me
know.

## A note about the name

When this project was started the most popular library to operate
Alphasense OPC devices was
[`py-opc`](https://github.com/dhagan/py-opc). At the time it only
supported OPC-N2 and had a lot of code very specific to that device
generation.

Adding support for next generation (hence the `-ng`) devices there
seemed to require quite some effort. We wanted to abstract common
characteristics of the different devices in a single interface right
from the start. We also didn't want to support all the quirks they had
for N2 different firmware versions as we were already moving away
from N2 devices.

So we opted to start a completely new project. It's not a fork and
doesn't share any code with
[`py-opc`](https://github.com/dhagan/py-opc).


## License

This module is licensed under the GNU Lesser General Public License
Version 3. Full text can be found in the LICENSE file.


## Acknowledgement
This package was developed within the Cagliari2020 project with the support of [Istituto Nazionale di Fisica Nucleare (INFN)](http://home.infn.it/en/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fargiolas/py-opc-ng",
    "name": "py-opc-ng",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "alphasense,opc,particulates sensors,air quality,optical particle counter,opc-n2,opc-n3,opc-r1,opc-r2",
    "author": "Filippo Argiolas",
    "author_email": "filippo.argiolas@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/66/69/bcca5278c9fb06d0da2c66aa8facee475522c6ee6e8750a5a9b87ba53285/py-opc-ng-0.0.5.tar.gz",
    "platform": null,
    "description": "# py-opc-ng\n\nA small python library to operate Alphasense OPC devices.\n\nSupports most modern OPC devices: OPC-N2, OPC-N3, OPC-R1 and OPC-R2.\n\n## Installation\n\n    $ pip install py-opc-ng\n\n## Dependencies\n\nThe devices work with SPI interface. You can either connect them\ndirectly to a SPI bus using\n[`py-spidev`](https://github.com/doceme/py-spidev) (e.g. with the GPIO\npins of a RaspberryPi) or use a SPI to USB device, like the one\nAlphasense provides, using the\n[`pyusbiss`](https://github.com/dancingquanta/pyusbiss) library.\n\n## Getting help\n\nYou can find full documentation, including API references, at http://py-opc-ng.readthedocs.io/\n\n## Usage\n\nWith a direct SPI connection:\n\n```python\nfrom time import sleep\nimport spidev\nimport opcng as opc\n\nspi = spidev.SpiDev()\nspi.open(0, 0)\nspi.mode = 1\nspi.max_speed_hz = 500000\nspi.lsbfirst = False\n\ndev = opc.detect(spi)\n\nprint(f'device information: {dev.info()}')\nprint(f'serial: {dev.serial()}')\nprint(f'firmware version: {dev.serial()}')\n\n# power on fan and laser\ndev.on()\n\nfor i in range(10):\n    # query particle mass readings\n    sleep(1)\n    print(dev.pm())\n\n# power off fan and laser\ndev.off()\n```\n\nor with a SPI to USB bridge:\n\n```python\nfrom time import sleep\nfrom usbiss.spi import SPI\nimport opcng as opc\n\nspi = SPI('/dev/ttyACM0')\nspi.mode = 1\nspi.max_speed_hz = 500000\nspi.lsbfirst = False\n\ndev = opc.detect(spi)\n\nprint(f'device information: {dev.info()}')\nprint(f'serial: {dev.serial()}')\nprint(f'firmware version: {dev.serial()}')\n\n# power on fan and laser\ndev.on()\n\nfor i in range(10):\n    # query particle mass readings\n    sleep(1)\n    print(dev.pm())\n\n# power off fan and laser\ndev.off()\n```\n\n## Known issues\n\nOPC N2 and N3 have a so-called *autonomous mode* where the device\noperates on its own saving data in the included sd-card. When you\npower on the devices and don't do anything for some time (about 65s\nfor N3) the automatically enter this standalone mode and start\nacquiring data. See e.g. Chapter 9 in OPC N3 manual.\n\nWhen this happens the device still listens for SPI commands but\nsometimes (most of the time?) fails to respond and behaves erratically.\n\nWhen you try to access the device while in this mode you may get\nerrors like:\n\n```\n>>> opc.detect()\nERROR:opcng:Error while reading bytes from the device: Received unexpected response 0x00 for command: 0x3F\nERROR:opcng:Something failed while reading byte sequence, expected size: 60, received: 0\nERROR:opcng:Could not detect a valid OPC device\n```\n\nI don't have a solution yet, see discussion in issue #1. The solution\nis do not let the device enter this mode. As soon as you power up your\nhost or connect the OPC send some SPI command to prevent this\nautonomous mode. If it enters it before you have the chance to\ninteract with it the best way out is to power cycle the device or\nreboot the host.\n\nNot much of an issue as these are devices that should be operated\ncontinously so you should start them as soon as you boot your host.\n\nNonetheless, if you know a way to disable this mode please do let me\nknow.\n\n## A note about the name\n\nWhen this project was started the most popular library to operate\nAlphasense OPC devices was\n[`py-opc`](https://github.com/dhagan/py-opc). At the time it only\nsupported OPC-N2 and had a lot of code very specific to that device\ngeneration.\n\nAdding support for next generation (hence the `-ng`) devices there\nseemed to require quite some effort. We wanted to abstract common\ncharacteristics of the different devices in a single interface right\nfrom the start. We also didn't want to support all the quirks they had\nfor N2 different firmware versions as we were already moving away\nfrom N2 devices.\n\nSo we opted to start a completely new project. It's not a fork and\ndoesn't share any code with\n[`py-opc`](https://github.com/dhagan/py-opc).\n\n\n## License\n\nThis module is licensed under the GNU Lesser General Public License\nVersion 3. Full text can be found in the LICENSE file.\n\n\n## Acknowledgement\nThis package was developed within the Cagliari2020 project with the support of [Istituto Nazionale di Fisica Nucleare (INFN)](http://home.infn.it/en/)\n",
    "bugtrack_url": null,
    "license": "LGPLv3",
    "summary": "Python library to operate Alphasense OPC particle counters",
    "version": "0.0.5",
    "split_keywords": [
        "alphasense",
        "opc",
        "particulates sensors",
        "air quality",
        "optical particle counter",
        "opc-n2",
        "opc-n3",
        "opc-r1",
        "opc-r2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db3c37645ed2e950a2b1d9163d130d3a085fbed0e3231dd15b3c1c4d6a94e024",
                "md5": "c481844fe632e52a4ea04defc9d811d5",
                "sha256": "f0fc40d4a960340e334bba6e6a72a254c01066bcecc6bd8af8a288edbac4763f"
            },
            "downloads": -1,
            "filename": "py_opc_ng-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c481844fe632e52a4ea04defc9d811d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11717,
            "upload_time": "2023-01-30T18:40:43",
            "upload_time_iso_8601": "2023-01-30T18:40:43.055984Z",
            "url": "https://files.pythonhosted.org/packages/db/3c/37645ed2e950a2b1d9163d130d3a085fbed0e3231dd15b3c1c4d6a94e024/py_opc_ng-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6669bcca5278c9fb06d0da2c66aa8facee475522c6ee6e8750a5a9b87ba53285",
                "md5": "84090c428a9e8557bcbc223b4d1127ab",
                "sha256": "8f045892f0b46a29f8d6be0e3a8e07e6f73d67c22530fff8a4d1c47338faf115"
            },
            "downloads": -1,
            "filename": "py-opc-ng-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "84090c428a9e8557bcbc223b4d1127ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13189,
            "upload_time": "2023-01-30T18:40:44",
            "upload_time_iso_8601": "2023-01-30T18:40:44.786432Z",
            "url": "https://files.pythonhosted.org/packages/66/69/bcca5278c9fb06d0da2c66aa8facee475522c6ee6e8750a5a9b87ba53285/py-opc-ng-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-30 18:40:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "fargiolas",
    "github_project": "py-opc-ng",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-opc-ng"
}
        
Elapsed time: 0.03546s