Gauge drive day: CANNY comparison, cluster signal research, serial tools
Wiki: two new pages - canny-5-3-pico-gauge-drive (why the CANNY's 12V negative output moved the needles and 3.3V push-pull could not; 2SK3069 low-side stage) and patrol-instrument-cluster (tach 2 ppr + trim -13 calibration, NTC temp sender curve, 20 kHz PWM flutter fix, and the four-layer steppy-needle diagnosis ending at the cluster's ~150 rpm count quantization, defeated with adaptive dither on B). Tools: serial_logger.py (multi-port capture to wiki/raw), serial_cmd.py (one-shot cfg commands to A), dual_serial_capture.py (bench snapshots), tach_ramp.py / tach_ramp2.py (synthetic rpm sweeps via cfg override). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Capture N seconds from two serial ports in parallel and print what arrived."""
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
|
||||
import serial
|
||||
|
||||
PORTS = sys.argv[1].split(",") if len(sys.argv) > 1 else ["COM8", "COM9"]
|
||||
SECONDS = float(sys.argv[2]) if len(sys.argv) > 2 else 6.0
|
||||
MAX_LINES = 40
|
||||
|
||||
|
||||
def cap(port, out):
|
||||
try:
|
||||
s = serial.Serial(port, 115200, timeout=0.5)
|
||||
end = time.time() + SECONDS
|
||||
buf = b""
|
||||
while time.time() < end:
|
||||
buf += s.read(4096)
|
||||
s.close()
|
||||
out[port] = buf
|
||||
except Exception as e:
|
||||
out[port] = ("ERR: %s" % e).encode()
|
||||
|
||||
|
||||
out = {}
|
||||
threads = [threading.Thread(target=cap, args=(p, out)) for p in PORTS]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
for p in PORTS:
|
||||
data = out.get(p, b"")
|
||||
print("=" * 20, p, "bytes:", len(data), "=" * 20)
|
||||
lines = data.decode("utf-8", "replace").splitlines()
|
||||
for ln in lines[:MAX_LINES]:
|
||||
print(ln)
|
||||
if len(lines) > MAX_LINES:
|
||||
print("... (%d more lines)" % (len(lines) - MAX_LINES))
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Send a command line to a serial port and print the reply.
|
||||
|
||||
Usage: python tools/serial_cmd.py COM10 "cfg show" [read_seconds]
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
port = sys.argv[1]
|
||||
cmd = sys.argv[2]
|
||||
secs = float(sys.argv[3]) if len(sys.argv) > 3 else 3.0
|
||||
|
||||
s = serial.Serial(port, 115200, timeout=0.5)
|
||||
s.reset_input_buffer()
|
||||
s.write((cmd + "\n").encode())
|
||||
s.flush()
|
||||
end = time.time() + secs
|
||||
buf = b""
|
||||
while time.time() < end:
|
||||
buf += s.read(4096)
|
||||
s.close()
|
||||
print(buf.decode("utf-8", "replace"))
|
||||
@@ -0,0 +1,66 @@
|
||||
"""Log one or more serial ports to timestamped files until Ctrl+C.
|
||||
|
||||
Usage:
|
||||
python tools/serial_logger.py COM9 # one port
|
||||
python tools/serial_logger.py COM8,COM9 # several ports
|
||||
python tools/serial_logger.py COM9 logs/ # custom output dir (default: wiki/raw/)
|
||||
|
||||
Each port gets its own file, e.g. wiki/raw/serial-COM9-20260922-141503.log.
|
||||
Lines are echoed to the console prefixed with the port name. Read-only:
|
||||
nothing is ever written to the port, so it is safe next to a live bus.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
from datetime import datetime
|
||||
|
||||
import serial
|
||||
|
||||
ports = sys.argv[1].split(",") if len(sys.argv) > 1 else ["COM9"]
|
||||
out_dir = sys.argv[2] if len(sys.argv) > 2 else os.path.join("wiki", "raw")
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
|
||||
stop = threading.Event()
|
||||
print_lock = threading.Lock()
|
||||
|
||||
|
||||
def log_port(port):
|
||||
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
path = os.path.join(out_dir, "serial-%s-%s.log" % (port, stamp))
|
||||
with print_lock:
|
||||
print("[%s] logging to %s" % (port, path))
|
||||
try:
|
||||
s = serial.Serial(port, 115200, timeout=0.5)
|
||||
except Exception as e:
|
||||
with print_lock:
|
||||
print("[%s] ERROR opening port: %s" % (port, e))
|
||||
return
|
||||
with open(path, "wb") as f:
|
||||
pending = b""
|
||||
while not stop.is_set():
|
||||
data = s.read(4096)
|
||||
if not data:
|
||||
continue
|
||||
f.write(data)
|
||||
f.flush()
|
||||
pending += data
|
||||
while b"\n" in pending:
|
||||
line, pending = pending.split(b"\n", 1)
|
||||
with print_lock:
|
||||
print("[%s] %s" % (port, line.decode("utf-8", "replace").rstrip()))
|
||||
s.close()
|
||||
with print_lock:
|
||||
print("[%s] closed, log saved: %s" % (port, path))
|
||||
|
||||
|
||||
threads = [threading.Thread(target=log_port, args=(p,)) for p in ports]
|
||||
for t in threads:
|
||||
t.start()
|
||||
try:
|
||||
while any(t.is_alive() for t in threads):
|
||||
time.sleep(0.2)
|
||||
except KeyboardInterrupt:
|
||||
stop.set()
|
||||
for t in threads:
|
||||
t.join()
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Sweep the tach via A's override: 800 -> 3500 -> 800 rpm, then override off.
|
||||
|
||||
Usage: python tools/tach_ramp.py COM10 [step_rpm] [step_ms]
|
||||
Sends 'cfg override rpm N' lines over A's console; A pushes each as a CONFIG
|
||||
frame to B. Ctrl+C aborts and switches the override off.
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
port = sys.argv[1] if len(sys.argv) > 1 else "COM10"
|
||||
step = int(sys.argv[2]) if len(sys.argv) > 2 else 50
|
||||
dwell = (int(sys.argv[3]) if len(sys.argv) > 3 else 150) / 1000.0
|
||||
|
||||
s = serial.Serial(port, 115200, timeout=0.1)
|
||||
# Native-USB boards reset when the port opens - give A time to boot.
|
||||
time.sleep(4)
|
||||
s.reset_input_buffer()
|
||||
|
||||
|
||||
def send(cmd):
|
||||
s.write((cmd + "\n").encode())
|
||||
s.flush()
|
||||
|
||||
|
||||
try:
|
||||
points = list(range(800, 3501, step)) + list(range(3500, 799, -step))
|
||||
print("ramp: %d points, %d ms each (~%.0f s total)" % (len(points), dwell * 1000, len(points) * dwell))
|
||||
for rpm in points:
|
||||
send("cfg override rpm %d" % rpm)
|
||||
time.sleep(dwell)
|
||||
finally:
|
||||
send("cfg override off")
|
||||
time.sleep(0.5)
|
||||
s.close()
|
||||
print("done, override off")
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Ramp tach override 800 -> 6000 rpm, hold 5 s, ramp back down, override off.
|
||||
|
||||
Usage: python tools/tach_ramp2.py COM10 [step_rpm] [step_ms]
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
port = sys.argv[1] if len(sys.argv) > 1 else "COM10"
|
||||
step = int(sys.argv[2]) if len(sys.argv) > 2 else 25
|
||||
dwell = (int(sys.argv[3]) if len(sys.argv) > 3 else 40) / 1000.0
|
||||
|
||||
s = serial.Serial(port, 115200, timeout=0.1)
|
||||
time.sleep(4) # native-USB reset on port open
|
||||
s.reset_input_buffer()
|
||||
|
||||
|
||||
def send(cmd):
|
||||
s.write((cmd + "\n").encode())
|
||||
s.flush()
|
||||
|
||||
|
||||
try:
|
||||
up = list(range(800, 6001, step))
|
||||
down = list(range(6000, 799, -step))
|
||||
print("up %d pts, hold 5 s at 6000, down %d pts" % (len(up), len(down)))
|
||||
for rpm in up:
|
||||
send("cfg override rpm %d" % rpm)
|
||||
time.sleep(dwell)
|
||||
send("cfg override rpm 6000")
|
||||
time.sleep(5)
|
||||
for rpm in down:
|
||||
send("cfg override rpm %d" % rpm)
|
||||
time.sleep(dwell)
|
||||
finally:
|
||||
send("cfg override off")
|
||||
time.sleep(0.5)
|
||||
s.close()
|
||||
print("done, override off")
|
||||
Reference in New Issue
Block a user