-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiptilt_window.py
89 lines (65 loc) · 2.65 KB
/
tiptilt_window.py
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
from PyQt5.QtWidgets import QMainWindow, QWidget
from PyQt5.QtCore import QTimer, pyqtSignal
from PyQt5.uic import loadUi
from opcua import OPCUAConnection
from asyncua import ua
from datetime import datetime
from redisclient import RedisClient
from camera.scify import MainWindow as camera_ui
from configparser import ConfigParser
from components.motor import Motor
from shutters_window import ShutterWindow
class TipTiltWindow(QWidget):
closing = pyqtSignal()
def __init__(self, parent, opcua_conn, redis_client):
super(TipTiltWindow, self).__init__()
self.parent = parent
config = ConfigParser()
config.read('config.ini')
url = config['DEFAULT']['opcuaaddress']
# save the OPC UA connection
self.opcua_conn = OPCUAConnection(url)
self.opcua_conn.connect()
self._motor1 = Motor(self.opcua_conn, "ns=4;s=MAIN.tiptilt_1", 'tiptilt_1')
self.redis_client = redis_client
self.ui = loadUi('tiptilt_window.ui', self)
self.ui.motor_widget_1.setup(self.opcua_conn, self.redis_client, self._motor1)
self._activeCommand = None
self.timestamp = None
self.t_pos = QTimer()
self.t_pos.timeout.connect(self.load_positions)
self.t_pos.start(10)
self.t = QTimer()
self.t.timeout.connect(self.refresh_status)
self.t.start(500)
def closeEvent(self, *args):
self.t.stop()
self.t_pos.stop()
self.opcua_conn.disconnect()
self.closing.emit()
super().closeEvent(*args)
def startCameraRecording(self):
self.parent.camera_window.start_recording()
def stopCameraRecording(self):
self.parent.camera_window.stop_recording()
def executeCommand(self, cmd):
cmd.execute()
if self._activeCommand is not None:
raise Exception('Already an active command!')
self._activeCommand = cmd
self.ui.dl_command_status.setText(f'Executing command \'{self._activeCommand.text()}\' ...')
self.ui.pb_homing.setEnabled(False)
self.ui.pb_move_rel.setEnabled(False)
self.ui.pb_move_abs.setEnabled(False)
self.ui.pb_scan.setEnabled(False)
def clearActiveCommand(self):
self._activeCommand = None
self.ui.dl_command_status.setText('Not executing command')
self.ui.pb_homing.setEnabled(True)
self.ui.pb_move_rel.setEnabled(True)
self.ui.pb_move_abs.setEnabled(True)
self.ui.pb_scan.setEnabled(True)
def refresh_status(self):
self.ui.motor_widget_1.refresh_status()
def load_positions(self):
self.ui.motor_widget_1.load_position()