linux LPT和COM回路测试(基于python+Qt+C++)

软件UI:

回路治具(COM+LPT):

lpt_test.cpp(c++ 源代码):

#include <iostream>
#include <fstream>
#include <sstream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/parport.h>
#include <linux/ppdev.h>
#include <string>
#include <map>//using namespace std;
int main() {// Use ANSI escape codes for coloring the outputconst char* RED = "\033[31m";   // Red color startconst char* GREEN = "\033[32m"; // Green color startconst char* RESET = "\033[0m";  // Reset to default colorstd::ifstream config_file("./Conf/lptconfig.txt");std::map<std::string, std::string> config;std::string line;unsigned char config_args_A;unsigned char config_args_B;unsigned char status;if (!config_file.is_open()) {std::cerr << "无法打开配置文件" << std::endl;return 1;}while (std::getline(config_file, line)) {std::istringstream is_line(line);std::string key;if (std::getline(is_line, key, '=')) {std::string value;if (std::getline(is_line, value)) {config[key] = value;}}}config_file.close();//const char* parport = config["parport"].c_str();config_args_A = static_cast<unsigned char>(std::stoi(config["Args_2"]));//读取参数1config_args_B=static_cast<unsigned char>(std::stoi(config["Args_1"]));//读取参数2const char* parport = "/dev/parport0";int fd = open(parport, O_RDWR);if (fd == -1) {std::cerr<<"无法打开并口设备 "<<parport<<std::endl;return 1;}if (ioctl(fd, PPCLAIM)) {std::cerr<<"无法获取并口的控制权"<<std::endl;close(fd);return 1;}// 发送数字1到并口50次for (int i = 0; i < 5; ++i) {// 写入数据unsigned char data = 1; // 要发送的数据if (ioctl(fd, PPWDATA, &data)) {std::cerr << "在写入数据 " << static_cast<int>(data) << " 时发生错误" << std::endl;break;}usleep(1000); // 延时以确保写入完成// 读取数据if (ioctl(fd, PPRSTATUS, &status)) {std::cerr << "在读取数据时发生错误" << std::endl;break;}std::cout << "写入 " << static_cast<int>(data) << ", 读取 " << static_cast<int>(status) << std::endl;}if (ioctl(fd, PPRELEASE)) {std::cerr << "无法释放并口控制权" << std::endl;}close(fd);if (static_cast<int>(config_args_A) == static_cast<int>(status)||static_cast<int>(config_args_B) == static_cast<int>(status)) {std::cout << GREEN << "Test PASS!!" << RESET << std::endl;return 0;}std::cout << RED << "Test FAIL!!" << RESET << std::endl;return 1;
}
COMLPTTest.py(Python+Qt源代码)
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'COMLPTTest.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.import sys
from PyQt5 import *
from PyQt5.Qt import *
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
import logging
import os
import json
import configparser
import serial
import subprocess
import io
import glob
import re#正则表达式
#pip install pyserialclass AnalysisThread(QtCore.QThread):test_result_signal = QtCore.pyqtSignal(tuple)  # 新增信号,传递一个包含设备路径和测试结果的元组def __init__(self, devicepath,type, parent=None):super(AnalysisThread, self).__init__(parent)self.devicepath = devicepathself.type=typeself.is_running = Truedef run(self):result = Falseif self.type == 'com':result = self.parent().ComTest(self.devicepath[1])if result:self.parent().rtsComTestPortInfo.remove(self.devicepath)self.parent().tsComTestPortInfops.append(self.devicepath)self.parent().TableAddItem(self.devicepath, True)  # 添加PASS数据self.parent().lbl_COMResult.setText(str(len(self.parent().tsComTestPortInfops)))self.parent().lbl_COMResult.setStyleSheet("background-color: lightgreen;")  # 后置端口背景色设置为浅绿色elif self.type == 'lpt':result = self.parent().LptTest(self.devicepath[1])if result:self.parent().rtsLptTestPortInfo.remove(self.devicepath)self.parent().tsLptTestPortInfops.append(self.devicepath)self.parent().TableAddItem(self.devicepath, True)  # 添加PASS数据self.parent().lbl_LPTResult.setText(str(len(self.parent().tsLptTestPortInfops)))self.parent().lbl_LPTResult.setStyleSheet("background-color: lightgreen;")  # 后置端口背景色设置为浅绿色self.test_result_signal.emit((self.devicepath, result))self.stop()# while self.is_running:#     # 在这里执行串口或者并口测试#     if self.type=='com':#串口测试#         if self.parent().ComTest(self.devicepath[1])==True:#             self.parent().rtsComTestPortInfo.remove(self.devicepath)#移除串口内容#             self.parent().tsComTestPortInfops.append(self.devicepath)#             self.parent().TableAddItem(self.devicepath,True)#添加PASS数据#             self.parent().lbl_COMResult.setText(str(len(self.parent().tsComTestPortInfops)))#             self.parent().lbl_COMResult.setStyleSheet("background-color: lightgreen;")  # 后置端口背景色设置为浅绿色#         else:#             self.parent().TableAddItem(self.devicepath,False)#添加FAIL数据#         result = self.parent().ComTest(self.devicepath[1])#         self.test_result_signal.emit((self.devicepath, result))#     elif self.type=='lpt':#并口测试#         if self.parent().LptTest(self.devicepath[1])==True:#             self.parent().rtsLptTestPortInfo.remove(self.devicepath)#移除LPT内容#             self.parent().tsLptTestPortInfops.append(self.devicepath)#             self.parent().TableAddItem(self.devicepath,True)#添加PASS数据#             self.parent().lbl_LPTResult.setText(str(len(self.parent().tsLptTestPortInfops)))#             self.parent().lbl_LPTResult.setStyleSheet("background-color: lightgreen;")  # 后置端口背景色设置为浅绿色#         else:#             self.parent().TableAddItem(self.devicepath,False)#添加FAIL数据#         result = self.parent().LptTest(self.devicepath[1])#         self.test_result_signal.emit((self.devicepath, result))#     #self.parent().AnalysisSoundFile_Frequency(self.filename,self.type)#     #self.parent().standard_frequency=int(self.parent().AnalysisSound_FrequencySample)#标准的频响#     self.stop()def stop(self):self.is_running = False # 或者使用更安全的停止逻辑class Ui_COMLPTTest(QWidget):updateTimer=pyqtSignal(bool)#def __init__(self):super().__init__()self.analysis_threads = []  # 存储所有的 AnalysisThread 实例#self.record_play_threads = []  # 存储所有的 RecordPlayThread 实例# 设置环境变量#os.environ["XDG_RUNTIME_DIR"] = "/run/user/{}".format(os.getuid())self.config = configparser.ConfigParser()  # 创建对象self.itemName = ''  # 项目名称self.itemFailSleepExit = 0  # 项目Fail延时退出self.testArgs = []  # 测试参数信息self.testStandardArgs=''#测试准标参数self.ComTestCount=1# COM测试数self.LptTestCount=1# LPT测试数self.testModel=True#设置为自动测试模式self.tbrowIndex=0#表单指针#测试PASS接口self.tsComTestPortInfops=[]#测试PASS COM接口self.tsLptTestPortInfops=[]#测试PASS LPT接口# 检测到串口信息self.rtsComTestPortInfo=[]#读取COM接口self.rtsLptTestPortInfo=[]#读取Lpt接口# 生成日志信息self.logger = logging.getLogger('my_logger')  # 步骤1 创建日志记录器self.logger.setLevel(logging.DEBUG)  # 步骤2 将指定日志级别self.file_handler = logging.FileHandler('./log/log.txt')  # 步骤3 创建文件处理器self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')  # 步骤4 创建格式化器self.file_handler.setFormatter(self.formatter)  # 步骤4 将格式化器添加到处理器self.logger.addHandler(self.file_handler)  # 步骤5 将处理器添加到日志记录器# 读取配置self.config.read('./Conf/config.conf', encoding='utf-8')  # 读取配置文件,如果配置文件不存在则创建# 读取测试配置self.itemName = self.config.get('TestItemNameArrays', 'COMLPTTestName')  # 项目名称self.itemFailSleepExit = int(self.config.get('TestItemWinFrmSleepExit', 'COMLPTTestName'))  # 项目测试Fail延时退出self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')  # 读取测试参数信息if self.ReadJsonTestArgs(self.itemName)==True:#获取标准参数testArgs=[]#测试参数testArgs=self.testStandardArgs.split('|')comArgs=testArgs[0]#分割com测试参数lptArgs=testArgs[1]#分割lpt测试参数testModel=testArgs[2]#分割测试模式self.ComTestCount=int(comArgs[comArgs.find('=') + 1:])self.LptTestCount=int(lptArgs[lptArgs.find('=') + 1:])testModel=testModel[testModel.find('=') + 1:]if testModel=='True':self.testModel=Trueelse:self.testModel=Falseself.setupUi()  # 初始化if self.GetTestPortInfo()==True:#获取测试COM和LPT接口信息# 创建一个定时器来检查视频是否播放结束self.timer = QTimer(self)self.timer.setInterval(1000)  # 每秒检查一次self.timer.timeout.connect(self.check_Test)self.timer.start()# 连接信号到槽self.updateTimer.connect(self.handleTimer)# 启动线程#self.start_analysis_threads()else:sys.exit(1)#校验是否完成测试def check_Test(self):try:if self.ComTestCount==len(self.tsComTestPortInfops) and self.LptTestCount==len(self.tsLptTestPortInfops):#判断测试PASSself.UpdateJsonTestArgs(self.itemName,f" COM ={str(len(self.tsComTestPortInfops))}|LPT ={str(len(self.tsLptTestPortInfops))}|TestModel = str({self.testModel})",'PASS')sys.exit(0)else:self.updateTimer.emit(False)  # 发射信号以停止定时器self.start_analysis_threads()#self.RecordPlay_analysis_threads()except Exception as e:self.ShowLog(f"check_Test Err:{e}", False)return False# 定义触发器def handleTimer(self, start):if start:self.timer.start()else:self.timer.stop()# 启动多线程def start_analysis_threads(self):# 创建多个线程self.threads = []#print("Starting COM threads")  # 调试信息for comDev in self.rtsComTestPortInfo:#遍历COM硬件信息#print(f"Starting COM thread for {comDev}")  # 调试信息thread=AnalysisThread(comDev,'com',self)thread.test_result_signal.connect(self.handle_test_result)  # 连接信号thread.start()self.threads.append(thread)self.analysis_threads.append(thread)#print("Starting LPT threads")  # 调试信息for lptDev in self.rtsLptTestPortInfo:#遍历LPT硬件信息#print(f"Starting LPT thread for {lptDev}")  # 调试信息thread=AnalysisThread(lptDev,'lpt',self)thread.test_result_signal.connect(self.handle_test_result)  # 连接信号thread.start()self.threads.append(thread)self.analysis_threads.append(thread)self.updateTimer.emit(True)  # 启动时钟def handle_test_result(self, result):devicepath, isPass = result# if isPass:#     # 更新UI的逻辑#     self.TableAddItem(devicepath, True)# else:#     self.TableAddItem(devicepath, False)devicepath, isPass = resultself.TableAddItem(devicepath, isPass)#日志信息栏添加数据 port:端口信息,isPass:测试结果# def TableAddItem(self,port,isPass):#     # 检查设备是否已经在表格中#     for rowIndex in range(self.tableWidget.rowCount()):#         if self.tableWidget.item(rowIndex, 1).text() == port[0] and self.tableWidget.item(rowIndex, 2).text() ==port[1]:#             return  # 如果已存在,则不添加#     newItem=QTableWidgetItem(str(self.tbrowIndex+1))#     newItem.setTextAlignment(Qt.AlignCenter)  # 文本内容居中#     self.tableWidget.setItem(self.tbrowIndex,0,newItem)#     newItem = QTableWidgetItem(port[0])#     newItem.setTextAlignment(Qt.AlignCenter)  # 文本内容居中#     self.tableWidget.setItem(self.tbrowIndex, 1, newItem)#     newItem = QTableWidgetItem(port[1])#     newItem.setTextAlignment(Qt.AlignCenter)  # 文本内容居中#     self.tableWidget.setItem(self.tbrowIndex,2,newItem)#     testResult='PASS'#     if isPass==False:#         testResult='FAIL'#     newItem=QTableWidgetItem(testResult)#     newItem.setTextAlignment(Qt.AlignCenter)  # 文本内容居中#     self.tableWidget.setItem(self.tbrowIndex,3,newItem)#     if testResult=='PASS':#         self.tableWidget.item(self.tbrowIndex, 3).setForeground(QtGui.QColor(51, 204, 51))#         self.tbrowIndex+=1#     else:#         self.tableWidget.item(self.tbrowIndex, 3).setForeground(QtGui.QColor(255, 51, 51))def TableAddItem(self, port, isPass):# 检查设备是否已经在表格中for rowIndex in range(self.tableWidget.rowCount()):if self.tableWidget.item(rowIndex, 1) and self.tableWidget.item(rowIndex, 2):if self.tableWidget.item(rowIndex, 1).text() == port[0] and self.tableWidget.item(rowIndex, 2).text() == \port[1]:# 更新现有行的测试结果testResult = 'PASS' if isPass else 'FAIL'self.tableWidget.item(rowIndex, 3).setText(testResult)if testResult == 'PASS':self.tableWidget.item(rowIndex, 3).setForeground(QtGui.QColor(51, 204, 51))else:self.tableWidget.item(rowIndex, 3).setForeground(QtGui.QColor(255, 51, 51))return# 添加新项目newItem = QTableWidgetItem(str(self.tbrowIndex + 1))newItem.setTextAlignment(Qt.AlignCenter)self.tableWidget.setItem(self.tbrowIndex, 0, newItem)newItem = QTableWidgetItem(port[0])newItem.setTextAlignment(Qt.AlignCenter)self.tableWidget.setItem(self.tbrowIndex, 1, newItem)newItem = QTableWidgetItem(port[1])newItem.setTextAlignment(Qt.AlignCenter)self.tableWidget.setItem(self.tbrowIndex, 2, newItem)testResult = 'PASS' if isPass else 'FAIL'newItem = QTableWidgetItem(testResult)newItem.setTextAlignment(Qt.AlignCenter)self.tableWidget.setItem(self.tbrowIndex, 3, newItem)if testResult == 'PASS':self.tableWidget.item(self.tbrowIndex, 3).setForeground(QtGui.QColor(51, 204, 51))else:self.tableWidget.item(self.tbrowIndex, 3).setForeground(QtGui.QColor(255, 51, 51))self.tbrowIndex += 1#LPT测试def LptTest(self,port):try:# 获取COM硬件信息lpttest = subprocess.Popen('./lpt_test', stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True, encoding='utf-8')lpt_output,_=lpttest.communicate()#获取输出#判断结果是否为PASSdef JudgeIsPass(output):for line in output.split('\n'):if line.strip():  # 确保行不是空的if 'Test PASS' in line:return Trueelse:#print(f'{port} Test Fail!!')return Falsereturn JudgeIsPass(lpt_output)except Exception as e:self.ShowLog(f"Lpt Test Err:{e}", False)return False#串口测试def ComTest(self,port):serial_port = serial.Serial(port=port,baudrate=115200,bytesize=serial.EIGHTBITS,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,timeout=0.5)try:self.lbl_Console.setText(f'{port} Test')serial_port.write("2".encode())if int(str(serial_port.read())[2:3]) == 2:self.lbl_Result.setText("测试中..")return Trueelse:return Falseexcept KeyboardInterrupt:print("Exiting Program")except Exception as exception_err:self.ShowLog(f"Error occurred. Exiting Program:{str(exception_err)}", False)finally:serial_port.close()#获取当前测试端口def GetTestPortInfo(self):try:self.rtsComTestPortInfo.clear()  # 清空COM存放硬件容器self.rtsLptTestPortInfo.clear()  # 清空LPT存放硬件容器# 获取COM硬件信息process_com = subprocess.Popen('dmesg | grep tty', stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True, encoding='utf-8')com_output, _ = process_com.communicate()  # 获取输出# 获取LPT硬件信息process_lpt = subprocess.Popen('dmesg | grep lp0', stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True, encoding='utf-8')lpt_output, _ = process_lpt.communicate()  # 获取输出#截取字符串def extract_tty_devices(log_data):# 使用正则表达式匹配 ttyS*, ttyUSB*, 和 lpt* 设备pattern = r"(ttyS\d+|ttyUSB\d+|lp\d+)"devices = re.findall(pattern, log_data)if devices:#检查列表是否为空return devices[0]else:return None# 解析输出硬件信息def GetDeviceInfo(output):device_names = []for line in output.split('\n'):if line.strip():  # 确保行不是空的parts =extract_tty_devices(line)#parts = line.split()  # 分割每一行if parts:device_names.append(f'/dev/{parts}')  # 假设设备名称是每行的第一个元素return device_names# 移除重复的字符串def remove_duplicates_keep_order(lst,type):seen = set()result = []i=1for item in lst:if item not in seen:seen.add(item)result.append((f'{type}{str(i)}',item))i+=1return resultself.rtsComTestPortInfo = remove_duplicates_keep_order(GetDeviceInfo(com_output),'COM')self.rtsLptTestPortInfo = remove_duplicates_keep_order(GetDeviceInfo(lpt_output),'LPT')return Trueexcept Exception as e:self.ShowLog(f"GetTestPortInfo Err:{e}", False)return Falsedef setupUi(self):self.setObjectName("COMLPTTest")self.resize(845, 835)icon = QtGui.QIcon()icon.addPixmap(QtGui.QPixmap("IMAGE/Serial.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)self.setWindowIcon(icon)self.gridLayout = QtWidgets.QGridLayout(self)self.gridLayout.setObjectName("gridLayout")self.verticalLayout = QtWidgets.QVBoxLayout()self.verticalLayout.setObjectName("verticalLayout")self.horizontalLayout_2 = QtWidgets.QHBoxLayout()self.horizontalLayout_2.setObjectName("horizontalLayout_2")self.verticalLayout_2 = QtWidgets.QVBoxLayout()self.verticalLayout_2.setObjectName("verticalLayout_2")self.lbl_Logo = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_Logo.setFont(font)self.lbl_Logo.setText("")self.lbl_Logo.setPixmap(QtGui.QPixmap("IMAGE/logo.jpg"))self.lbl_Logo.setAlignment(QtCore.Qt.AlignCenter)self.lbl_Logo.setObjectName("lbl_Logo")self.verticalLayout_2.addWidget(self.lbl_Logo)self.label_4 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_4.setFont(font)self.label_4.setText("")self.label_4.setAlignment(QtCore.Qt.AlignCenter)self.label_4.setObjectName("label_4")self.verticalLayout_2.addWidget(self.label_4)self.horizontalLayout_2.addLayout(self.verticalLayout_2)self.verticalLayout_3 = QtWidgets.QVBoxLayout()self.verticalLayout_3.setObjectName("verticalLayout_3")self.label_6 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_6.setFont(font)self.label_6.setStyleSheet("background-color: rgb(170, 170, 127);\n"
"color: rgb(255, 255, 255);")self.label_6.setAlignment(QtCore.Qt.AlignCenter)self.label_6.setObjectName("label_6")self.verticalLayout_3.addWidget(self.label_6)self.lbl_Console = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_Console.setFont(font)self.lbl_Console.setStyleSheet("background-color: rgb(85, 255, 127);")self.lbl_Console.setAlignment(QtCore.Qt.AlignCenter)self.lbl_Console.setObjectName("lbl_Console")self.verticalLayout_3.addWidget(self.lbl_Console)self.horizontalLayout_2.addLayout(self.verticalLayout_3)self.horizontalLayout_4 = QtWidgets.QHBoxLayout()self.horizontalLayout_4.setObjectName("horizontalLayout_4")self.verticalLayout_7 = QtWidgets.QVBoxLayout()self.verticalLayout_7.setObjectName("verticalLayout_7")self.label_8 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_8.setFont(font)self.label_8.setStyleSheet("background-color: rgb(170, 170, 127);\n"
"color: rgb(255, 255, 255);")self.label_8.setAlignment(QtCore.Qt.AlignCenter)self.label_8.setObjectName("label_8")self.verticalLayout_7.addWidget(self.label_8)self.lbl_TestModel = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_TestModel.setFont(font)self.lbl_TestModel.setStyleSheet("background-color: rgb(255, 170, 127);")self.lbl_TestModel.setAlignment(QtCore.Qt.AlignCenter)self.lbl_TestModel.setObjectName("lbl_TestModel")self.verticalLayout_7.addWidget(self.lbl_TestModel)self.horizontalLayout_4.addLayout(self.verticalLayout_7)self.horizontalLayout_2.addLayout(self.horizontalLayout_4)self.verticalLayout_5 = QtWidgets.QVBoxLayout()self.verticalLayout_5.setObjectName("verticalLayout_5")self.label = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label.setFont(font)self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)self.label.setObjectName("label")self.verticalLayout_5.addWidget(self.label)self.label_7 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_7.setFont(font)self.label_7.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)self.label_7.setObjectName("label_7")self.verticalLayout_5.addWidget(self.label_7)self.label_2 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_2.setFont(font)self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)self.label_2.setObjectName("label_2")self.verticalLayout_5.addWidget(self.label_2)self.horizontalLayout_2.addLayout(self.verticalLayout_5)self.verticalLayout_4 = QtWidgets.QVBoxLayout()self.verticalLayout_4.setObjectName("verticalLayout_4")self.label_12 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_12.setFont(font)self.label_12.setAlignment(QtCore.Qt.AlignCenter)self.label_12.setObjectName("label_12")self.verticalLayout_4.addWidget(self.label_12)self.lbl_LPTArgs = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_LPTArgs.setFont(font)self.lbl_LPTArgs.setAlignment(QtCore.Qt.AlignCenter)self.lbl_LPTArgs.setObjectName("lbl_LPTArgs")self.verticalLayout_4.addWidget(self.lbl_LPTArgs)self.lbl_LPTResult = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_LPTResult.setFont(font)self.lbl_LPTResult.setAlignment(QtCore.Qt.AlignCenter)self.lbl_LPTResult.setObjectName("lbl_LPTResult")self.verticalLayout_4.addWidget(self.lbl_LPTResult)self.horizontalLayout_2.addLayout(self.verticalLayout_4)self.verticalLayout_6 = QtWidgets.QVBoxLayout()self.verticalLayout_6.setObjectName("verticalLayout_6")self.label_9 = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.label_9.setFont(font)self.label_9.setAlignment(QtCore.Qt.AlignCenter)self.label_9.setObjectName("label_9")self.verticalLayout_6.addWidget(self.label_9)self.lbl_COMArgs = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_COMArgs.setFont(font)self.lbl_COMArgs.setAlignment(QtCore.Qt.AlignCenter)self.lbl_COMArgs.setObjectName("lbl_COMArgs")self.verticalLayout_6.addWidget(self.lbl_COMArgs)self.lbl_COMResult = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(12)self.lbl_COMResult.setFont(font)self.lbl_COMResult.setAlignment(QtCore.Qt.AlignCenter)self.lbl_COMResult.setObjectName("lbl_COMResult")self.verticalLayout_6.addWidget(self.lbl_COMResult)self.horizontalLayout_2.addLayout(self.verticalLayout_6)self.verticalLayout.addLayout(self.horizontalLayout_2)self.verticalLayout_9 = QtWidgets.QVBoxLayout()self.verticalLayout_9.setObjectName("verticalLayout_9")self.tableWidget = QtWidgets.QTableWidget(self)self.tableWidget.setObjectName("tableWidget")self.tableWidget.setColumnCount(4)self.tableWidget.setRowCount(self.ComTestCount+self.LptTestCount)#设置表格行数self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)item = QtWidgets.QTableWidgetItem()font = QtGui.QFont()font.setPointSize(11)item.setFont(font)item.setBackground(QtGui.QColor(170, 170, 255))self.tableWidget.setHorizontalHeaderItem(0, item)self.tableWidget.setFont(font)item = QtWidgets.QTableWidgetItem()font = QtGui.QFont()font.setPointSize(11)item.setFont(font)item.setBackground(QtGui.QColor(170, 255, 127))self.tableWidget.setHorizontalHeaderItem(1, item)item = QtWidgets.QTableWidgetItem()font = QtGui.QFont()font.setPointSize(11)item.setFont(font)item.setBackground(QtGui.QColor(255, 170, 127))self.tableWidget.setHorizontalHeaderItem(2, item)item = QtWidgets.QTableWidgetItem()font = QtGui.QFont()font.setPointSize(11)item.setFont(font)item.setBackground(QtGui.QColor(170, 170, 127))self.tableWidget.setHorizontalHeaderItem(3, item)self.verticalLayout_9.addWidget(self.tableWidget)self.verticalLayout.addLayout(self.verticalLayout_9)self.lbl_Result = QtWidgets.QLabel(self)font = QtGui.QFont()font.setPointSize(22)self.lbl_Result.setFont(font)self.lbl_Result.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(170, 255, 127);")self.lbl_Result.setAlignment(QtCore.Qt.AlignCenter)self.lbl_Result.setObjectName("lbl_Result")self.verticalLayout.addWidget(self.lbl_Result)self.horizontalLayout_3 = QtWidgets.QHBoxLayout()self.horizontalLayout_3.setObjectName("horizontalLayout_3")self.verticalLayout.addLayout(self.horizontalLayout_3)self.gridLayout.addLayout(self.verticalLayout, 1, 0, 1, 1)self.retranslateUi()QtCore.QMetaObject.connectSlotsByName(self)self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint)  # 只显示最小化按钮和关闭按钮def retranslateUi(self):_translate = QtCore.QCoreApplication.translateself.setWindowTitle(_translate("COMLPTTest", "COMLPTTest"))self.label_6.setText(_translate("COMLPTTest", "控制过程"))self.lbl_Console.setText(_translate("COMLPTTest", "当前COM1测试"))self.label_8.setText(_translate("COMLPTTest", "测试模式"))if self.testModel==True:self.lbl_TestModel.setText(_translate("COMLPTTest", "自动"))else:self.lbl_TestModel.setText(_translate("COMLPTTest", "单步"))self.label.setText(_translate("COMLPTTest", "接口名称:"))self.label_7.setText(_translate("COMLPTTest", "设置参数:"))self.label_2.setText(_translate("COMLPTTest", "测试结果:"))self.label_12.setText(_translate("COMLPTTest", "LPT"))self.lbl_LPTArgs.setText(_translate("COMLPTTest", str(self.LptTestCount)))self.lbl_LPTResult.setText(_translate("COMLPTTest", "N/A"))self.label_9.setText(_translate("COMLPTTest", "COM"))self.lbl_COMArgs.setText(_translate("COMLPTTest", str(self.ComTestCount)))self.lbl_COMResult.setText(_translate("COMLPTTest", "N/A"))item = self.tableWidget.horizontalHeaderItem(0)item.setText(_translate("COMLPTTest", "NO"))item = self.tableWidget.horizontalHeaderItem(1)item.setText(_translate("COMLPTTest", "项目名称"))item = self.tableWidget.horizontalHeaderItem(2)item.setText(_translate("COMLPTTest", "端口号"))item = self.tableWidget.horizontalHeaderItem(3)item.setText(_translate("COMLPTTest", "测试结果"))self.lbl_Result.setText(_translate("COMLPTTest", "测试中.."))self.tableWidget.setColumnWidth(0, 60)self.tableWidget.setColumnWidth(1, 220)self.tableWidget.setColumnWidth(2, 250)self.tableWidget.setColumnWidth(3, 260)self.tableWidget.setShowGrid(False)  # 是否显示网线self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)  # 表格状态只读self.tableWidget.clicked.connect(self.TestThread)  # 表单,单击事件# 读取项目参数信息,itemName:项目名称def ReadJsonTestArgs(self, itemName):try:self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')for js in self.testArgs:if itemName in js['ItemName']:self.testStandardArgs = js['Standard']return Trueself.ShowLog('Read TestArgs.json ItemName:' + itemName + ' Info Is Empty!!', False)sys.exit(1)except Exception as e:self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)sys.exit(1)#读取json信息def ReadJsonInfo(self,fileName):try:if os.path.exists(fileName):f=open(fileName,'r',encoding='utf-8')return json.loads(f.read())except Exception as e:self.ShowLog("Read "+fileName+" Err:" + str(e),False)sys.exit(1)#手动关闭窗口def closeEvent(self, event):# 创建一个消息框,上面有两个按钮:“是”和“否”#reply = QMessageBox.question(self, '退出', "你确定要退出吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)# 如果用户点击了“是”,则执行event.accept()来关闭窗口#if reply == QMessageBox.Yes:#    event.accept()#    sys.exit(1)#else:# 如果用户点击了“否”,则忽略event,不关闭窗口#    event.ignore()sys.exit(1)# 定义一个函数使得函数窗口居中显示def Center(self):# 获取屏幕尺寸screen_geometry = app.desktop().availableGeometry()# 计算窗口居中位置x = (screen_geometry.width() - self.width()) // 2y = (screen_geometry.height() - self.height()) // 2# 设置窗口位置self.move(x, y)# 打印的信息def ShowLog(self, log, isPass):try:if isPass == True:self.lbl_Result.setStyleSheet("color:green;")self.logger.info(str(log))self.lbl_Result.setText("TEST PASS")else:self.lbl_Result.setStyleSheet("color:red;")self.logger.error(str(log))self.lbl_Result.setText("TEST FAIL")except Exception as e:print("\033[1;31m" + str(e) + " \033[0m")sys.exit(1)# 更新测试参数json,itemName:项目名称,readValue:读取值,testResult:测试结果def UpdateJsonTestArgs(self, itemName, readValue, testResult):try:updateTestArgs = []  # 更新的测试参数self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')for js in self.testArgs:if itemName in js['ItemName']:js['Read'] = readValue  # 读取的值js['TestResult'] = testResult  # 测试结果updateTestArgs.append(js)else:updateTestArgs.append(js)with open("./Conf/TestArgs.json", "w") as write_file:json.dump(updateTestArgs, write_file)return Trueexcept Exception as e:self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)sys.exit(1)#启动线重脚本def TestThread(self):pass#self.t_autoplay=Thread(target=self.Test)#self.t_autoplay.start()if __name__=='__main__':app=QApplication(sys.argv)win=Ui_COMLPTTest()win.Center()  # 居中win.show()sys.exit(app.exec_())

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/242620.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【cucumber】cluecumber-report-plugin生成测试报告

cluecumber为生成测试报告的第三方插件&#xff0c;可以生成html测报&#xff0c;该测报生成需以本地json测报的生成为基础。 所以需要在测试开始主文件标签CucumberOptions中&#xff0c;写入生成json报告。 2. pom xml文件中加入插件 <!-- 根据 cucumber json文件 美化测…

ckman:非常好用的ClickHouse可视化集群运维工具

概述 什么是ckman ckman&#xff0c;全称是ClickHouse Management Console&#xff0c; 即ClickHouse管理平台。它是由擎创科技数据库团队主导研发的一款用来管理和监控ClickHouse集群的可视化运维工具。目前该工具已在github上开源&#xff0c;开源地址为&#xff1a;github…

YOLOv8改进 | Conv篇 | 在线重参数化卷积OREPA助力二次创新(提高推理速度 + FPS)

一、本文介绍 本文给大家带来的改进机制是一种重参数化的卷积模块OREPA,这种重参数化模块非常适合用于二次创新,我们可以将其替换网络中的其它卷积模块可以不影响推理速度的同时让模型学习到更多的特征。OREPA是通过在线卷积重参数化(Online Convolutional Re-parameteriza…

2024最新 8 款电脑数据恢复软件推荐分享

数据恢复是一个涉及从设备硬盘驱动器检索已删除文件的过程。这可能需要存储在工作站、笔记本电脑、移动设备、服务器、相机、闪存驱动器上的数据——任何在独立或镜像/阵列驱动器上存储数据的东西&#xff0c;无论是内部还是外部。 在某些情况下&#xff0c;文件可能被意外或故…

Pytest 测试框架与Allure 测试报告——Allure2测试报告-L3

目录&#xff1a; allure2报告中添加附件-图片 Allure2报告中添加附件Allure2报告中添加附件&#xff08;图片&#xff09;应用场景Allure2报告中添加附件&#xff08;图片&#xff09;-Python代码示例&#xff1a;allure2报告中添加附件-日志 Allure2报告中添加附件&#xff…

GEE:随机森林回归器投票方法的优化与修改

作者:CSDN @ _养乐多_ 在随机森林中,随机生成的每棵决策树都对输入数据进行分类或回归,并产生一个输出。对于分类问题,这个输出通常是一个类别标签 ,而对于回归问题,输出通常是一个连续的数值。例如,如果有五棵树的分类输出为 [0.1, 0.2, 0.3, 0.1, 0.1],则平均数是0.…

SpringBoot SaToken Filter如用使用ControllerAdvice统一异常拦截

其实所有的Filter都是一样的原理 大致流程: 创建一个自定义Filter, 用于拦截所有异常此Filter正常进行后续Filter调用当调用后续Filter时, 如果发生异常, 则委托给HandlerExceptionResolver进行后续处理即可 以sa-token的SaServletFilter为例 首先注册SaToken的过滤器 pac…

【51单片机】矩阵按键

0、前言 参考&#xff1a;普中 51 单片机开发攻略 1、硬件 2、软件 main.c #include <reg52.h> #include <intrins.h> #include "delayms.h"typedef unsigned int u16; //对数据类型进行声明定义 typedef unsigned char u8; #define GPIO_KEY P1 #d…

ADSelfService Plus 推出离线多因素身份验证以提升远程工作安全性

采用先进验证方法&#xff0c;确保在任何时间、地点或连接问题下对业务数据的合法访问即使远程用户未连接到身份验证服务器或互联网&#xff0c;也可通过MFA安全认证。 MFA 得克萨斯州德尔瓦雷 — 2023年5月3日 — Zoho Corporation 旗下的企业IT管理部门ManageEngine今日宣布…

web渗透安全学习笔记:2、HTML基础知识

目录 前言 HTML的标题 段落链接与插入图片 HTML元素 HTML属性 HTML头部 HTML与CSS HTML与JavaScript 表格与列表 HTML区块 布局 HTML表单 HTML与数据库 音频与视频 HTML事件 前言 HTML的标题 <!DOCTYPE html> <html> <head> <meta chars…

《WebKit 技术内幕》之七(3): 渲染基础

3 渲染方式 3.1 绘图上下文&#xff08;GraphicsContext&#xff09; 上面介绍了WebKit的内部表示结构&#xff0c;RenderObject对象知道如何绘制自己&#xff0c;但是&#xff0c;问题是RenderObject对象用什么来绘制内容呢&#xff1f;在WebKit中&#xff0c;绘图操作被定…

算法第二十一天-丑数

丑数 题目要求 解题思路 首先判断数字是不是为0或者负数&#xff0c;两者均不可能成为丑数&#xff1b; 之后对n进行不断整除&#xff0c;直到无法除尽为止。 简单判断最后的数是不是1即可。 代码 class Solution:def isUgly(self, n: int) -> bool:if n<0:return Fa…

React的合成事件

合成事件&#xff1a;通过事件委托&#xff0c;利用事件传播机制&#xff0c;当事件传播到document时&#xff0c;再进行分发到对应的组件&#xff0c;从而触发对应所绑定的事件&#xff0c;然后事件开始在组件树DOM中走捕获冒泡流程。 原生事件 —— > React事件 —— >…

力扣每日一练(24-1-20)

大脑里的第一想法是排列组合&#xff0c;直接给出超级准确的最优解。 但不适用&#xff0c;hhh 只要连续的n个元素大于或者等于target就可以了 题目比自己想象的要好解决 解法是使用滑动窗口算法。这个算法的基本思想是维护一个窗口&#xff0c;使得窗口内的元素总和大于等于目…

MySQL---单表查询综合练习

创建emp表 CREATE TABLE emp( empno INT(4) NOT NULL COMMENT 员工编号, ename VARCHAR(10) COMMENT 员工名字, job VARCHAR(10) COMMENT 职位, mgr INT(4) COMMENT 上司, hiredate DATE COMMENT 入职时间, sal INT(7) COMMENT 基本工资, comm INT(7) COMMENT 补贴, deptno INT…

PostgreSQL命令大全

文章目录 连接与退出数据库操作表操作外键约束视图操作存储过程与函数权限管理事务管理查询优化与分析数据类型转换分区表操作复制与备份恢复 PostgreSQL是一个功能强大的开源关系型数据库管理系统&#xff0c;以下是一些基本且常用的命令按功能分类&#xff1a; 连接与退出 连…

Es bulk批量导入数据(1w+以上)

最近在学习es的理论知识以及实际操作&#xff0c;随时更新~ 概要&#xff1a;首先你得有1w条数据的json&#xff0c;然后用java读取json文件导入 一. 创建Json数据 首先我生成1.5w条数据&#xff0c;是为了实践分页查询&#xff0c;用from-size和scroll翻页去实践 生成四个字段…

Servlet系列:生命周期(init、 service、destroy)详解

Servlet的生命周期是由Web容器&#xff08;如Tomcat&#xff09;管理的&#xff0c;包括以下三个阶段&#xff1a; 加载和实例化&#xff1a;当Web应用程序启动时&#xff0c;Web容器会加载和实例化Servlet。加载和实例化过程可以在应用程序启动时自动完成&#xff0c;也可以通…

Nginx快速入门

1.Ngix介绍 1.1 介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器&#xff0c;同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔赛索耶夫为俄罗斯访问量第二的Rambler.ru站点&#xff08;俄文&#xff1a;Рамблер&#xff09;开发的&#xff0c;第一个公…

2.RHCSA启动配置

rht-clearcourse 0 #重置练习环境 rht-setcourse rh134 #切换CSA练习环境 cat /etc/rht #查看当前环境 virt-manager #打开KVM控制台 rht-vmctl start classroom #必做&#xff0c;start all不会包含classroom&#xff0c;需…