1## Example_RTD/ main.py
2## This is example for RTD with WPC DAQ Device with synchronous mode.
3## Copyright (c) 2023 WPC Systems Ltd.
4## All rights reserved.
5
6## Python
7import sys
8import os
9
10## Third party
11from PyQt5 import QtWidgets, QtGui
12from UI_design.Ui_example_GUI_RTD import Ui_MainWindow
13
14## WPC
15from wpcsys import pywpc
16
17DEVIDER = 2000
18class MainWindow(QtWidgets.QMainWindow):
19 def __init__(self):
20 super(MainWindow, self).__init__()
21
22 ## UI initialize
23 self.ui = Ui_MainWindow()
24 self.ui.setupUi(self)
25
26 ## Get Python driver version
27 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
28
29 ## Connection flag
30 self.connect_flag = 0
31
32 ## Handle declaration
33 self.dev = None
34
35 ## Material path
36 file_path = os.path.dirname(__file__)
37 self.trademark_path = file_path + "\Material\\trademark.jpg"
38 self.blue_led_path = file_path + "\Material\LED_blue.png"
39 self.red_led_path = file_path + "\Material\LED_red.png"
40 self.green_led_path = file_path + "\Material\LED_green.png"
41 self.gray_led_path = file_path + "\Material\LED_gray.png"
42
43 ## Set trademark & LED path
44 self.ui.lb_trademark.setPixmap(QtGui.QPixmap(self.trademark_path))
45 self.ui.lb_led.setPixmap(QtGui.QPixmap(self.gray_led_path))
46
47 ## Define callback events
48 self.ui.btn_connect.clicked.connect(self.connectEvent)
49 self.ui.btn_disconnect.clicked.connect(self.disconnectEvent)
50
51 self.ui.btn_set.clicked.connect(self.setEvent)
52 self.ui.btn_RTD.clicked.connect(self.RTDEvent)
53
54 def selectHandle(self):
55 handle_idx = int(self.ui.comboBox_handle.currentIndex())
56 if handle_idx == 0:
57 self.dev = pywpc.USBDAQF1RD()
58
59 def updateParam(self):
60 ## Get IP or serial_number from GUI
61 self.ip = self.ui.lineEdit_IP.text()
62
63 ## Get port from GUI
64 self.port = int(self.ui.comboBox_port.currentIndex())+1
65
66 ## Get type from GUI
67 self.type = self.ui.comboBox_type.currentIndex()
68
69 ## Get noiserejection from GUI
70 self.noiserejection = self.ui.comboBox_noiserejection.currentIndex()
71
72 def RTDEvent(self):
73 ## Update Param
74 self.updateParam()
75
76 ## Read sensor in Channel 0
77 data = self.dev.Thermal_readSensor(self.port, 0)
78 print("Read channel 0 data:", data, "°C")
79
80 ## Update in GUI
81 self.ui.lineEdit_sensor0.setText(str(data))
82
83 ## Read sensor in Channel 1
84 data = self.dev.Thermal_readSensor(self.port, 1)
85 print("Read channel 1 data:", data, "°C")
86
87 ## Update in GUI
88 self.ui.lineEdit_sensor1.setText(str(data))
89
90 def setEvent(self):
91 ## Update Param
92 self.updateParam()
93
94 ## Set RTD port to 1 and set type for two channels
95 for i in range(2):
96 status = self.dev.Thermal_setType(self.port, i, self.type)
97 print("Thermal_setType_async status: ", status)
98
99 def connectEvent(self):
100 if self.connect_flag == 1:
101 return
102
103 ## Select handle
104 self.selectHandle()
105
106 ## Update Param
107 self.updateParam()
108
109 ## Connect to device
110 try:
111 self.dev.connect(self.ip)
112 except pywpc.Error as err:
113 print("err: " + str(err))
114 return
115
116 ## Change LED status
117 self.ui.lb_led.setPixmap(QtGui.QPixmap(self.blue_led_path))
118
119 ## Change connection flag
120 self.connect_flag = 1
121
122 ## Open RTD port
123 status = self.dev.Thermal_open(self.port)
124 print("Thermal_open status: ", status)
125
126 def disconnectEvent(self):
127 if self.connect_flag == 0:
128 return
129
130 ## Update Param
131 self.updateParam()
132
133 ## Close RTD port
134 status = self.dev.Thermal_close(self.port)
135 print("Thermal_close status: ", status)
136
137 ## Disconnect device
138 self.dev.disconnect()
139
140 ## Change LED status
141 self.ui.lb_led.setPixmap(QtGui.QPixmap(self.green_led_path))
142
143 ## Change connection flag
144 self.connect_flag = 0
145
146 def closeEvent(self, event):
147 if self.dev is not None:
148 ## Disconnect device
149 self.dev.disconnect()
150
151 ## Release device handle
152 self.dev.close()
153
154if __name__ == "__main__":
155 app = QtWidgets.QApplication([])
156 WPC_main_ui = MainWindow()
157 WPC_main_ui.show()
158 sys.exit(app.exec_())