-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutters_window.py
63 lines (49 loc) · 2.31 KB
/
shutters_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
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QTimer, pyqtSignal
from PyQt5.uic import loadUi
from opcua import OPCUAConnection
from configparser import ConfigParser
from components.shutter import Shutter
class ShutterWindow(QWidget):
closing = pyqtSignal()
def __init__(self, parent, opcua_conn, redis_client):
super(ShutterWindow, 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._shutter1 = Shutter(self.opcua_conn, "ns=4;s=MAIN.nott_ics.Shutters.NSH1", 'Shutter 1')
self._shutter2 = Shutter(self.opcua_conn, "ns=4;s=MAIN.nott_ics.Shutters.NSH2", 'Shutter 2')
self._shutter3 = Shutter(self.opcua_conn, "ns=4;s=MAIN.nott_ics.Shutters.NSH3", 'Shutter 3')
self._shutter4 = Shutter(self.opcua_conn, "ns=4;s=MAIN.nott_ics.Shutters.NSH4", 'Shutter 4')
self.redis_client = redis_client
self.ui = loadUi('shutters.ui', self)
self.ui.shutter_widget_1.setup(self.opcua_conn, self.redis_client, self._shutter1)
self.ui.shutter_widget_2.setup(self.opcua_conn, self.redis_client, self._shutter2)
self.ui.shutter_widget_3.setup(self.opcua_conn, self.redis_client, self._shutter3)
self.ui.shutter_widget_4.setup(self.opcua_conn, self.redis_client, self._shutter4)
self.t_pos = QTimer()
self.t_pos.timeout.connect(self.load_positions)
self.t_pos.start(5)
self.t = QTimer()
self.t.timeout.connect(self.refresh_status)
self.t.start(200)
def closeEvent(self, *args):
self.t.stop()
self.t_pos.stop()
self.opcua_conn.disconnect()
self.closing.emit()
super().closeEvent(*args)
def refresh_status(self):
self.ui.shutter_widget_1.refresh_status()
self.ui.shutter_widget_2.refresh_status()
self.ui.shutter_widget_3.refresh_status()
self.ui.shutter_widget_4.refresh_status()
def load_positions(self):
self.ui.shutter_widget_1.load_position()
self.ui.shutter_widget_2.load_position()
self.ui.shutter_widget_3.load_position()
self.ui.shutter_widget_4.load_position()