Add spectrometer.py JSON wrapper for external tools
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
44
spectrometer.py
Normal file
44
spectrometer.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
"""Thin wrapper for external tools — outputs JSON to stdout."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from hpcs6500 import HPCS6500, find_hpcs_port
|
||||||
|
|
||||||
|
|
||||||
|
def measure():
|
||||||
|
port = find_hpcs_port()
|
||||||
|
if not port:
|
||||||
|
print('{"error": "HPCS 6500 not found"}', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
dev = HPCS6500(port)
|
||||||
|
try:
|
||||||
|
dev.identify()
|
||||||
|
dev.psu_on()
|
||||||
|
reading = dev.take_reading(psu=False)
|
||||||
|
finally:
|
||||||
|
dev.psu_off()
|
||||||
|
dev.close()
|
||||||
|
|
||||||
|
if reading is None:
|
||||||
|
print('{"error": "measurement failed"}', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"lumen": round(reading["Phi_lm"], 1),
|
||||||
|
"cct": round(reading["CCT_K"]),
|
||||||
|
}
|
||||||
|
print(json.dumps(result))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="HPCS 6500 JSON interface")
|
||||||
|
parser.add_argument("--measure", action="store_true", help="Take a measurement and output JSON")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.measure:
|
||||||
|
measure()
|
||||||
|
else:
|
||||||
|
parser.print_help()
|
||||||
Reference in New Issue
Block a user