-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutterwidget.py
99 lines (81 loc) · 3.03 KB
/
shutterwidget.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
90
91
92
93
94
95
96
97
98
99
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import pyqtSignal
from PyQt5.uic import loadUi
from datetime import datetime
class ShutterWidget(QWidget):
closing = pyqtSignal()
def __init__(self, parent):
QWidget.__init__(self, parent)
def setup(self, opcua_conn, redis_client, shutter):
self.opcua_conn = opcua_conn
self._shutter = shutter
self.redis_client = redis_client
self.timestamp = None
self.ui = loadUi('shutter_widget.ui', self)
self.ui.pb_reset.clicked.connect(self.reset)
self.ui.pb_init.clicked.connect(self.init)
self.ui.pb_enable.clicked.connect(self.enable)
self.ui.pb_disable.clicked.connect(self.disable)
self.ui.pb_stop.clicked.connect(self.stop)
self.ui.pb_open.clicked.connect(self.open)
self.ui.pb_close.clicked.connect(self.close)
self.ui.label_name.setText(self._shutter.name)
def refresh_status(self):
try:
status, state, substate = self._shutter.getStatusInformation()
self.ui.label_status.setText(str(status))
self.ui.label_state.setText(str(state))
self.ui.label_subState.setText(str(substate))
hwStatus = self._shutter.getHardwareStatus()
self.ui.label_opened.setText(str(hwStatus))
except Exception as e:
print(e)
self.ui.label_error.setText(str(e))
def load_position(self):
try:
hwStatus, timestamp = self._shutter.getHardwareStatus()
timestamp_plc = datetime.strptime(timestamp, '%Y-%m-%d-%H:%M:%S.%f')
shutter_pos = -1
if hwStatus == "OPEN":
shutter_pos = 1
if hwStatus == "CLOSED":
shutter_pos = 0
self.redis_client.add_shutter_position(self._shutter.name, timestamp_plc, shutter_pos)
except Exception as e:
print(e)
self.ui.label_error.setText(str(e))
def reset(self):
try:
res = self._shutter.reset()
except Exception as e:
print(f"Error calling RPC method: {e}")
def init(self):
try:
res = self._shutter.init()
except Exception as e:
print(f"Error calling RPC method: {e}")
def enable(self):
try:
res = self._shutter.enable()
except Exception as e:
print(f"Error calling RPC method: {e}")
def disable(self):
try:
res = self._shutter.disable()
except Exception as e:
print(f"Error calling RPC method: {e}")
def stop(self):
try:
res = self._shutter.stop()
except Exception as e:
print(f"Error calling RPC method: {e}")
def open(self):
try:
res = self._shutter.open()
except Exception as e:
print(f"Error calling RPC method: {e}")
def close(self):
try:
res = self._shutter.close()
except Exception as e:
print(f"Error calling RPC method: {e}")