Metadata-Version: 2.4
Name: serial-scale-bench
Version: 0.2.0
Summary: Python driver for RS-232/USB bench scales (Kern, Mettler-Toledo, etc.).
Project-URL: Homepage, https://github.com/MurineShiftWork/serial-scale-bench
Project-URL: Documentation, https://larsrollik.github.io/serial-scale-bench/
Project-URL: Issue Tracker, https://github.com/MurineShiftWork/serial-scale-bench/issues
Author-email: "Lars B. Rollik" <L.B.Rollik@protonmail.com>
License: BSD 3-Clause License
        
        Copyright (c) 2021, Lars B. Rollik
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: pyserial
Provides-Extra: api
Requires-Dist: fastapi; extra == 'api'
Requires-Dist: pydantic; extra == 'api'
Requires-Dist: uvicorn[standard]; extra == 'api'
Provides-Extra: dev
Requires-Dist: commitizen; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material; extra == 'docs'
Description-Content-Type: text/markdown

# serial-scale-bench

Python driver for RS-232/USB commercial bench scales (Kern, Mettler-Toledo, etc.).

Supports two ASCII response protocols:
- **Protocol 1** — multi-line header responses (`GS`, `NT`, `GT` prefixes); typical of
  Kern and similar label-printing scales
- **Protocol 2** — single float line; minimal scales and simpler firmware

Protocol is auto-detected on first connection. A FastAPI HTTP server is included for
running the scale as a networked service (e.g. LabWatch integration).

## Install

Base (serial only):

```bash
pip install serial-scale-bench
```

With HTTP API server:

```bash
pip install "serial-scale-bench[api]"
```

Or editable from this repo:

```bash
pip install -e .
```

## Usage

```python
from serial_scale_bench import SerialScale

scale = SerialScale(port="/dev/ttyUSB0", baudrate=9600)
scale.tare()
weight = scale.get_weight()   # float grams or None
scale.close()
```

### Auto-reconnect wrapper

```python
from serial_scale_bench import AutoReconnectSerialScale

scale = AutoReconnectSerialScale(port="/dev/ttyUSB0")
weight = scale.get_weight()   # reconnects automatically on error
```

## HTTP API server

Start a local REST server exposing the scale over HTTP:

```bash
python -m serial_scale_bench.entrypoint --device /dev/ttyUSB0 --port 8080 --scale-id bench1
```

Endpoints: `GET /weight`, `POST /tare`, `POST /zero`, `GET /status`, `GET /ping`.

## API reference

| Method | Description |
|---|---|
| `get_weight()` | Poll current weight (float or None) |
| `tare()` | Send tare command |
| `zero()` | Send zero command |
| `set_tare_value(value)` | Set absolute tare |
| `is_connected()` | True if serial port is open |
| `is_responsive()` | True if scale responds to ping |
| `close()` | Close serial connection |

## murineshiftwork integration

Planned: `BenchScaleAdapter` in `murineshiftwork.logic.scale`. Install with:

```bash
pip install "murineshiftwork[calibration]"
```
