Coder Social home page Coder Social logo

lobis / hvps Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 289 KB

A Python package for controlling high voltage power supplies (HVPS) over serial port. Supports CAEN and iseg power supplies.

Home Page: https://github.com/lobis/hvps

License: BSD 3-Clause "New" or "Revised" License

Python 95.94% JavaScript 2.13% HTML 1.93%
caen high-voltage power-supply pyserial python serial-communication iseg

hvps's Introduction

All Contributors

PyPI version node.js bindings node-red node

PyPI downloads Python Version

Build and Test Upload Python Package to PyPI and nodejs bindings to npm

What is this? ๐Ÿค”

This is a Python package for controlling high voltage power supplies (HVPS) over serial port. The aim is to provide a unified pythonic interface for different HVPS models.

Along with the Python package, a minimal set of bindings for Node.js is also provided. A nodered node is also available. They both rely on the Python package to be installed in order to work.

Currently only CAEN and iseg brands are supported.

Installation โš™๏ธ

Installation via pip is supported. To install the latest published version, run:

pip install hvps

To install the package from source, including development dependencies, clone the repository and run:

pip install .[dev]

Usage ๐Ÿ‘จโ€๐Ÿ’ป

There is a hierarchy of objects that represent the HVPS and its components:

  • HVPS: represents the HVPS itself and handles the connection to the serial port. The classes Caen and Iseg are available for the respective brands.
  • Module: represents a module of the HVPS. Some HVPS support multiple modules over the same connection
  • Channel: represents a channel of the HVPS

Connection

from hvps import Caen, Iseg
import logging

# connection interface is common to all HVPS
# if no serial port is specified, the first available port will be used
# if no baudrate is specified, the default baudrate will be used
# if logging_level is specified, the logger will be configured accordingly
with Caen(port="/dev/ttyUSB0", baudrate=115200, logging_level=logging.DEBUG) as hvps:
    # using context manager (with) is recommended, but not required.
    # If not used, the connection must be opened and closed manually (hvps.open() and hvps.close())
    # connection settings can be accessed
    print(f"port: {hvps.port}")
    print(f"baudrate: {hvps.baudrate}")

Module

from hvps import Caen

# default connection settings
with Caen() as caen:
    module = caen.module()  # get the first module (module 0)
    # if multiple modules are present, they can be accessed by index e.g. caen.module(1)

    # get the module's name
    print(f"module name: {module.name}")

Channel

from hvps import Caen

with Caen() as caen:
    module = caen.module(0)

    print(f"number of channels: {module.number_of_channels}")

    channel = module.channel(2)  # get channel number 2

    # get monitoring parameters
    print(f"vmon: {channel.vmon}")
    print(f"vset: {channel.vset}")

    # set values (remote mode must be enabled)
    # turn on channel
    channel.turn_on()

    channel.vset = 300.0  # 300 V

CLI ๐Ÿ–ฅ๏ธ

A CLI is provided to interact with the HVPS from the command line.

TODO @AlonsoDRDLV

Show available serial ports

python -m hvps --ports

Output: command output

Disclaimer โš ๏ธ

The development of this package is mostly based on documentation with access to only a few models of HVPS.

If you use this package, it is very possible you find a bug or some oversight. You are encouraged to make a pull request or to create an issue to report a bug, to request additional features or to suggest improvements.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Luis Antonio Obis Aparicio
Luis Antonio Obis Aparicio

๐Ÿ’ป
AlonsoDRDLV
AlonsoDRDLV

๐Ÿ’ป
jherkenhoff
jherkenhoff

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

hvps's People

Contributors

allcontributors[bot] avatar alonsodrdlv avatar jherkenhoff avatar lobis avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hvps's Issues

Serial port not being closed properly

Currently the serial port is not being closed properly in some instances which can lead to errors (not enough permissions). We should use python context manager to handle this.

Javascript (node.js) bindings

It would be useful to be able to call this library from node.js in order to integrate it in nodered.

Instead of rewritting the library in javascript, we could create bindings for javascript (nodejs).

The details need to be defined, I have done minimal research and it's not straightforward to create javascript bindings for python code but I think we can just use the python-shell javascript library to call this python library directly and it should work okay, since we do not care about performance. It will have to make a new connection each time it's called but this should be OK.

We should also create an npm package to allow install of the bindings, I don't think (at this time) it makes sense to publish it into a repository such as npm as it would not work without the python counter-part.

Support multiple high voltage power supply brands

Initially this project was born to interface with CAEN power supplies but we currently have the need to also interface with ISEG power supplies.

Since both PSU support communication via serial commands (over usb connection) I think it makes sense to evolve this library into supporting multiple brands of PSU, since there would be a good portion of shared code.

  • Rename library and repository to new name: hvcontrol?
  • Refactor current CAEN code to be generic
  • Implement basic ISEG interface code
  • Publish new package to PyPI

Implement remaining methods for CAEN

Only the commonly used methods are implemented (vmon, vset...). All the commands exist in the codebase but they are not implemented as properties yet.

nodejs bindings - pass cli options to python

When invoking the nodejs bindings via the CLI, options should be passed to the python module, except some specific options to the javascript bindings such as --python (to specify the python installation).

Create parent class for top level PS connector

Create class HVPS which defines common code to connect to serial port etc.

Child classes CAEN and ISEG will inherit from this class and implement specific methods (such as module addressing in caen).

Make communication thread safe

While using this library in the context of an EPICS server (using the p4p python library), which is inherently multi-threaded, I encountered issues while multiple threads tried to communicated with the device.

For example, wrapping the serial.write and serial.readline functions together in a threading.Lock would avoid any possible race conditions by making sure that no other thread can take over the serial bus during a "transaction".

What do you think about this?
The problem would be: Where to store the threading.Lock?

Ramp down parameter not working

When trying to set the ramp down speed of a CAEN R803x channel, it responds with a command error.
From the manual I see that the command should be RDWN, while in the sourc it is RDW:

"RDW": "VAL:XXX Set RAMP DOWN value",

Attached is a screenshot from the R803x manual:
Screenshot from 2023-10-30 14-23-20

Is the RDW command in the source code a typo, or are there actually devices that use this command? If so, could I maybe simply add the RDWN command to the list?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.