Hantek Power Supply Controller
This is an interface to the serial port on Hantek HDP1160V4S power supply. It should work with other HDP10000-series power supplies. buy
❗ATTENTION❗
USING THIS CODE MAY DAMAGE YOUR POWER SUPPLY OR CONNECTED DEVICES. USE AT YOUR OWN RISK.To communicate with the PSU I am using USB-to-RS232 adapter - does not require any drivers on debian linux.
Installation
pip install hantekpsu
Usage
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:
>>> 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:
$ 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
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:
$ 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:
poetry run ptw --runner 'pytest -v'
Metadata
Release files for hantekpsu 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| hantekpsu-1.0.3.tar.gz | 3.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hantekpsu-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.3 kB
Release files / hantekpsu-1.0.3.tar.gz
| Download URL | hantekpsu-1.0.3.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5c2257c294be02106827702607eacd0ee41ccd9af5dd9aa8951fdb1a2f45484
|
|
BLAKE2b-256 checksum How to use checksums |
4edefa354c9adb9358bd1fef1fb67b36e590e6053519b75474843036478b2778
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2024.
Transparency logRelease files / hantekpsu-1.0.3-py3-none-any.whl
| Download URL | hantekpsu-1.0.3-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a31b4e26fa2a9e9222fa8d6d8018608bb22535d8a43923d960c213121baee019
|
|
BLAKE2b-256 checksum How to use checksums |
f5e0f781d8a28d7e5dd5cf00e4fdfb10b525a13674e034d12f99339bfc714c9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2024.
Transparency logSecurity for hantekpsu 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for hantekpsu-1.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.