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

Dev #9

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Docker-Image-Build-Publish
on:
push:
branches:
#- 'main'
- 'dev'
tags:
- 'v*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
-
name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
69 changes: 69 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
on:
pull_request:
branches: [ dev ]
#push:
# branches:
# - 'dev'
#push:
# branches : 'dev'

jobs:
build:
runs-on: ubuntu-latest
# for self-hosted:
# runs-on: [self-hosted, linux, X64]
strategy:
matrix:
python-version: [3.9.12]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: |
python3 -m pip install --upgrade pip
python3 -m pip --version
- name: Print environment
run: |
env
- name: Install dependencies
run: |
python3 -m pip install -U black
python3 -m pip install -r requirements/local.txt
python3 -m pip install -e .

- name: Docker-compose start mqtt
run: |
cd docker/tedd_caen_hvps
pwd
echo "---------------------"
ls
echo $HOME
docker-compose up -d
docker-compose ps -a
cd -
- name: Run black --check .
run: black --check . --exclude _actions
#- name: Test with pytest
# run: |
# cd unittests
# python3 -m pip install pytest-cov
# python3 -m pytest --cov=../ --cov-report=xml
# ls
#- name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# directory: ./unittests
# env_vars: OS,PYTHON
# fail_ci_if_error: true
# flags: unittests
# name: codecov-umbrella
# # path_to_write_report: ./coverage/codecov_report.txt
# verbose: true

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dist/
downloads/
eggs/
.eggs/
lib/
#lib/
lib64/
parts/
sdist/
Expand Down
47 changes: 18 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM --platform=linux/amd64 centos:centos7
FROM centos:centos7
#for Mac m1 -->
#FROM --platform=linux/amd64 centos:centos7

# Update packages and install tools

WORKDIR /usr/app
Expand All @@ -12,42 +15,28 @@ RUN yum install -y java-11-openjdk java-11-openjdk-devel
RUN yum install -y wget


#RUN apt-get update && apt-get install -y --no-install-recommends apt-utils

#WORKDIR /usr/local/lib
#COPY caenlib/CAENHVWrapper-6.3 ./CAENHVWrapper-6.3
#WORKDIR /usr/local/lib/CAENHVWrapper-6.3/
#RUN cd CAENHVWrapper-6.3/

WORKDIR /usr/app/caen_hvps/
COPY caen_hvps/hvps .

# install dependencies
COPY requirements ./requirements

RUN python3 -m pip install --no-cache-dir -r requirements/docker.txt

COPY caenlib ./caenlib
WORKDIR /usr/app/caenlib/
COPY caen_hvps/caenlib ./caenlib
WORKDIR /usr/app/caen_hvps/caenlib/
RUN tar -xzf CAENHVWrapper-6.3.tgz
RUN rm CAENHVWrapper-6.3.tgz

RUN unzip CAEN_HVPSS_ChannelsController.zip
RUN rm CAEN_HVPSS_ChannelsController.zip
WORKDIR /usr/app/caen_hvps/caenlib/CAENHVWrapper-6.3/
RUN ./install.sh && \
rm *.txt && \
rm -rf HVWrapperDemo/

WORKDIR /usr/app/caenlib/CAENHVWrapper-6.3/
RUN pwd && ls
#WORKDIR /usr/lib
#CMD pwd && ls
#RUN ldconfig -l libcaenhvwrapper.so.6.3
#RUN export LD_LIBRARY_PATH="/usr/lib"

RUN ./install.sh
RUN rm *.txt
RUN rm -rf HVWrapperDemo/
RUN pwd && ls
ENV LD_LIBRARY_PATH="/usr/lib"



WORKDIR /usr/lib
CMD pwd && ls
RUN ldconfig -l libcaenhvwrapper.so.6.3
RUN export LD_LIBRARY_PATH="/usr/lib"

WORKDIR /usr/app
COPY hvps ./hvps
WORKDIR /usr/app/hvps/
WORKDIR /usr/app/caen_hvps/
97 changes: 96 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,97 @@
# caen_hvps
integrate caen power supply to tracker dcs
integrate caen SY4527 power supply to tracker dcs
Interface to control CAEN power supplies using a python wrapper to the CAEN C API

## CAEN prerequisite
In order to use the CAEN power supplies it is necessary to install the CAEN HV Wrapper Library:

CAENHVWRAPPER https://www.caen.it/download/?filter=CAEN%20HV%20Wrapper%20Library
You need to signup to download.

CAEN HV Wrapper is a set of ANSI C functions which allows to control CAEN devices. It contains a generic software interface independent by the Power Supply models and by the communication path used to exchange data with them.

### caenlib
Detalied information can be found in CAENHVWrapper-6.3/CAENHVWrapperReadme.txt
To install the necessary libraries execute:

./install.sh

The installation copies and installs the library in /usr/lib, and installs it in the work directory.

### hvps
lib/caen.py : Contains CAEN controller class. Provide low level wrapper for CAEN's c-api via Python's cdll functionality and is accessed via hvps.py

lib/hvps.py : Contains a class of objects that represent all the channels for the HVPS and provides a nicer interface to the CAEN C-wrapper and should be used for all programatic iteractions with the power supply

hvps_ctrl.py : Main interface to the control software. Handles all user interactions

hvps.cfg : CAEN HV modules can be setup automatically using a configuration file.

* Global Section :
Should be defined
* max_bias_voltage
* max_ramp_rate : max_ramp_rate V/sec, probably want to keep this under <=50
* default_slot (Mandatory): slot number where the boards are located

* Power supply section : Contains Mandatory informations:
* Hostname or IP address
* username and password
* system_type : CAENHV_BOARD_TYPE (SY4527) for our case it should be 2
* link_type : CAENHV_LINK_TYPE if TCP/IP then it should be 0

* Channels section: All channels must start with CH_. should be defined the following info for each channel;
* channel_num (Mandatory)
* chanel enable/disable (Mandatory)
* max_bias_voltage
* ramp_rate

### Dockerfile
Create an image and Install all the necessary tools.

#### Build Docker image

docker build -t tedd_caen_hvps:centos7 .


##### To run the image as a container:

docker run -it --name=caen_hvps tedd_caen_hvps:centos7 bash


###### To run the python file inside the container:

1- To check the status of the specific channel e.g: channel 0 :

python3 hvps_ctrl.py --status --chan 0


You will see the following statement:

Could get the IP address for the hostname :%s 10.2.2.20
Initilizing HVPS...
DEBUG_INIT::::: admin admin b'10.2.2.20' 10.2.2.20 ds-hvps 2 0
Initialized Connection to : 10.2.2.20
communicating with HVPS, check SLOT # and Channel #, IP : b'10.2.2.20', ERROR code : 0x0
Slot: 4 | Channel Name: LV_1-0 | Channel#: 0 | V0Set : 5.0 | I0Set : 1.1 | RUpTime : 100.0 | RDwTime : 100.0 | Trip : 0.1 | UNVThr : 0.0 | OVVThr : 7.0 | VMon : 0.0 | VCon : 0.4 | IMon : 0.0 | Temp : 0.0 | Pw : 0.0 | TripInt : 0.0 | TripExt : 0.0 | ChToGroup : 0.0 | OnGrDel : 0.0 | Status : Off


2- Other parameters: V0Set / RumpDown / Rump Up / Trip / etc.:

--param V0Set:

python3 hvps_ctrl.py --action set_param --param V0Set --param_value 6 --chan 1

--param RDWn:

python3 hvps_ctrl.py --action set_param --param RDWn --param_value 40 --chan 0

--param RUp:

python3 hvps_ctrl.py --action set_param --param RUp --param_value 50 --chan 0


--param Trip:

python3 hvps_ctrl.py --action set_param --param Trip --param_value 0.5 --chan 0


File renamed without changes.
File renamed without changes.
Binary file added caen_hvps/caenlib/lib/CAENHVWrapper.jar
Binary file not shown.
Binary file added caen_hvps/caenlib/lib/JTattoo.jar
Binary file not shown.
30 changes: 30 additions & 0 deletions caen_hvps/hvps/hvps.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Global Section
#max_bias_voltage = 10
# max_ramp_rate V/sec, probably want to keep this under <=50
#max_ramp_rate = 5
default_slot = 9 #(slot4: LV channels/ slot9 :HV channels )
default_hvps = HVPS_SY4527

# All power supplies must start with HVPS_
[HVPS_SY4527]
device_name = SY4527
system_type = 2 #BOARD_TYPE: SY4527 = 2
link_type = 0 #TCP/IP
# This can be a hostname or an IP address
hostname = 192.168.1.210
# Leave username and password blank if your unit does not have these values
username = admin
password = admin

# All channels must start with CH_
[[CH_0]]
channel_num = 0
Enabled = True
#max_bias_voltage = 10
#ramp_rate = 5

[[CH_1]]
channel_num = 1
Enabled = True
#max_bias_voltage = 10
#ramp_rate = 5
Loading