Metadata-Version: 2.4
Name: eaps2000
Version: 1.2.0
Summary: Elektro-Automatik Series PS 2000 Python Controller
Project-URL: Homepage, https://github.com/KozhinovAlexander/eaps2000
Project-URL: Documentation, https://github.com/KozhinovAlexander/eaps2000/blob/main/README.md
Author-email: Alexander Kozhinov <ak.alexander.kozhinov@gmail.com>
License-Expression: Apache-2.0
Keywords: ds-power-supply,ea-ps-2042-06b,ea-ps-2042-10b,ea-ps-2042-20b,ea-ps-2084-03b,ea-ps-2084-05b,ea-ps-2342-06b,ea-ps-2342-10b,ea-ps-2384-05b,psu,psu-controller,pypi-package,python-psu-controller,series-ps-2000-b
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python
Requires-Python: >=3.8
Requires-Dist: pyserial>=3.5
Provides-Extra: dev
Requires-Dist: flake8>=7.1.2; extra == 'dev'
Requires-Dist: pytest-flake8>=1.3.0; extra == 'dev'
Requires-Dist: pytest>=6.2.2; extra == 'dev'
Requires-Dist: versioningit>=3.1.2; extra == 'dev'
Description-Content-Type: text/markdown

- [eaps2000 - PS 2000B Series PSU Python Control Unit](#eaps2000---ps-2000b-series-psu-python-control-unit)
  - [Installing the package](#installing-the-package)
  - [Getting Started](#getting-started)
    - [Setup Linux Host](#setup-linux-host)
    - [Using the CLI Interface](#using-the-cli-interface)
  - [Running Tests](#running-tests)
  - [Building the Project](#building-the-project)
  - [Documentation from the Manufacturer](#documentation-from-the-manufacturer)
    - [Object List](#object-list)
- [Debugging the System](#debugging-the-system)


# eaps2000 - PS 2000B Series PSU Python Control Unit

The `eaps2000` is a Python module for [Elektro-Automatik PS 2000B Series][_ps_2kb_url_] PSU control.

This software implements the following functionality:

- Reading out device information (serial number, model etc.)
- Setting over-voltage and over-current protection
- Setting voltage and current for an output
- Controlling the output stage on/off
- Acknowledging alarms

## Installing the package

Install the project from PyPi or [build](#building-the-project) it first.

```bash
pip install eaps2000
```

## Getting Started

### Setup Linux Host

Check permissions on `/dev/ttyACM0`

```bash
ls -l /dev/ttyACM0
```

Add user to `dialout` group:

```bash
sudo usermod -aG dialout $USER
# if your distro uses uucp instead:
# sudo usermod -aG uucp $USER
```

Verify your groups:

```bash
groups
```

Make sure dialout (or uucp) is listed.

Close all other programs using `/dev/ttyACM0`:

```bash
lsof /dev/ttyACM0
```

Reboot your machine.

### Using the CLI Interface

```bash

# Showing help
eaps2000 --help

# Show device info and current state (use /dev/ttyACM0 for Linux-based systems)
eaps2000 -p COM123 --info

# Set output voltage to 3.3V, current to 1.3A, output off:
eaps2000 -p COM123 -V 3.5 -I 1.3 --off

# Set output voltage to 3.3V, current to 1.3A, output on:
# CAUTION: This command will apply power to the output!
eaps2000 -p COM123 -V 3.5 -I 1.3 --on
```

**NOTE:** On Linux, use a device path such as `/dev/ttyACM0` instead of `COM123`.

Using Python interface:

```python
from eaps2000 import eaps2k

port = 'COM123'  # use /dev/ttyACM0 for Linux-based systems
with eaps2k(port) as ps:
    # Prepare config:
    cfg = eaps2k.get_config_template()
    cfg['ACK'] = True  # acknowledge alarms if any
    cfg['OVP'] = 5.0   # over-voltage-protection value
    cfg['OCP'] = 0.5   # over-current-protection value
    cfg['Iset'] = 0.1  # current to be set
    cfg['Vset'] = 3.3  # voltage to be set

    # Turn off the output stage:
    ps.set_output_state(False)

    # Apply configuration:
    ps.configure(cfg)

    # Turn on the output stage:
    # ATTENTION: The power will be applied to your probe here!
    # ps.set_output_state(True)

    # Show information:
    ps.print_info()
```

## Running Tests

Install development dependencies first:

```bash
pip install -e ".[dev]"
```

Run unit tests:

```bash
pytest
```

Run tests together with flake8 checks (same mode as CI):

```bash
pytest --flake8
```

Run hardware tests (requires a connected PSU):

```bash
EAPS2000_RUN_HW_TESTS=1 \
EAPS2000_TEST_PORT=/dev/ttyACM0 \
pytest -m hardware
```

Run interactive hardware tests:

```bash
EAPS2000_RUN_HW_TESTS=1 \
EAPS2000_TEST_PORT=/dev/ttyACM0 \
EAPS2000_HW_INTERACTIVE_CONFIRM=1 \
pytest -m hardware_interactive -s
```

## Building the Project

The project is built with [`hatchling`][_hatchling_home_]

```bash
pip install hatchling && flake8 . -v && hatchling build && pytest --flake8
```

Installing a freshly built project can be done by running:

```bash
pip install ./dist/eaps2000-*.whl --upgrade --force-reinstall
```

## Documentation from the Manufacturer

The manufacturer `EA ELEKTRO-AUTOMATIK GMBH & CO. KG` provides an overview of all
available `PS 2000 B Series` models in the shop [Serie PS 2000 B 100 bis 332 W][_ps_2kb_url_]
on its German web page.

The [Programming_Guide_PS2000B_TFT][_ps2kb_programming_guide_] gives an overview of
the protocol implemented. It also describes voltage/current conversions necessary for the
communication.

### Object List

Additional document `object_list_ps2000b_de_en.pdf` mentioned in
[Programming_Guide_PS2000B_TFT][_ps2kb_programming_guide_] (or [here][_ps2kb_programming_guide_alt0_] and [here][_ps2kb_programming_guide_alt1_]) gives an overview of control commands.
Each object in the list is basically a get/set command to control the PSU.

The table below lists objects in one place:

| Object | Description                | Access | Data type | Data length in Bytes | Mask for type 'char' | Data | Example or further description |
|--------|----------------------------|--------|-----------|----------------------|----------------------|------|--------------------------------|
| 0  | Device type                   | ro | string | 16 | | | PS2042-06B + EOL (EOL= End of Line 0x00) |
| 1  | Device serial no.             | ro | string | 16 | | | 1034440002 + EOL |
| 2  | Nominal voltage               | ro | float  | 4  | | | Unom = 42.0 (Floating point number IEEE754 Standard) |
| 3  | Nominal current               | ro | float  | 4  | | | Inom = 6.0 (Floating point number IEEE754 Standard)|
| 4  | Nominal power                 | ro | float  | 4  | | | Pnom = 100.0 (Floating point number IEEE754 Standard) |
| 6  | Device article no.            | ro | string | 16 | | | 39200112 + EOL |
| 8  | Manufacturer                  | ro | string | 16 | | | Manufacturer's name + EOL |
| 9  | Software version              | ro | string | 16 | | | V2.01 09.08.06 + EOL |
| 19 | Device class                  | ro | int    | 2  | | | 0x0010 = PS 2000 B Single, 0x0018 = PS 2000 B Triple |
| 38 | OVP threshold                 | rw | int    | 2  | | | Overvoltage set value 0-110% of Unom * 256 |
| 39 | OCP threshold                 | rw | int    | 2  | | | Overcurrent set value 0-110% of Inom * 256 |
| 50 | Set value U                   | rw | int    | 2  | | | Set value of voltage 0-100% of Unom * 256 |
| 51 | Set value I                   | rw | int    | 2  | | | Set value of current 0-100% of Inom * 256 |
| 54 | Power supply control          | rw | char   | 2  | 0x01<br>0x01<br>0x0A<br>0x10<br>0x10<br>0xF0<br>0xF0 | 0x01<br>0x00<br>0x0A<br>0x10<br>0x00<br>0xF0<br>0xE0 | <li>Switch power output on<br><li>Switch power output off<br><li>Acknowledge alarms<br><li>Switch to remote control<br><li>Switch to manual control<br><li>Tracking on<br><li>Tracking off |
| 71 | Status + Actual values        | ro | int    | 6  | | <li>Byte 0:<br>Bits 1+0:<br>Byte 1:<br>Bit 0:<br><li>Bits 2+1:<br>Bit 3:<br>Bit 4:<br>Bit 5:<br>Bit 6:<br>Bit 7:<br><li>Word 1:<br><li>Word 2: | <li>Query device state<br>00=free access; 01=Remote<br><br>1=Output on<br><li>Controller state: 00=CV, 10=CC<br>1=Tracking active**<br>1=OVP active<br>1=OCP active<br>1=OPP active<br>1=OTP active<br><li>Actual voltage (% of Unom * 256)<br><li>Actual current (% of Inom * 256) |
| 72 | Status + Momentary set values | ro | int    | 6  | | <li>Byte 0:<br>Bits 1+0:<br>Byte 1:<br>Bit 0:<br><li>Bits 2+1:<br>Bit 3:<br>Bit 4:<br>Bit 5:<br>Bit 6:<br>Bit 7:<br><li>Word 1:<br><li>Word 2: | <li>Query device state<br>00=free access; 01=Remote<br><br>1=Output on<br><li>Controller state: 00=CV; 10=CC<br>1=Tracking active**<br>1=OVP active<br>1=OCP active<br>1=OPP active<br>1=OTP active<br><li>Set value of voltage (% of Unom * 256)<br><li>Set value of current (% of Inom * 256) |

** PS 2000 B Triple only

# Debugging the System

I very handy CLI option to see messages transfered on the bus is `-vvv`.

The command will show all the bytes transfered to and from the device.

```bash
eaps2000 -p /dev/ttyACM0 --info -vvv
```

[_ps_2kb_url_]: https://elektroautomatik.com/shop/de/produkte/programmierbare-dc-laborstromversorgungen/dc-laborstromversorgungen/serie-ps-2000-b-br-100-bis-332-w/
[_ps2kb_programming_guide_]: https://elektroautomatik.com/shop/media/archive/f1/49/71/Programming_Guide_PS2000B_TFT.zip
[_ps2kb_programming_guide_alt0_]: https://wiki.cuvoodoo.info/lib/exe/fetch.php?media=ea-ps_2084-03b:ps2000b_programming.pdf
[_ps2kb_programming_guide_alt1_]: https://wiki.fablab.sorbonne-universite.fr/BookStack/attachments/1542&ved=2ahUKEwjUrbiZxpuUAxWl-QIHHb9cMBgQFnoECB0QAQ&usg=AOvVaw08f6liGdzKGvGxK9XNQWwb
[_hatchling_home_]: https://hatch.pypa.io/1.9/
