Device network info center

get_device_info_gui.PNG

  1##  Example_get_device_info/ main.py
  2##  This is an example for getting information 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 QMessageBox
 13from UI_design.Ui_example_GUI_get_device_info import Ui_MainWindow
 14
 15## WPC
 16from wpcsys import pywpc
 17
 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        self.ui.btn_deviceInfo.clicked.connect(self.getdeviceinfoEvent)
 51
 52    def selectHandle(self):
 53        handle_idx = int(self.ui.comboBox_handle.currentIndex())
 54        if handle_idx == 0:
 55            self.dev = pywpc.WifiDAQE3A()
 56        elif handle_idx == 1:
 57            self.dev = pywpc.EthanA()
 58        elif handle_idx == 2:
 59            self.dev = pywpc.EthanD()
 60
 61    def updateParam(self):
 62        ## Get IP or serial_number from GUI
 63        self.ip = self.ui.lineEdit_IP.text()
 64
 65    def connectEvent(self):
 66        if self.connect_flag == 1:
 67            return
 68
 69        ## Select handle
 70        self.selectHandle()
 71
 72        ## Update Param
 73        self.updateParam()
 74
 75        ## Connect to device
 76        try:
 77            self.dev.connect(self.ip)
 78        except pywpc.Error as err:
 79            print("err: " + str(err))
 80            return
 81
 82        ## Change LED status
 83        self.ui.lb_led.setPixmap(QtGui.QPixmap(self.blue_led_path))
 84
 85        ## Change connection flag
 86        self.connect_flag = 1
 87
 88    def disconnectEvent(self):
 89        if self.connect_flag == 0:
 90            return
 91
 92        ## Disconnect device
 93        self.dev.disconnect()
 94
 95        ## Change LED status
 96        self.ui.lb_led.setPixmap(QtGui.QPixmap(self.green_led_path))
 97
 98        ## Change connection flag
 99        self.connect_flag = 0
100
101    def closeEvent(self, event):
102        if self.dev is not None:
103            ## Disconnect device
104            self.dev.disconnect()
105
106            ## Release device handle
107            self.dev.close()
108
109    def getdeviceinfoEvent(self):
110        ## Check connection status
111        if self.checkConnectionStatus() == False:
112            return
113
114        ## Get firmware model & version
115        driver_info = self.dev.Sys_getDriverInfo()
116        model = driver_info[0]
117        version = driver_info[-1]
118
119        ## Get serial number & RTC Time
120        serial_number = self.dev.Sys_getSerialNumber()
121        rtc = self.dev.Sys_getRTC()
122
123        ## Get IP & submask & MAC
124        ip, submask = self.dev.Sys_getIPAddrAndSubmask()
125        mac = self.dev.Sys_getMACAddr()
126
127        ## Update information in GUI
128        self.ui.lineEdit_ip.setText(ip)
129        self.ui.lineEdit_sbk.setText(submask)
130        self.ui.lineEdit_serialNum.setText(serial_number)
131        self.ui.lineEdit_mac.setText(mac)
132        self.ui.lineEdit_model.setText(model)
133        self.ui.lineEdit_version.setText(version)
134        self.ui.lineEdit_rtc.setText(rtc)
135
136    ## Check TCP connection with QMessageBox
137    def checkConnectionStatus(self):
138        if self.connect_flag == 0:
139            QMessageBox.information(self, "Error Messages", "Please connect server first.", QMessageBox.Ok)
140            return False
141        else:
142            return True
143
144if __name__ == "__main__":
145    app = QtWidgets.QApplication([])
146    WPC_main_ui = MainWindow()
147    WPC_main_ui.show()
148    sys.exit(app.exec_())