5a8527e96e
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>
COM Port Test Writer - Simulates device sending data
This utility simulates a physical device (like scales) by continuously writing test data to a COM port.
Features
- ✅ Writes test data continuously to COM port
- ✅ Multiple data types: scales, counter, random, mixed
- ✅ Configurable write interval
- ✅ Easy start/stop with Ctrl+C
- ✅ List available COM ports
- ✅ Command-line arguments
Setup
-
Install dependencies:
pip install -r requirements.txt -
Configure environment (optional):
copy .env.example .env # Edit .env with your settings
Usage
List Available COM Ports
python test_writer.py --list
Basic Usage (using configured port)
python test_writer.py
Specify COM Port
python test_writer.py --port COM3
Different Data Types
Scales Data (default) - Simulates scale readings
python test_writer.py --type scales
Counter Data - Incrementing numbers
python test_writer.py --type counter
Random Data - Random numeric values
python test_writer.py --type random
Mixed Sensor Data - Temperature, humidity, pressure
python test_writer.py --type mixed
Custom Write Interval
python test_writer.py --interval 2.0 # Send every 2 seconds
python test_writer.py --interval 0.5 # Send every 0.5 seconds
Custom Baud Rate
python test_writer.py --baud 115200
Testing Workflow
-
Start Serial Bridge (reads COM port)
cd serial_bridge python app.py -
Start Test Writer (writes test data)
cd test_comport_writer python test_writer.py --type scales --interval 1.0 -
View in React Frontend
- Open http://localhost:3000
- Data should appear in real-time
Configuration
Edit .env for default settings:
COM_PORT=COM1
BAUD_RATE=9600
WRITE_INTERVAL=1.0
TEST_DATA_TYPE=scales
SCALES_MIN=0
SCALES_MAX=100
Example Output
==================================================
COM Port Test Writer
==================================================
Port: COM1
Baud Rate: 9600
Data Type: scales
Write Interval: 1.0s
==================================================
✓ Connected to COM1 at 9600 baud
Press Ctrl+C to stop writing data
→ Sent: 45.23 kg
→ Sent: 45.67 kg
→ Sent: 46.12 kg
→ Sent: 46.45 kg
...
(Press Ctrl+C to stop)
✓ Disconnected from COM1
✓ Test writer stopped
Troubleshooting
- "COM port not found": Check
COM_PORTsetting and ensure port exists - "Port already in use": Another application is using the port (close Serial Bridge temporarily)
- No data appearing: Ensure Serial Bridge is running and pointing to same COM port
- Baud rate mismatch: Ensure test writer and serial bridge use same baud rate
Complete System Test
To test the complete flow:
# Terminal 1: Django Backend
cd backend
venv\Scripts\activate
python manage.py runserver
# Terminal 2: React Frontend
cd frontend
npm start
# Terminal 3: Serial Bridge
cd serial_bridge
venv\Scripts\activate
python app.py
# Terminal 4: Test Writer
cd test_comport_writer
python test_writer.py --type scales --interval 1.0
Then visit http://localhost:3000 to see real-time data flow.