
# Hantek Power Supply Controller
<img src="https://github.com/builder555/hantek-controller/blob/master/psu.jpg?raw=true" align="right" style="float:right; height: 200px">
This is an interface to the serial port on [Hantek HDP1160V4S](http://www.hantek.com/products/detail/18193) power supply. It should work with other HDP10000-series power supplies. [buy](https://s.click.aliexpress.com/e/_DCkHtB1)
### ❗**ATTENTION**❗
<mark>
USING THIS CODE MAY DAMAGE YOUR POWER SUPPLY OR CONNECTED DEVICES. USE AT YOUR OWN RISK.
</mark>
###
To communicate with the PSU I am using [USB-to-RS232](https://s.click.aliexpress.com/e/_DCOVD2J) adapter - does not require any drivers on debian linux.
<br clear="both"/>
## Installation
`pip install hantekpsu`
## Usage
```python
from hantekpsu import PSU
p = PSU(port='/dev/ttyUSB0', baudrate=2400)
```
## Methods
| Method | Description | Return Type |
| ------ | ----------- | ----------- |
| `turn_on()` | Turns on the power supply unit. | None |
| `turn_off()` | Turns off the power supply unit. | None |
| `ocp_on()` | Enables Over Current Protection (OCP). | None |
| `ocp_off()` | Disables Over Current Protection (OCP). | None |
| `ovp_on()` | Enables Over Voltage Protection (OVP). | None |
| `ovp_off()` | Disables Over Voltage Protection (OVP). | None |
| `get_model()` | Gets the model of the PSU. | `str` |
| `get_active_voltage()` | Gets the active output voltage of the PSU in volts. | `float` |
| `get_active_current()` | Gets the active output current of the PSU in milliamps. | `int` |
| `get_voltage_limit()` | Gets the voltage limit setting of the PSU in volts. | `float` |
| `get_current_limit()` | Gets the current limit setting of the PSU in milliamps. | `int` |
| `get_on_off_status()` | Returns the on/off status of the PSU. | `bool` |
| `set_output_voltage(v: float)` | Sets the output voltage of the PSU in volts. | None |
| `set_output_current(mA: int)` | Sets the output current of the PSU in milliamps. | None |
| `set_ovp_limit(v: float)` | Sets the Over Voltage Protection (OVP) limit in volts. | None |
| `set_ocp_limit(mA: int)` | Sets the Over Current Protection (OCP) limit in milliamps. | None |
## Examples
Set voltage to 12V and turn on the power supply:
```python
>>> from hantekpsu import PSU
>>> p = PSU()
>>> p.set_output_voltage(12.0)
>>> p.turn_on()
```
## Development
### Requirements
* python 3.10+
* poetry
Ensure the device is connected. If using usb-to-rs232 adapter, run `lsusb`:
```bash
$ lsusb
Bus 001 Device 012: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
```
You should also see something similar to `/dev/ttyUSB0` in the `/dev` folder.
To figure out which device it is, you can run `ls /dev` before plugging in the adapter and after and compare the differences.
### Installation
```bash
git clone https://github.com/builder555/hantek-controller
cd hantek-controller
poetry config virtualenvs.in-project true --local
poetry install
```
### Unit Tests
When adding new features or modifying existing ones, make sure you add unit tests and run them:
```bash
$ poetry run pytest -v
test_psu.py::test_get_model_number PASSED [ 6%]
test_psu.py::test_get_active_voltage PASSED [ 12%]
test_psu.py::test_get_active_current_in_milliamps PASSED [ 18%]
test_psu.py::test_get_voltage_limit PASSED [ 25%]
test_psu.py::test_get_current_limit_in_milliamps PASSED [ 31%]
test_psu.py::test_get_on_off_status PASSED [ 37%]
test_psu.py::test_turn_on PASSED [ 43%]
test_psu.py::test_turn_off PASSED [ 50%]
test_psu.py::test_ocp_on PASSED [ 56%]
test_psu.py::test_ocp_off PASSED [ 62%]
test_psu.py::test_ovp_on PASSED [ 68%]
test_psu.py::test_ovp_off PASSED [ 75%]
test_psu.py::test_set_voltage PASSED [ 81%]
test_psu.py::test_set_current PASSED [ 87%]
test_psu.py::test_set_ovp PASSED [ 93%]
test_psu.py::test_set_ocp PASSED [100%]
========================= 16 passed in 0.03s =========================
```
You can also run pytest-watch while developing to run tests automatically on save:
```bash
poetry run ptw --runner 'pytest -v'
```
Raw data
{
"_id": null,
"home_page": "https://github.com/builder555/hantek-controller",
"name": "hantekpsu",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "builder555",
"author_email": "85308587+builder555@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/4e/de/fa354c9adb9358bd1fef1fb67b36e590e6053519b75474843036478b2778/hantekpsu-1.0.3.tar.gz",
"platform": null,
"description": "\n\n# Hantek Power Supply Controller\n\n<img src=\"https://github.com/builder555/hantek-controller/blob/master/psu.jpg?raw=true\" align=\"right\" style=\"float:right; height: 200px\">\n\nThis is an interface to the serial port on [Hantek HDP1160V4S](http://www.hantek.com/products/detail/18193) power supply. It should work with other HDP10000-series power supplies. [buy](https://s.click.aliexpress.com/e/_DCkHtB1)\n\n\n### \u2757**ATTENTION**\u2757\n<mark>\nUSING THIS CODE MAY DAMAGE YOUR POWER SUPPLY OR CONNECTED DEVICES. USE AT YOUR OWN RISK.\n</mark>\n\n###\n\nTo communicate with the PSU I am using [USB-to-RS232](https://s.click.aliexpress.com/e/_DCOVD2J) adapter - does not require any drivers on debian linux.\n\n<br clear=\"both\"/>\n\n## Installation\n\n`pip install hantekpsu`\n\n## Usage\n\n```python\nfrom hantekpsu import PSU\np = PSU(port='/dev/ttyUSB0', baudrate=2400)\n```\n\n## Methods\n| Method | Description | Return Type |\n| ------ | ----------- | ----------- |\n| `turn_on()` | Turns on the power supply unit. | None |\n| `turn_off()` | Turns off the power supply unit. | None |\n| `ocp_on()` | Enables Over Current Protection (OCP). | None |\n| `ocp_off()` | Disables Over Current Protection (OCP). | None |\n| `ovp_on()` | Enables Over Voltage Protection (OVP). | None |\n| `ovp_off()` | Disables Over Voltage Protection (OVP). | None |\n| `get_model()` | Gets the model of the PSU. | `str` |\n| `get_active_voltage()` | Gets the active output voltage of the PSU in volts. | `float` |\n| `get_active_current()` | Gets the active output current of the PSU in milliamps. | `int` |\n| `get_voltage_limit()` | Gets the voltage limit setting of the PSU in volts. | `float` |\n| `get_current_limit()` | Gets the current limit setting of the PSU in milliamps. | `int` |\n| `get_on_off_status()` | Returns the on/off status of the PSU. | `bool` |\n| `set_output_voltage(v: float)` | Sets the output voltage of the PSU in volts. | None |\n| `set_output_current(mA: int)` | Sets the output current of the PSU in milliamps. | None |\n| `set_ovp_limit(v: float)` | Sets the Over Voltage Protection (OVP) limit in volts. | None |\n| `set_ocp_limit(mA: int)` | Sets the Over Current Protection (OCP) limit in milliamps. | None |\n\n## Examples\n\nSet voltage to 12V and turn on the power supply:\n\n```python\n>>> from hantekpsu import PSU\n>>> p = PSU()\n>>> p.set_output_voltage(12.0)\n>>> p.turn_on()\n```\n\n## Development\n\n### Requirements\n\n* python 3.10+\n* poetry\n\nEnsure the device is connected. If using usb-to-rs232 adapter, run `lsusb`:\n\n```bash\n$ lsusb\nBus 001 Device 012: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC\n```\n\nYou should also see something similar to `/dev/ttyUSB0` in the `/dev` folder.\n\nTo figure out which device it is, you can run `ls /dev` before plugging in the adapter and after and compare the differences.\n\n### Installation\n\n```bash\ngit clone https://github.com/builder555/hantek-controller\ncd hantek-controller\npoetry config virtualenvs.in-project true --local\npoetry install\n```\n\n### Unit Tests\n\nWhen adding new features or modifying existing ones, make sure you add unit tests and run them:\n\n```bash\n$ poetry run pytest -v\n\ntest_psu.py::test_get_model_number PASSED [ 6%]\ntest_psu.py::test_get_active_voltage PASSED [ 12%]\ntest_psu.py::test_get_active_current_in_milliamps PASSED [ 18%]\ntest_psu.py::test_get_voltage_limit PASSED [ 25%]\ntest_psu.py::test_get_current_limit_in_milliamps PASSED [ 31%]\ntest_psu.py::test_get_on_off_status PASSED [ 37%]\ntest_psu.py::test_turn_on PASSED [ 43%]\ntest_psu.py::test_turn_off PASSED [ 50%]\ntest_psu.py::test_ocp_on PASSED [ 56%]\ntest_psu.py::test_ocp_off PASSED [ 62%]\ntest_psu.py::test_ovp_on PASSED [ 68%]\ntest_psu.py::test_ovp_off PASSED [ 75%]\ntest_psu.py::test_set_voltage PASSED [ 81%]\ntest_psu.py::test_set_current PASSED [ 87%]\ntest_psu.py::test_set_ovp PASSED [ 93%]\ntest_psu.py::test_set_ocp PASSED [100%]\n\n========================= 16 passed in 0.03s =========================\n```\n\nYou can also run pytest-watch while developing to run tests automatically on save:\n\n```bash\npoetry run ptw --runner 'pytest -v'\n```\n\n",
"bugtrack_url": null,
"license": "MIT-0",
"summary": "Python interface for Hantek bench power supply",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/builder555/hantek-controller"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f5e0f781d8a28d7e5dd5cf00e4fdfb10b525a13674e034d12f99339bfc714c9c",
"md5": "366673f98f37e684041a77c35f494561",
"sha256": "a31b4e26fa2a9e9222fa8d6d8018608bb22535d8a43923d960c213121baee019"
},
"downloads": -1,
"filename": "hantekpsu-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "366673f98f37e684041a77c35f494561",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 3849,
"upload_time": "2024-11-07T02:00:50",
"upload_time_iso_8601": "2024-11-07T02:00:50.421090Z",
"url": "https://files.pythonhosted.org/packages/f5/e0/f781d8a28d7e5dd5cf00e4fdfb10b525a13674e034d12f99339bfc714c9c/hantekpsu-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4edefa354c9adb9358bd1fef1fb67b36e590e6053519b75474843036478b2778",
"md5": "82799efb7c8b8986331610869e76d788",
"sha256": "f5c2257c294be02106827702607eacd0ee41ccd9af5dd9aa8951fdb1a2f45484"
},
"downloads": -1,
"filename": "hantekpsu-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "82799efb7c8b8986331610869e76d788",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 3466,
"upload_time": "2024-11-07T02:00:51",
"upload_time_iso_8601": "2024-11-07T02:00:51.557843Z",
"url": "https://files.pythonhosted.org/packages/4e/de/fa354c9adb9358bd1fef1fb67b36e590e6053519b75474843036478b2778/hantekpsu-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 02:00:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "builder555",
"github_project": "hantek-controller",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "hantekpsu"
}