Python implementation of the KCP (KERN Communications Protocol) protocol.
Project description
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()
[!NOTE] Stopping a stream does not close the device connection. You can continue to use the device for other commands after stopping a stream.
If you stop consuming the stream early, call
stop_stream()explicitly so the device exits streaming mode cleanly.
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())
[!NOTE] Use this advanced path only when you need custom transport behavior. For most use cases, the default
SauterFS220(port=...)constructor is sufficient and the recommended usage.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kcp_protocol-0.1.0.tar.gz.
File metadata
- Download URL: kcp_protocol-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cb6bec5e56efa3e16701ac65d98598007ebe19cfdcec30b90bb434398ac1188
|
|
| MD5 |
6a48b4d099301b73d6f8744e359e9df1
|
|
| BLAKE2b-256 |
39a165f1aaaa591bfddd1a51a627b887e760eaab4346bba69074c69e84c43bcc
|
File details
Details for the file kcp_protocol-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kcp_protocol-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
007144c7c58296dcaf889e9b3bee442ce528162feb7f7b5ac28466f4b734bdc5
|
|
| MD5 |
b1cf231e842d51ddb46984392f7c70fb
|
|
| BLAKE2b-256 |
1c3971ccc227099b497f85545bf86d27a36b9e5a5db5a68e0643c6647aebd710
|