1## Example_find_all_device/ main.py
2## This is example for finding all available ethernet devices 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 PyQt5.QtWidgets import QTableWidget,QApplication
13from PyQt5.QtCore import Qt
14from UI_design.Ui_example_GUI_find_all_device import Ui_MainWindow
15
16## WPC
17from wpcsys import pywpc
18
19COLUMN_WIDTH = 160
20
21class MainWindow(QtWidgets.QMainWindow):
22 def __init__(self):
23 super(MainWindow, self).__init__()
24 QTableWidget.__init__(self)
25
26 ## UI initialize
27 self.ui = Ui_MainWindow()
28 self.ui.setupUi(self)
29
30 ## Set trademark path
31 trademark_path = os.getcwd() + "\Material\\trademark.jpg"
32 self.ui.lb_trademark.setPixmap(QtGui.QPixmap(trademark_path))
33
34 ## Initialize table
35 self.initiBroadcastTable()
36
37 ## Define button callback events
38 self.ui.btn_broadcast.clicked.connect(self.broadcastNetworkEvent)
39
40 ## Create handle
41 self.dev = pywpc.DeviceFinder()
42
43 ## Connect to device
44 self.dev.connect()
45
46 ## Get Python driver version
47 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
48
49 ## Initialize list
50 self.broadcast_list=[]
51
52 def initiBroadcastTable(self): ## 5 for columns
53 for i in range(5):
54 self.ui.tableWidget_brst.setColumnWidth(i, COLUMN_WIDTH)
55 self.ui.tableWidget_brst.setStyleSheet("selection-background-color: #217536;")
56
57 def loaddata(self):
58 row = 0
59 self.ui.tableWidget_brst.setRowCount(len(self.broadcast_list))
60 for i in self.broadcast_list:
61 self.ui.tableWidget_brst.setItem(row, 0, QtWidgets.QTableWidgetItem(i["ip"]))
62 self.ui.tableWidget_brst.setItem(row, 1, QtWidgets.QTableWidgetItem(i["submask"]))
63 self.ui.tableWidget_brst.setItem(row, 2, QtWidgets.QTableWidgetItem(i["mac"]))
64 self.ui.tableWidget_brst.setItem(row, 3, QtWidgets.QTableWidgetItem(i["model"]))
65 self.ui.tableWidget_brst.setItem(row, 4, QtWidgets.QTableWidgetItem(i["firmware_ver"]))
66 row = row + 1
67 QApplication.restoreOverrideCursor()
68
69 def broadcastNetworkEvent(self):
70 ## Add WaitCursor
71 QApplication.setOverrideCursor(Qt.WaitCursor)
72
73 ## Clear Broadcast table
74 self.broadcast_list.clear()
75 self.ui.tableWidget_brst.setRowCount(0)
76
77 ## Perform device information
78 broadcast_info = self.dev.Bcst_enumerateNetworkDevices()
79 print(broadcast_info)
80
81 ## Return information length
82 device_amount = len(broadcast_info)
83 for i in range (device_amount):
84 ip = broadcast_info[i][0]
85 submask = broadcast_info[i][1]
86 mac = broadcast_info[i][2]
87 model_version = broadcast_info[i][3]
88 str_list = model_version.split('_')
89 model = str_list[0]
90 version = str_list[-1]
91 self.broadcast_list.append({'ip': ip , 'submask': submask, 'mac':mac, 'model': model, 'firmware_ver': version})
92 self.loaddata()
93
94 def closeEvent(self, event):
95 if self.dev is not None:
96 ## Disconnect device
97 self.dev.disconnect()
98
99 ## Release device handle
100 self.dev.close()
101
102if __name__ == "__main__":
103 app = QtWidgets.QApplication([])
104 WPC_main_ui = MainWindow()
105 WPC_main_ui.show()
106 sys.exit(app.exec_())