Skip to content

Commit

Permalink
Merge pull request #5 from lobis/1-support-multiple-high-voltage-powe…
Browse files Browse the repository at this point in the history
…r-supply-brands

Support multiple power supply brands
  • Loading branch information
lobis authored Jun 19, 2023
2 parents f06381f + b127bff commit 2484a71
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 24 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# caenhv
# HVPS

[![PyPI version](https://badge.fury.io/py/caenhv.svg)](https://badge.fury.io/py/caenhv)
[![Build and Test](https://github.com/lobis/caen-hv/actions/workflows/build-test.yml/badge.svg)](https://github.com/lobis/caen-hv/actions/workflows/build-test.yml)
Expand All @@ -7,7 +7,8 @@

## 🤔 What is this?

This is an unofficial Python package to interface with CAEN high voltage power supplies over USB (RS232 protocol).
The goal of this Python package is to interface with different brands of high voltage power supplies in a uniform way.
Currently only CAEN and iseg brands are supported. Communication is performed via serial port (over USB).

## ⚠️ Disclaimer

Expand All @@ -26,7 +27,7 @@ Installation via `pip` is supported.
To install the latest [published version](https://github.com/lobis/lecroy-scope/releases), run:

```bash
pip install caenhv
pip install hvps
```

To install the package from source, including test dependencies, clone the repository and run:
Expand All @@ -38,7 +39,7 @@ pip install .[test]
## 👨‍💻 Usage

```python
from caenhv import CaenHV
from hvps import CaenHV

# automatically detect serial port and baudrate (can be manually set)
caen = CaenHV()
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"


[project]
name = "caenhv"
name = "hvps"
authors = [
{ name = "Luis Antonio Obis Aparicio", email = "[email protected]" },
]
Expand All @@ -30,9 +30,9 @@ test = [
]

[project.urls]
"Download" = "https://github.com/lobis/caen-hv/releases"
"Homepage" = "https://github.com/lobis/caen-hv"
"Bug Tracker" = "https://github.com/lobis/caen-hv/issues"
"Download" = "https://github.com/lobis/hvps/releases"
"Homepage" = "https://github.com/lobis/hvps"
"Bug Tracker" = "https://github.com/lobis/hvps/issues"

[tool.hatch.version]
path = "src/caenhv/version.py"
path = "src/hvps/version.py"
Empty file added src/__init__.py
Empty file.
1 change: 0 additions & 1 deletion src/caenhv/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion src/caenhv/devices/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions src/hvps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .devices import HVPS
Empty file added src/hvps/commands/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations
import re

from .module import _get_set_module_command, _get_mon_module_command
from src.hvps.commands.caen.module import _get_mon_module_command, _get_set_module_command
from src.hvps.commands.caen.channel import _get_mon_channel_command, _get_set_channel_command

import logging

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _get_mon_module_command(bd: int, parameter: str) -> bytes:
Generate a command string to monitor a specific module parameter.
Args:
bd (int): The board number.
bd (int): The board number. Must be in the range 0..31.
parameter (str): The parameter to monitor.
Returns:
Expand All @@ -34,6 +34,9 @@ def _get_mon_module_command(bd: int, parameter: str) -> bytes:
Raises:
ValueError: If the provided parameter is not valid.
"""
if not 0 <= bd <= 31:
raise ValueError(f"Invalid board number '{bd}'. Must be in the range 0..31.")

parameter = parameter.upper()
if parameter not in _mon_module_parameters:
valid_parameters = ", ".join(_mon_module_parameters.keys())
Expand Down
11 changes: 11 additions & 0 deletions src/hvps/commands/iseg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations
import re

from src.hvps.commands.iseg.channel import _get_set_channel_command, _get_mon_channel_command

import logging


def _parse_response(response: bytes) -> str:
# TODO: implement
pass
11 changes: 11 additions & 0 deletions src/hvps/commands/iseg/channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations


def _get_mon_channel_command(channel: int, parameter: str) -> bytes:
# TODO: implement
pass


def _get_set_channel_command(channel: int, parameter: str, value: str | int | float | None) -> bytes:
# TODO: implement
pass
1 change: 1 addition & 0 deletions src/hvps/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .hvps import HVPS
6 changes: 2 additions & 4 deletions src/caenhv/devices/channel.py → src/hvps/devices/channel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from functools import cached_property

import serial

from ..commands.channel import _get_set_channel_command, _get_mon_channel_command
from ..commands import _parse_response
from src.hvps.commands.caen.channel import _get_set_channel_command, _get_mon_channel_command
from src.hvps.commands.caen import _parse_response

from time import sleep

Expand Down
2 changes: 1 addition & 1 deletion src/caenhv/devices/caenhv.py → src/hvps/devices/hvps.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def detect_baudrate(port: str) -> int:
raise Exception("Could not detect baud rate")


class CaenHV:
class HVPS:
def __init__(
self,
baudrate: int | None = None,
Expand Down
6 changes: 3 additions & 3 deletions src/caenhv/devices/module.py → src/hvps/devices/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import serial

from ..commands.module import _get_mon_module_command, _get_set_module_command
from ..commands import _parse_response
from .channel import Channel
from src.hvps.commands.caen.module import _get_mon_module_command
from src.hvps.commands.caen import _parse_response
from src.hvps.devices.channel import Channel


class Module:
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions tests/test_caen.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import pytest

from caenhv import CaenHV
from hvps import HVPS


# find a way to only run these tests if a serial port connection exists

@pytest.mark.skip(reason="Needs fixing")
def test_caen_no_connection():
with pytest.raises(Exception):
# no ports available
caen = CaenHV(port=None, connect=False)
caen = HVPS(port=None, connect=False)

with pytest.raises(Exception):
# no ports available or cannot connect
caen = CaenHV(connect=True)
caen = HVPS(connect=True)
31 changes: 31 additions & 0 deletions tests/test_caen_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from hvps.commands.caen import _parse_response, _get_set_module_command, _get_mon_module_command


def test_caen_module_get_commands():
with pytest.raises(ValueError):
# invalid parameter name
_get_mon_module_command(0, "TEST")

with pytest.raises(ValueError):
# invalid board number
_get_mon_module_command(-1, "BDNAME")

command = _get_mon_module_command(0, "BDNAME")


def test_caen_module_set_commands():
pass


def test_caen_channel_get_commands():
pass


def test_caen_channel_set_commands():
pass


def test_caen_parse_response():
pass
1 change: 1 addition & 0 deletions tests/test_iseg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import pytest
21 changes: 21 additions & 0 deletions tests/test_iseg_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


def test_iseg_module_get_commands():
pass


def test_iseg_module_set_commands():
pass


def test_iseg_channel_get_commands():
pass


def test_iseg_channel_set_commands():
pass


def test_iseg_parse_response():
pass

0 comments on commit 2484a71

Please sign in to comment.