Files
scalesApp/serial_bridge
gitea 5a8527e96e Add multi-protocol scale support and admin COM monitor
The bridge becomes pure transport: it opens the port, writes a poll
string it is given at runtime, and streams raw lines. Protocol
definitions live in Django and parsing happens in the browser, so a new
scale type never means a new binary on the station PCs. The poll loop
stays in the bridge because a browser cannot be the heartbeat - hidden
tabs get throttled and a closed tab would stop the scale.

Every payload now carries a hex field. Toledo Continuous sends STX and
bit-packed status, which UTF-8 decoding silently corrupts. Fixed-column
protocols need the opposite care: a space can mean balanced, so the
trailing whitespace must survive.

Parsers for the simulator, fixed-column, Toledo Continuous and SICS
return an explicit error rather than a guess on a frame that does not
match, since a silently wrong weight on a weighbridge is worse than no
weight. Toledo and SICS are written from documented structure and have
not been validated against real hardware.

The admin monitor shows the raw stream as text and hex, sends one-off
probe commands, and builds fixed-column protocols against captured
lines. Spaces render as middots because in some protocols a space is
the stability flag.

The test writer now simulates a weighing cycle - idle, ramp, balanced,
drop - alternating empty and loaded trucks, quantised to the 20kg and
50kg divisions real truck scales use.

Bridge logging rotates and per-reading lines drop to DEBUG; the old
config had grown two log files totalling 368MB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 18:58:00 +03:00
..
2026-02-21 19:53:04 +02:00

Serial Bridge - COM Port Reader

This is the serial port reading application that runs as a system tray service.

Features

  • ✅ Reads data from COM ports
  • ✅ Runs in system tray (no console window)
  • ✅ Automatically posts data to Django backend
  • ✅ Retry logic for failed posts
  • ✅ Backend health checks
  • ✅ Configurable via environment variables
  • ✅ Can be packaged as a Windows .exe

Setup

  1. Install Python dependencies:

    pip install -r requirements.txt
    
  2. Configure environment:

    copy .env.example .env
    # Edit .env with your settings
    
  3. Run the application:

    python app.py
    

Building as EXE

To create a standalone Windows executable:

pip install pyinstaller
pyinstaller serial_bridge.spec

The executable will be created in the dist\ScalesApp\ folder.

Configuration

Edit .env to configure:

  • COM_PORT: COM port to read from (default: COM1)
  • BAUD_RATE: Serial port baud rate (default: 9600)
  • BACKEND_URL: Django backend URL (default: http://localhost:8000)
  • AUTO_CONNECT: Automatically connect on startup (default: True)
  • DEBUG: Enable debug logging (default: False)

Architecture

COM Port → Serial Reader → Backend Client → Django API
                             ↓
                         System Tray Icon

Logging

Logs are written to serial_bridge.log and console output.

Troubleshooting

  • COM port not found: Check COM_PORT setting and device connection
  • Cannot connect to backend: Verify Django server is running on BACKEND_URL
  • Data not posting: Check logs in serial_bridge.log
  • Tray icon not appearing: Run as administrator, check Windows settings