-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecmcGuiMain.py
187 lines (152 loc) · 5.94 KB
/
ecmcGuiMain.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
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
#!/usr/bin/python3.6
# coding: utf-8
from PyQt5 import QtWidgets,uic
import numpy as np
import epics
from ecmcArrayStat import *
from ecmcOneMotorGUI import *
from ecmcMainWndDesigner import Ui_MainWindow
from ecmcFFTMainGui import *
from ecmcScopeMainGui import *
import ecmcTrendPv
import time
# Needed packages:
# 1. sudo yum -y install https://rhel7.iuscommunity.org/ius-release.rpm
# 2. sudo pip3.6 install pyqt5
# 3. sudo yum install qt5-qtbase-devel
# 4. sudo python3.6 -m pip install numpy scipy matplotlib
# 5. sudo pip3 install pyepics
# 6. sudo yum install python3-matplotlib
# Regenerate py from ui file:
# pyuic5 -x ecmcMainWndDesigner.ui -o ecmcMainWndDesigner.py
class ecmcMainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ecmcMainWindow,self).__init__()
self.prefix=""
self.pvName=""
self.pv=None
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pbStartGUI.clicked.connect(self.showGUI)
self.ui.pbStartGUI.setToolTip("Start GUI for ioc-prefix + pv-name")
self.ui.lineIOCPrefix.textChanged.connect(self.newIOCPrefix)
self.ui.lineIOCPrefix.setToolTip("Enter ioc-prefix to to use.")
self.ui.linepvName.textChanged.connect(self.newIOCpvName)
self.ui.linepvName.setToolTip("Enter pv-name to plot/trend (or control)")
self.ui.comboPrefix.currentIndexChanged.connect(self.newPrefixComboIndex)
self.ui.comboPrefix.addItem("IOC_TEST:")
self.ui.comboPrefix.addItem("IOC:")
self.ui.comboPrefix.addItem("IOC2:")
self.ui.comboPrefix.addItem("IOC_SLIT:")
self.ui.comboPrefix.addItem("TEST")
self.ui.comboPrefix.setToolTip("Predefined ioc-prefix. Choose one to use..")
self.ui.comboPvName.currentIndexChanged.connect(self.newPvComboIndex)
self.ui.comboPvName.addItem("Axis1")
self.ui.comboPvName.addItem("Axis2")
self.ui.comboPvName.addItem("MCU-ThdLatMax")
self.ui.comboPvName.addItem("MCU-ThdLatMin")
self.ui.comboPvName.addItem("MCU-ThdPrdMax")
self.ui.comboPvName.addItem("MCU-ThdPrdMin")
self.ui.comboPvName.addItem("MCU-ThdSndMax")
self.ui.comboPvName.addItem("MCU-ThdSndMin")
self.ui.comboPvName.addItem("m0-DomFailCntrTot")
self.ui.comboPvName.addItem("MCU-ErrId")
self.ui.comboPvName.addItem("m0s001-BI01")
self.ui.comboPvName.addItem("m0s001-BI02")
self.ui.comboPvName.addItem("m0s003-Enc01-PosAct")
self.ui.comboPvName.addItem("FFT-0")
self.ui.comboPvName.addItem("Scope-0")
self.ui.comboPvName.setToolTip("Predefined pv-names. Choose one to use..")
if len(sys.argv)>1:
self.prefix=sys.argv[1]
self.ui.lineIOCPrefix.setText(self.prefix)
if len(sys.argv)>2:
self.pvName=sys.argv[2]
self.ui.linepvName.setText(self.pvName)
if (len(sys.argv)>2):
for i in range(2,len(sys.argv)):
self.ui.linepvName.setText(str(sys.argv[i]))
self.showGUI()
def showGUI(self):
#Check and start FFT gui
if self.showGuiFFT(self.prefix, self.pvName):
return
#Check and start Scope gui
if self.showGuiScope(self.prefix, self.pvName):
return
# See if scalar or motor
self.ui.pbStartGUI.setText("Connecting to: " + self.prefix + self.pvName + "...")
self.ui.pbStartGUI.setEnabled(False)
self.ui.pbStartGUI.update()
QtCore.QCoreApplication.processEvents()
self.prefix=self.ui.lineIOCPrefix.text()
self.pvName=self.ui.linepvName.text()
entirePvName = self.prefix+self.pvName
pos = entirePvName.rfind('.')
# ensure record/pv exist
pvtest = epics.PV(entirePvName)
connected = pvtest.wait_for_connection(timeout=2)
self.ui.pbStartGUI.setEnabled(True)
self.ui.pbStartGUI.setText("Start GUI for: " + self.prefix + self.pvName)
self.ui.pbStartGUI.update()
if not(connected):
print("Timeout. Could not connect to: " + entirePvName + ". Probably not a valid PV name.")
return
del(pvtest)
# Check if motor
if pos < 0:
pv = epics.PV(entirePvName + '.RTYP')
if pv.get() == 'motor':
self.showMotorGUI(self.prefix, self.pvName)
return
# Normal PV
self.showGuiPv(self.prefix+self.pvName)
def showMotorGUI(self,prefix,pvName):
self.dialog = MotorPanel(self,prefix,pvName)
self.dialog.resize(500, 900)
self.dialog.show()
def showGuiPv(self, pvName):
dialog = ecmcTrendPv.ecmcTrendPv(pvName)
dialog.show()
def showGuiFFT(self, prefix, pvName):
# Check if FFT gui
if pvName.find('FFT-') == 0 and len(prefix) > 0:
pvNameTemp = pvName.split('-')
if np.size(pvNameTemp)==2:
if pvNameTemp[1].isdigit():
self.dialog = ecmcFFTMainGui(prefix,int(pvNameTemp[1]))
self.dialog.show()
return 1
return 0
def showGuiScope(self, prefix, pvName):
# Check if FFT gui
if pvName.find('Scope-') == 0 and len(prefix) > 0:
pvNameTemp = pvName.split('-')
if np.size(pvNameTemp)==2:
if pvNameTemp[1].isdigit():
self.dialog = ecmcScopeMainGui(prefix,int(pvNameTemp[1]))
self.dialog.show()
return 1
return 0
def newIOCPrefix(self,iocPrefix):
self.prefix=iocPrefix
self.ui.pbStartGUI.setText("Start GUI for: " + self.prefix + self.pvName)
def newIOCpvName(self,pvName):
self.pvName=pvName
self.ui.pbStartGUI.setText("Start GUI for: " + self.prefix + self.pvName)
def newPrefixComboIndex(self,index):
self.prefix=self.ui.comboPrefix.itemText(index)
self.ui.lineIOCPrefix.setText(self.prefix)
self.ui.pbStartGUI.setText("Start GUI for: " + self.prefix + self.pvName)
def newPvComboIndex(self,index):
self.pvName=self.ui.comboPvName.itemText(index)
self.ui.linepvName.setText(self.pvName)
self.ui.pbStartGUI.setText("Start GUI for: " + self.prefix + self.pvName)
def quit(self):
self.close()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window=ecmcMainWindow();
window.show()
sys.exit(app.exec_())