-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
663 lines (545 loc) · 24.9 KB
/
Copy pathgui.py
File metadata and controls
663 lines (545 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
"""LaserPoint GUI — Tkinter-based test GUI for the hgc_laser Python library.
Mimics the LaserPoint.exe UI layout:
- Connection panel (port, baud, slave ID, connect/disconnect)
- Live measurement display (large mm readout + µm)
- Real-time strip chart (last 200 samples)
- Laser ON/OFF toggle
- Precision mode selector
- Sensor settings (change address, change baud)
- Log panel
Usage:
python gui.py
python gui.py --port COM4 --baud 115200 --slave 1
Requirements: Python 3.10+, pyserial (pip install pyserial)
No other dependencies — uses only tkinter (stdlib).
"""
from __future__ import annotations
import argparse
import queue
import sys
import threading
import time
import tkinter as tk
from tkinter import font as tkfont
from tkinter import messagebox, ttk
from collections import deque
from typing import Optional
# ---------------------------------------------------------------------------
# Import the library
# ---------------------------------------------------------------------------
try:
from hgc_laser import LaserDevice, SerialConfig, MeasurementResult
from hgc_laser.protocol.commands import BAUD_CODE_MAP, PRECISION_MODE_MAP
import serial.tools.list_ports as _list_ports # type: ignore
def _get_ports() -> list[str]:
return [str(p.device) for p in _list_ports.comports()]
except ImportError:
print(
"ERROR: hgc_laser package not found.\n"
"Install it first:\n"
" pip install -e .\n"
)
sys.exit(1)
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
POLL_INTERVAL_MS = 100
STREAM_INTERVAL_S = 0.1
CHART_SAMPLES = 200
CHART_H = 160
CHART_W = 600
BAUD_OPTIONS = [str(v) for v in sorted(BAUD_CODE_MAP.values())]
PRECISION_OPTIONS = list(PRECISION_MODE_MAP.values()) # ['low_speed_high_precision', ...]
# ---------------------------------------------------------------------------
# Background worker
# ---------------------------------------------------------------------------
class SensorWorker:
"""Runs all sensor I/O in a daemon thread; communicates via queues."""
def __init__(self, result_q: queue.Queue, log_q: queue.Queue):
self._result_q = result_q
self._log_q = log_q
self._device: Optional[LaserDevice] = None
self._cmd_q: queue.Queue = queue.Queue()
self._streaming = False
self._thread = threading.Thread(target=self._run, daemon=True)
self._thread.start()
# ---- public interface (called from GUI thread) ----
def connect(self, config: SerialConfig):
self._cmd_q.put(("connect", config))
def disconnect(self):
self._cmd_q.put(("disconnect",))
def single_read(self):
self._cmd_q.put(("single_read",))
def start_stream(self):
self._cmd_q.put(("start_stream",))
def stop_stream(self):
self._cmd_q.put(("stop_stream",))
def laser_on(self):
self._cmd_q.put(("laser_on",))
def laser_off(self):
self._cmd_q.put(("laser_off",))
def set_precision(self, mode: str):
self._cmd_q.put(("set_precision", mode))
def set_address(self, addr: int):
self._cmd_q.put(("set_address", addr))
def set_baud(self, baud: int):
self._cmd_q.put(("set_baud", baud))
def refresh_state(self):
self._cmd_q.put(("refresh",))
# ---- internal ----
def _log(self, msg: str):
self._log_q.put(msg)
def _is_open(self) -> bool:
return (
self._device is not None
and self._device._client._transport.is_open
)
def _run(self):
while True:
try:
cmd = self._cmd_q.get(timeout=STREAM_INTERVAL_S if self._streaming else 1.0)
except queue.Empty:
cmd = None
if cmd is not None:
name = cmd[0]
if name == "connect":
cfg = cmd[1]
try:
if self._device and self._is_open():
try:
self._device.close()
except Exception:
pass
self._device = LaserDevice(cfg)
self._device.open()
self._log(f"Connected to {cfg.port} @ {cfg.baudrate} slave={cfg.slave_id}")
self._result_q.put(("connected", True))
self._do_refresh()
except Exception as e:
self._log(f"Connect error: {e}")
self._result_q.put(("connected", False))
elif name == "disconnect":
self._streaming = False
if self._device:
try:
self._device.close()
except Exception:
pass
self._device = None
self._log("Disconnected")
self._result_q.put(("connected", False))
elif name == "single_read":
self._do_read()
elif name == "start_stream":
self._streaming = True
self._log("Streaming started")
elif name == "stop_stream":
self._streaming = False
self._log("Streaming stopped")
elif name == "laser_on":
self._do_cmd("laser_on", lambda: self._device.laser_on())
elif name == "laser_off":
self._do_cmd("laser_off", lambda: self._device.laser_off())
elif name == "set_precision":
mode = cmd[1]
self._do_cmd("set_precision_mode",
lambda m=mode: self._device.set_precision_mode(m))
elif name == "set_address":
addr = cmd[1]
self._do_cmd("set_address",
lambda a=addr: self._device.set_address(a),
success_msg=f"Address set to {addr}. Power-cycle sensor.")
elif name == "set_baud":
baud = cmd[1]
self._do_cmd("set_baud",
lambda b=baud: self._device.set_baud(b),
success_msg=f"Baud set to {baud}. Power-cycle sensor.")
elif name == "refresh":
self._do_refresh()
# Streaming tick
if self._streaming and self._is_open():
self._do_read()
def _do_read(self):
if not self._is_open():
return
try:
result = self._device.measure()
self._result_q.put(("measurement", result))
except Exception as e:
self._log(f"Read error: {e}")
def _do_cmd(self, name: str, fn, success_msg: str = ""):
if not self._is_open():
self._log(f"{name}: not connected")
return
try:
fn()
self._log(success_msg or f"{name}: OK")
self._do_refresh()
except Exception as e:
self._log(f"{name} error: {e}")
def _do_refresh(self):
if not self._is_open():
return
try:
laser_on = self._device.is_laser_on()
self._result_q.put(("state", "laser_on", laser_on))
except Exception:
pass
try:
code = self._device.raw_client.read_precision_mode()
mode = PRECISION_MODE_MAP.get(code, "standard")
self._result_q.put(("state", "precision_mode", mode))
except Exception:
pass
try:
addr = self._device.get_address()
self._result_q.put(("state", "address", addr))
except Exception:
pass
try:
baud = self._device.get_baud()
self._result_q.put(("state", "baud", baud))
except Exception:
pass
# ---------------------------------------------------------------------------
# Strip chart (pure Tkinter canvas)
# ---------------------------------------------------------------------------
class StripChart(tk.Canvas):
"""Scrolling strip chart that plots the last N mm values."""
def __init__(self, parent, width=CHART_W, height=CHART_H, maxpts=CHART_SAMPLES, **kw):
super().__init__(parent, width=width, height=height,
bg="#1a1a2e", highlightthickness=1,
highlightbackground="#444", **kw)
self._maxpts = maxpts
self._data: deque[float] = deque(maxlen=maxpts)
self._cw = width # chart pixel width (not self._w — that's tkinter-internal)
self._ch = height # chart pixel height
self.bind("<Configure>", self._on_resize)
def _on_resize(self, event):
self._cw = event.width
self._ch = event.height
self._redraw()
def push(self, value_mm: float):
self._data.append(value_mm)
self._redraw()
def clear(self):
self._data.clear()
self._redraw()
def _redraw(self):
self.delete("all")
if len(self._data) < 2:
self._draw_grid()
return
mn = min(self._data)
mx = max(self._data)
span = mx - mn
if span < 0.01:
mn -= 0.5
mx += 0.5
span = mx - mn
pad = 6
w = self._cw - pad * 2
h = self._ch - pad * 2
self._draw_grid(mn, mx)
pts = []
for i, v in enumerate(self._data):
x = pad + i * w / (self._maxpts - 1)
y = pad + (1 - (v - mn) / span) * h
pts.extend([x, y])
if len(pts) >= 4:
self.create_line(pts, fill="#00d4ff", width=1.5, smooth=False)
last = list(self._data)[-1]
self.create_text(self._cw - 4, 4, text=f"{last:.3f} mm",
fill="#00d4ff", anchor="ne", font=("Consolas", 9))
def _draw_grid(self, mn=None, mx=None):
pad = 6
h = self._ch - pad * 2
for frac in (0.25, 0.5, 0.75):
y = pad + frac * h
self.create_line(pad, y, self._cw - pad, y, fill="#333355", dash=(4, 4))
if mn is not None and mx is not None:
mid = (mn + mx) / 2
self.create_text(2, pad + h * 0.5, text=f"{mid:.2f}",
fill="#555577", anchor="w", font=("Consolas", 8))
self.create_text(2, pad, text=f"{mx:.2f}",
fill="#555577", anchor="nw", font=("Consolas", 8))
self.create_text(2, pad + h, text=f"{mn:.2f}",
fill="#555577", anchor="sw", font=("Consolas", 8))
# ---------------------------------------------------------------------------
# Main application window
# ---------------------------------------------------------------------------
class LaserPointApp(tk.Tk):
def __init__(self, default_port="", default_baud=115200, default_slave=1):
super().__init__()
self.title("LaserPoint — HGC Python GUI")
self.resizable(True, True)
self.configure(bg="#0f0f1a")
self._result_q: queue.Queue = queue.Queue()
self._log_q: queue.Queue = queue.Queue()
self._worker = SensorWorker(self._result_q, self._log_q)
self._connected = False
self._streaming = False
self._laser_on = False
self._build_ui(default_port, default_baud, default_slave)
self._poll()
# ---- UI construction ----
def _build_ui(self, default_port, default_baud, default_slave):
# ---- connection bar ----
conn_frame = tk.Frame(self, bg="#16213e", padx=8, pady=6)
conn_frame.pack(fill=tk.X, padx=6, pady=(6, 0))
tk.Label(conn_frame, text="Port", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=0, padx=(0, 2))
self._port_var = tk.StringVar(value=default_port)
self._port_cb = ttk.Combobox(conn_frame, textvariable=self._port_var,
width=10, font=("Segoe UI", 9))
self._port_cb.grid(row=0, column=1, padx=(0, 8))
self._port_cb.bind("<Button-1>", self._refresh_ports)
tk.Label(conn_frame, text="Baud", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=2, padx=(0, 2))
self._baud_var = tk.StringVar(value=str(default_baud))
ttk.Combobox(conn_frame, textvariable=self._baud_var,
values=BAUD_OPTIONS, width=8,
font=("Segoe UI", 9)).grid(row=0, column=3, padx=(0, 8))
tk.Label(conn_frame, text="Slave ID", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=4, padx=(0, 2))
self._slave_var = tk.StringVar(value=str(default_slave))
tk.Entry(conn_frame, textvariable=self._slave_var, width=5,
font=("Segoe UI", 9)).grid(row=0, column=5, padx=(0, 12))
self._conn_btn = tk.Button(conn_frame, text="Connect",
command=self._toggle_connect,
bg="#1a6b3c", fg="white", relief=tk.FLAT,
font=("Segoe UI", 9, "bold"), padx=10)
self._conn_btn.grid(row=0, column=6, padx=(0, 4))
self._status_label = tk.Label(conn_frame, text="● Disconnected",
bg="#16213e", fg="#e74c3c",
font=("Segoe UI", 9, "bold"))
self._status_label.grid(row=0, column=7, padx=(8, 0))
# ---- measurement display ----
meas_frame = tk.Frame(self, bg="#0f0f1a", pady=4)
meas_frame.pack(fill=tk.X, padx=6)
big_font = tkfont.Font(family="Consolas", size=48, weight="bold")
sub_font = tkfont.Font(family="Consolas", size=14)
self._mm_label = tk.Label(meas_frame, text="----.---",
font=big_font, bg="#0f0f1a", fg="#00d4ff",
anchor="e", width=10)
self._mm_label.pack(side=tk.LEFT, padx=(20, 0))
unit_frame = tk.Frame(meas_frame, bg="#0f0f1a")
unit_frame.pack(side=tk.LEFT, padx=(4, 20), anchor="s")
tk.Label(unit_frame, text="mm", font=sub_font, bg="#0f0f1a",
fg="#4488aa").pack(anchor="w")
self._um_label = tk.Label(unit_frame, text="-- µm",
font=("Consolas", 11), bg="#0f0f1a", fg="#336688")
self._um_label.pack(anchor="w")
# ---- chart ----
chart_frame = tk.Frame(self, bg="#0f0f1a")
chart_frame.pack(fill=tk.BOTH, expand=True, padx=6, pady=(0, 4))
self._chart = StripChart(chart_frame)
self._chart.pack(fill=tk.BOTH, expand=True)
# ---- control row ----
ctrl_frame = tk.Frame(self, bg="#16213e", padx=8, pady=6)
ctrl_frame.pack(fill=tk.X, padx=6, pady=(0, 2))
self._read_btn = tk.Button(ctrl_frame, text="Read Once",
command=self._single_read,
bg="#1a3a6b", fg="white", relief=tk.FLAT,
font=("Segoe UI", 9), padx=8,
state=tk.DISABLED)
self._read_btn.grid(row=0, column=0, padx=(0, 4))
self._stream_btn = tk.Button(ctrl_frame, text="▶ Start Stream",
command=self._toggle_stream,
bg="#1a3a6b", fg="white", relief=tk.FLAT,
font=("Segoe UI", 9), padx=8,
state=tk.DISABLED)
self._stream_btn.grid(row=0, column=1, padx=(0, 4))
tk.Button(ctrl_frame, text="Clear Chart",
command=self._chart.clear,
bg="#2a2a3a", fg="#aaa", relief=tk.FLAT,
font=("Segoe UI", 9), padx=8).grid(row=0, column=2, padx=(0, 16))
self._laser_btn = tk.Button(ctrl_frame, text="Laser ON",
command=self._toggle_laser,
bg="#6b1a1a", fg="white", relief=tk.FLAT,
font=("Segoe UI", 9, "bold"), padx=10,
state=tk.DISABLED)
self._laser_btn.grid(row=0, column=3, padx=(0, 16))
tk.Label(ctrl_frame, text="Precision", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=4, padx=(0, 2))
self._prec_var = tk.StringVar(value=PRECISION_OPTIONS[0])
self._prec_cb = ttk.Combobox(ctrl_frame, textvariable=self._prec_var,
values=PRECISION_OPTIONS, width=22,
font=("Segoe UI", 9), state="readonly")
self._prec_cb.grid(row=0, column=5, padx=(0, 4))
self._prec_cb.bind("<<ComboboxSelected>>", self._on_precision_change)
# ---- settings row ----
set_frame = tk.Frame(self, bg="#16213e", padx=8, pady=4)
set_frame.pack(fill=tk.X, padx=6, pady=(0, 2))
tk.Label(set_frame, text="Change Address:", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=0, padx=(0, 2))
self._new_addr_var = tk.StringVar(value="1")
tk.Entry(set_frame, textvariable=self._new_addr_var, width=5,
font=("Segoe UI", 9)).grid(row=0, column=1, padx=(0, 4))
self._addr_btn = tk.Button(set_frame, text="Apply",
command=self._apply_address,
bg="#2a2a3a", fg="#ccc", relief=tk.FLAT,
font=("Segoe UI", 9), padx=6,
state=tk.DISABLED)
self._addr_btn.grid(row=0, column=2, padx=(0, 20))
tk.Label(set_frame, text="Change Baud:", bg="#16213e", fg="#aaa",
font=("Segoe UI", 9)).grid(row=0, column=3, padx=(0, 2))
self._new_baud_var = tk.StringVar(value="115200")
ttk.Combobox(set_frame, textvariable=self._new_baud_var,
values=BAUD_OPTIONS, width=8,
font=("Segoe UI", 9)).grid(row=0, column=4, padx=(0, 4))
self._baud_btn = tk.Button(set_frame, text="Apply",
command=self._apply_baud,
bg="#2a2a3a", fg="#ccc", relief=tk.FLAT,
font=("Segoe UI", 9), padx=6,
state=tk.DISABLED)
self._baud_btn.grid(row=0, column=5, padx=(0, 0))
# ---- log panel ----
log_frame = tk.Frame(self, bg="#0a0a14")
log_frame.pack(fill=tk.X, padx=6, pady=(2, 6))
tk.Label(log_frame, text="Log", bg="#0a0a14", fg="#555",
font=("Segoe UI", 8)).pack(anchor="w", padx=4)
log_inner = tk.Frame(log_frame, bg="#0a0a14")
log_inner.pack(fill=tk.X, padx=4, pady=(0, 4))
self._log_text = tk.Text(log_inner, height=5, bg="#0a0a14", fg="#556677",
font=("Consolas", 8), relief=tk.FLAT,
state=tk.DISABLED)
self._log_text.pack(side=tk.LEFT, fill=tk.X, expand=True)
sb = ttk.Scrollbar(log_inner, command=self._log_text.yview)
sb.pack(side=tk.RIGHT, fill=tk.Y)
self._log_text.configure(yscrollcommand=sb.set)
self._refresh_ports()
# ---- polling loop ----
def _poll(self):
while not self._log_q.empty():
self._append_log(self._log_q.get_nowait())
while not self._result_q.empty():
item = self._result_q.get_nowait()
if item[0] == "measurement":
self._update_measurement(item[1])
elif item[0] == "connected":
self._set_connected(item[1])
elif item[0] == "state":
self._update_state(item[1], item[2])
self.after(POLL_INTERVAL_MS, self._poll)
# ---- event handlers ----
def _refresh_ports(self, _event=None):
try:
names = _get_ports()
except Exception:
names = []
self._port_cb["values"] = names
if names and not self._port_var.get():
self._port_var.set(names[0])
def _toggle_connect(self):
if self._connected:
self._worker.disconnect()
else:
try:
cfg = SerialConfig(
port=self._port_var.get(),
baudrate=int(self._baud_var.get()),
slave_id=int(self._slave_var.get()),
)
except ValueError as e:
messagebox.showerror("Config error", str(e))
return
self._worker.connect(cfg)
def _toggle_stream(self):
if self._streaming:
self._streaming = False
self._worker.stop_stream()
self._stream_btn.config(text="▶ Start Stream", bg="#1a3a6b")
else:
self._streaming = True
self._worker.start_stream()
self._stream_btn.config(text="■ Stop Stream", bg="#6b3a1a")
def _single_read(self):
self._worker.single_read()
def _toggle_laser(self):
if self._laser_on:
self._worker.laser_off()
else:
self._worker.laser_on()
def _on_precision_change(self, _event=None):
if self._connected:
self._worker.set_precision(self._prec_var.get())
def _apply_address(self):
try:
addr = int(self._new_addr_var.get())
except ValueError:
messagebox.showerror("Input error", "Address must be an integer 1–247")
return
if messagebox.askyesno("Confirm",
f"Change sensor address to {addr}?\n"
"You will need to power-cycle the sensor afterwards."):
self._worker.set_address(addr)
def _apply_baud(self):
try:
baud = int(self._new_baud_var.get())
except ValueError:
messagebox.showerror("Input error", "Invalid baud rate")
return
if messagebox.askyesno("Confirm",
f"Change baud rate to {baud}?\n"
"You will need to power-cycle the sensor afterwards."):
self._worker.set_baud(baud)
# ---- state updates (GUI thread only, called from poll loop) ----
def _set_connected(self, connected: bool):
self._connected = connected
if connected:
self._conn_btn.config(text="Disconnect", bg="#6b1a1a")
self._status_label.config(text="● Connected", fg="#2ecc71")
for w in (self._read_btn, self._stream_btn,
self._laser_btn, self._addr_btn, self._baud_btn):
w.config(state=tk.NORMAL)
else:
self._connected = False
self._streaming = False
self._conn_btn.config(text="Connect", bg="#1a6b3c")
self._status_label.config(text="● Disconnected", fg="#e74c3c")
self._stream_btn.config(text="▶ Start Stream", bg="#1a3a6b")
for w in (self._read_btn, self._stream_btn,
self._laser_btn, self._addr_btn, self._baud_btn):
w.config(state=tk.DISABLED)
def _update_measurement(self, result: MeasurementResult):
self._mm_label.config(text=f"{result.displacement_mm:+.3f}")
self._um_label.config(text=f"{result.displacement_um:+,} µm")
self._chart.push(result.displacement_mm)
def _update_state(self, key: str, value):
if key == "laser_on":
self._laser_on = value
if value:
self._laser_btn.config(text="Laser ON ●", bg="#1a6b3c")
else:
self._laser_btn.config(text="Laser OFF ○", bg="#6b1a1a")
elif key == "precision_mode":
self._prec_var.set(value)
elif key == "address":
self._new_addr_var.set(str(value))
self._slave_var.set(str(value))
elif key == "baud":
self._new_baud_var.set(str(value))
def _append_log(self, msg: str):
ts = time.strftime("%H:%M:%S")
self._log_text.config(state=tk.NORMAL)
self._log_text.insert(tk.END, f"[{ts}] {msg}\n")
self._log_text.see(tk.END)
self._log_text.config(state=tk.DISABLED)
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
def main():
parser = argparse.ArgumentParser(description="LaserPoint HGC Python GUI")
parser.add_argument("--port", default="", help="Serial port, e.g. COM4")
parser.add_argument("--baud", type=int, default=115200, help="Baud rate")
parser.add_argument("--slave", type=int, default=1, help="Modbus slave ID")
args = parser.parse_args()
app = LaserPointApp(
default_port=args.port,
default_baud=args.baud,
default_slave=args.slave,
)
app.mainloop()
if __name__ == "__main__":
main()