Add logger_script/src/logger_script/cli.py
This commit is contained in:
parent
6721b83137
commit
12d202fc08
1 changed files with 40 additions and 0 deletions
40
logger_script/src/logger_script/cli.py
Normal file
40
logger_script/src/logger_script/cli.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from logger_script import core
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI-Einstiegspunkt für den Fluoreszenz-Datenlogger."""
|
||||||
|
parser = argparse.ArgumentParser(description="Fluoreszenz-Datenlogger für USB-Spektrometer")
|
||||||
|
parser.add_argument(
|
||||||
|
"--duration",
|
||||||
|
type=int,
|
||||||
|
required=True,
|
||||||
|
help="Dauer der Datenerfassung in Sekunden (positiver Integer)"
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Eingabevalidierung
|
||||||
|
if args.duration <= 0:
|
||||||
|
print("Fehler: --duration muss eine positive Ganzzahl sein.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
logs = core.start_logging(args.duration)
|
||||||
|
core.flush_buffer()
|
||||||
|
output_path = Path("output/logs.json")
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
import json
|
||||||
|
with output_path.open("w", encoding="utf-8") as f:
|
||||||
|
json.dump(logs, f, ensure_ascii=False, indent=2)
|
||||||
|
print(f"Datenerfassung abgeschlossen. Ergebnisse gespeichert unter: {output_path}")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Messung abgebrochen per Tastatur.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler während der Messung: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue