kcp-protocol
Python client for devices that use the KERN Communications Protocol (KCP), with current support focused on the Sauter FS2-20.
Status
This project is in an early public release stage and currently targets a subset of KCP commands needed for the Sauter FS2-20 workflow.
Features
- Serial communication over
pyserial - KCP frame parsing and command handling
- High-level
SauterFS220device wrapper - Immediate value reads
- Continuous streaming reads
- Device information and serial number queries
- Battery status query
- Zero command support
Requirements
- Python 3.11 or newer
- A serial connection to a compatible KCP-enabled device
- For
SauterFS220, a device that supports the required commands used during initialization and measurement
Installation
Install from PyPI:
uv add kcp-protocol
# or
pip install kcp-protocol
Quick Start
Basic Usage
from kcp_protocol import SauterFS220
# Initialize the device (replace with your serial port)
with SauterFS220(port="COM3") as device:
# Device information
print("Device Info:", device.get_device_information())
# Serial number
print("Serial Number:", device.get_serial_number())
# Battery status
print("Battery Status:", device.get_battery_status())
# Read an immediate value
value = device.read_value()
print("Current value:", value)
# Read a measurement
measurement = device.read_measurement()
print("Measurement:", measurement.value, measurement.unit)
Streaming data
from kcp_protocol import SauterFS220
with SauterFS220(port="COM3") as device:
for value in device.stream_values(interval_ms=100):
print(value)
# or another stopping condition, e.g. based on user input or a timer
if should_stop():
device.stop_stream()
# or in case you need a measurement stream:
for measurement in device.stream_measurements(interval_ms=100):
print(measurement.value, measurement.unit)
if should_stop():
device.stop_stream()
Advanced Transport Configuration
If you need to customize transport parameters (e.g. timeouts) or implement a custom transport, you can use KCPSerialTransport directly or subclass it.
from kcp_protocol import KCPSerialTransport, SauterFS220
transport = KCPSerialTransport(
"COM3",
read_poll_timeout=0.1,
write_timeout=1.0,
)
with SauterFS220(transport=transport) as device:
print(device.read_value())
Public API
The main public entry points are:
SauterFS220for the device-specific high-level interfaceKCPSerialTransportfor serial transport accessKCPTransportfor custom or test transports
The main high-level methods on SauterFS220 are:
read_value()read_measurement()stream_values(interval_ms: int | None = None)stream_measurements(interval_ms: int | None = None)stop_stream()get_device_information()get_serial_number()get_battery_status()
Example
A Windows interactive example is available in examples/read_fs220.py.
Notes
- Supported parsed measurement units are currently
gandN. stop_stream()is explicit so callers can stop streaming and continue using the same device connection.get_battery_status()currently returns either a parsed integer percentage or the raw line when parsing fails.
Contributing
Contributions are welcome! Please open issues for bug reports or feature requests, and submit pull requests for any improvements or additions.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for kcp-protocol 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kcp_protocol-0.1.0.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kcp_protocol-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / kcp_protocol-0.1.0.tar.gz
| Download URL | kcp_protocol-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cb6bec5e56efa3e16701ac65d98598007ebe19cfdcec30b90bb434398ac1188
|
|
BLAKE2b-256 checksum How to use checksums |
39a165f1aaaa591bfddd1a51a627b887e760eaab4346bba69074c69e84c43bcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / kcp_protocol-0.1.0-py3-none-any.whl
| Download URL | kcp_protocol-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
007144c7c58296dcaf889e9b3bee442ce528162feb7f7b5ac28466f4b734bdc5
|
|
BLAKE2b-256 checksum How to use checksums |
1c3971ccc227099b497f85545bf86d27a36b9e5a5db5a68e0643c6647aebd710
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|