66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
import sys
|
|
import pysmu
|
|
from PyQt5.QtWidgets import QApplication
|
|
from PyQt5.QtCore import pyqtSignal, QObject
|
|
from GUI import MainWindow
|
|
from DeviceController import DeviceController
|
|
from functools import partial
|
|
|
|
class ControllerSignals(QObject):
|
|
started = pyqtSignal(str) # serial
|
|
stopped = pyqtSignal(str)
|
|
error = pyqtSignal(str, str) # serial, msg
|
|
|
|
signals = ControllerSignals()
|
|
|
|
def main():
|
|
# 1) Geräte einsammeln (pysmu nur hier benutzen)
|
|
sess = pysmu.Session()
|
|
sess.add_all()
|
|
|
|
controllers = {dev.serial: DeviceController(sess, dev) for dev in sess.devices}
|
|
serials = list(controllers.keys())
|
|
print("Gefundene Geräte:", serials)
|
|
|
|
# Optional: Modi setzen
|
|
for serial in serials:
|
|
c = controllers[serial]
|
|
c.set_mode("A", pysmu.Mode.SIMV) # CH A z. B.
|
|
c.set_mode("B", pysmu.Mode.HI_Z) # CH B z. B.
|
|
|
|
# 2) GUI erstellen
|
|
app = QApplication(sys.argv)
|
|
win = MainWindow()
|
|
|
|
# Kleine Helfer, damit die ListItem-Buttons nur Controller.start/stop aufrufen
|
|
def on_start(ctrl, widget, checked=False):
|
|
try:
|
|
ctrl.start() # darf nicht blockieren!
|
|
widget.set_running(True)
|
|
except Exception as e:
|
|
print("Start-Fehler:", e)
|
|
|
|
def on_stop(ctrl, widget, checked=False):
|
|
try:
|
|
ctrl.stop()
|
|
widget.set_running(False)
|
|
except Exception as e:
|
|
print("Stop-Fehler:", e)
|
|
|
|
# 3) Liste befüllen (auf der INSTANZ, nicht auf der Klasse!)
|
|
for i, serial in enumerate(serials):
|
|
ctrl = controllers[serial]
|
|
widget = win.add_list_item(serial, i)
|
|
# Wichtig: partial gibt eine Callback-Funktion mit fester Signatur zurück;
|
|
# PyQt darf noch ein 'checked' anhängen -> unsere Slots akzeptieren es.
|
|
widget.btn_start.clicked.connect(partial(on_start, ctrl, widget))
|
|
widget.btn_stop.clicked.connect(partial(on_stop, ctrl, widget))
|
|
|
|
|
|
# 4) Start
|
|
win.show()
|
|
sys.exit(app.exec_())
|
|
|
|
if __name__ == "__main__":
|
|
main()
|