注意:
这种情况适用于多个线程,每个线程中有多个测试的情况
可以使用定时器
每个测试项中都加入定时器,没有点击暂停按钮的时候,测试项中的定时器每隔1ms就暂停,恢复
点击按钮后,定时器被set,线程暂停
from datetime import datetime
import os
from unittest import case
import threading
from threading import Event
import pyvisa
import serial
from PyQt5.QtCore import QSize, QDateTime, QTimer, QThread, pyqtSignal, QMutex, QEvent, QWaitCondition
from PyQt5.QtGui import QPixmap, QIcon, QColor
from openpyxl.styles import Font
from Inner_Test import InnerTest
from R1553B_Test import R1553BTest
from R429_Test import R429Test
from Can_Test import CanTest
from R422_Test import R422Test
from PWM_Test import PWMTest
from IO_Test import IOTest
from Sim_Out_Test import SOutTest
from Sim_In_Test import SInTest
from SPI_Test import SPITest
import sys
import threading
import time
import openpyxl
from PyQt5 import uic, QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidgetItem, QCheckBox
import os, PyQt5
dirname = os.path.dirname(PyQt5.__file__)
qt_dir = os.path.join(dirname, 'Qt5', 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qt_dir
class TestThread(threading.Thread):
def __init__(self, test_function, event):
super().__init__()
self.test_function = test_function
self.pause_event = event
self.stopped = False
def run(self):
while not self.stopped:
if self.pause_event.is_set():
self.test_function()
self.pause_event.clear() # 重置事件,等待下一次触发
def pause(self):
self.pause_event.clear()
def resume(self):
self.pause_event.set()
def stop(self):
self.stopped = True
self.stopped = True
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.ui_start_test = uic.loadUi("PySerial_index.ui")
self.all_selected = False
self.excel_checkbox_1 = []
self.excel_checkbox_2 = []
self.tests1 = []
self.tests2 = []
self.tests_thread1 = []
self.tests_thread2 = []
self.timer1 = QTimer(self)
self.timer1.timeout.connect(self.timer_event1)
self.timer1.setInterval(1) # 1ms
self.timer2 = QTimer(self)
self.timer2.timeout.connect(self.timer_event2)
self.timer2.setInterval(1) # 1ms
self.pause_event1 = threading.Event()
self.pause_event2 = threading.Event()
# 连接信号和槽
self.ui_start_test.TestButton.clicked.connect(self.start_threads)
self.ui_start_test.pause_1.clicked.connect(self.pauseButtonClicked1)
self.ui_start_test.pause_2.clicked.connect(self.pauseButtonClicked2)
def start_threads(self):
# self.save_settings()
self.perform_test()
def perform_test(self):
# 获取复选框状态
cb1_checked = self.ui_start_test.checkBox_1.isChecked()
gw1_checked = self.ui_start_test.gw_1.isChecked()
gw2_checked = self.ui_start_test.gw_2.isChecked()
if cb1_checked:
if gw1_checked:
self.tests1.append(self.Normal_Test_1)
if gw2_checked:
self.tests2.append(self.Normal_Test_2)
# # 创建测试队列
# test_queue1 = list(self.tests1)
# test_queue2 = list(self.tests2)
#
# # 创建并启动线程
# self.thread1 = TestThread(test_queue1,self.event)
# self.thread2 = TestThread(test_queue2,self.event)
for test_function in self.tests1:
thread = TestThread(test_function, self.pause_event1)
self.tests_thread1.append(thread)
thread.setDaemon(True)
thread.start()
for test_function in self.tests2:
thread = TestThread(test_function, self.pause_event2)
self.tests_thread2.append(thread)
thread.setDaemon(True)
thread.start()
self.timer1.start()
self.timer2.start()
def Normal_Test_1(self):
def Inner(self):
self.ui_start_test.Ptext1.append("\n内部定时器设计测试")
flag_right_4 = 0
flag_wrong_4 = 0
Inner_test_1 = InnerTest()
test_result = Inner_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n内部定时器设计测试成功")
flag_right_4 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n内部定时器设计测试失败")
flag_wrong_4 += 1
Inner_test_1.close_1()
if flag_right_4 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(2, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_4 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(2, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(2, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
Inner(self)
def R1553B(self):
self.ui_start_test.Ptext1.append("\n开始1553B接口测试——产品端为RT")
flag_right_5 = 0
flag_wrong_5 = 0
R1553B_test_1 = R1553BTest()
test_result = R1553B_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n1553B接口测试——BC-RT测试成功")
flag_right_5 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n1553B接口测试——BC-RT测试失败")
flag_wrong_5 += 1
R1553B_test_1.close_1()
if flag_right_5 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(3, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_5 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(3, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(3, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
R1553B(self)
def R429(self):
self.ui_start_test.Ptext1.append("\n开始429接口测试")
flag_right_6 = 0
flag_wrong_6 = 0
R429_test_1 = R429Test()
test_result = R429_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n429接口测试——第一项测试成功")
flag_right_6 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n429接口测试——第一项测试失败")
flag_wrong_6 += 1
R429_test_1.close_1()
if flag_right_6 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(3, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_6 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(4, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(4, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
R429(self)
def can(self):
self.ui_start_test.Ptext1.append("\n开始CAN测试")
flag_right_7 = 0
flag_wrong_7 = 0
can_test_1 = CanTest()
test_result = can_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\nCAN测试——第一项测试成功")
flag_right_7 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\nCAN测试——第一项测试失败")
flag_wrong_7 += 1
can_test_1.close_1()
if flag_right_7 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(5, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_7 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(5, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(5, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
can(self)
def R422(self):
self.ui_start_test.Ptext1.append("\n开始422接口测试")
flag_right_8 = 0
flag_wrong_8 = 0
r422_test_1 = R422Test()
test_result = r422_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n422接口测试——第一项测试成功")
flag_right_8 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n422接口测试——第一项测试失败")
flag_wrong_8 += 1
r422_test_1.close_1()
if flag_right_8 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(5, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_8 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(6, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(6, 3, item)
self.excel_checkbox_1.append("错误")
R422(self)
def pwm(self):
self.ui_start_test.Ptext1.append("\n开始PWM测试")
flag_right_10 = 0
flag_wrong_10 = 0
pwm_test_1 = PWMTest()
test_result = pwm_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\nPWM测试——第一项测试成功")
flag_right_10 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\nPWM测试——第一项测试失败")
flag_wrong_10 += 1
pwm_test_1.close_1()
if flag_right_10 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(8, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_10 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(8, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(8, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
pwm(self)
def io(self):
self.ui_start_test.Ptext1.append("\n开始IO测试——被产品IO为in")
flag_right_11 = 0
flag_wrong_11 = 0
io_test_1 = IOTest()
test_result = io_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\nIO测试——写入全0成功")
flag_right_11 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\nIO测试——写入全0失败")
flag_wrong_11 += 1
io_test_1.close_1()
if flag_right_11 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(9, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_11 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(9, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(9, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
io(self)
def sout(self):
self.ui_start_test.Ptext1.append("\n开始模拟量输出测试")
flag_right_12 = 0
flag_wrong_12 = 0
sout_test_1 = SOutTest()
test_result = sout_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n模拟量输出测试——第一项测试成功")
flag_right_12 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n模拟量输出测试——第一项测试失败")
flag_wrong_12 += 1
sout_test_1.close_1()
if flag_right_12 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(10, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_12 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(10, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(10, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
sout(self)
def sin(self):
self.ui_start_test.Ptext1.append("\n开始模拟量输入测试")
flag_right_13 = 0
flag_wrong_13 = 0
sin_test_1 = SInTest()
test_result = sin_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\n模拟量输入测试——第一项测试成功")
flag_right_13 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\n模拟量输入测试——第一项测试失败")
flag_wrong_13 += 1
sin_test_1.close_1()
if flag_right_13 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(11, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_13 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(11, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(11, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
sin(self)
def spi(self):
self.ui_start_test.Ptext1.append("\n开始SPI接口测试")
flag_right_14 = 0
flag_wrong_14 = 0
spi_test_1 = SPITest()
test_result = spi_test_1.test_1(port='COM2', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext1.append("\nSPI接口测试——第一项测试成功")
flag_right_14 += 1
elif test_result == 2:
self.ui_start_test.Ptext1.append("\nSPI接口测试——第一项测试失败")
flag_wrong_14 += 1
spi_test_1.close_1()
if flag_right_14 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(12, 3, item)
self.excel_checkbox_1.append("正确")
if flag_wrong_14 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform1.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform1.setItem(12, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform1.setItem(12, 3, item)
self.excel_checkbox_1.append("错误")
self.pause_event1.wait()
spi(self)
def Normal_Test_2(self):
def Inner(self):
self.ui_start_test.Ptext2.append("\n内部定时器设计测试")
flag_right_4 = 0
flag_wrong_4 = 0
Inner_test_1 = InnerTest()
test_result = Inner_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n内部定时器设计测试成功")
flag_right_4 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n内部定时器设计测试失败")
flag_wrong_4 += 1
Inner_test_1.close_1()
if flag_right_4 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(2, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_4 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(2, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(2, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
Inner(self)
def R1553B(self):
self.ui_start_test.Ptext2.append("\n开始1553B接口测试——产品端为RT")
flag_right_5 = 0
flag_wrong_5 = 0
R1553B_test_1 = R1553BTest()
test_result = R1553B_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n1553B接口测试——BC-RT测试成功")
flag_right_5 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n1553B接口测试——BC-RT测试失败")
flag_wrong_5 += 1
R1553B_test_1.close_1()
if flag_right_5 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(3, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_5 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(3, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(3, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
R1553B(self)
def R429(self):
self.ui_start_test.Ptext2.append("\n开始429接口测试")
flag_right_6 = 0
flag_wrong_6 = 0
R429_test_1 = R429Test()
test_result = R429_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n429接口测试——第一项测试成功")
flag_right_6 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n429接口测试——第一项测试失败")
flag_wrong_6 += 1
R429_test_1.close_1()
if flag_right_6 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(3, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_6 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(4, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(4, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
R429(self)
def can(self):
self.ui_start_test.Ptext2.append("\n开始CAN测试")
flag_right_7 = 0
flag_wrong_7 = 0
can_test_1 = CanTest()
test_result = can_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\nCAN测试——第一项测试成功")
flag_right_7 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\nCAN测试——第一项测试失败")
flag_wrong_7 += 1
can_test_1.close_1()
if flag_right_7 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(5, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_7 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(5, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(5, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
can(self)
def R422(self):
self.ui_start_test.Ptext2.append("\n开始422接口测试")
flag_right_8 = 0
flag_wrong_8 = 0
r422_test_1 = R422Test()
test_result = r422_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n422接口测试——第一项测试成功")
flag_right_8 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n422接口测试——第一项测试失败")
flag_wrong_8 += 1
r422_test_1.close_1()
if flag_right_8 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(5, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_8 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(6, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(6, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
R422(self)
def pwm(self):
self.ui_start_test.Ptext2.append("\n开始PWM测试")
flag_right_10 = 0
flag_wrong_10 = 0
pwm_test_1 = PWMTest()
test_result = pwm_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\nPWM测试——第一项测试成功")
flag_right_10 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\nPWM测试——第一项测试失败")
flag_wrong_10 += 1
pwm_test_1.close_1()
if flag_right_10 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(8, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_10 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(8, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(8, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
pwm(self)
def io(self):
self.ui_start_test.Ptext2.append("\n开始IO测试——被产品IO为in")
flag_right_11 = 0
flag_wrong_11 = 0
io_test_1 = IOTest()
test_result = io_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\nIO测试——写入全0成功")
flag_right_11 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\nIO测试——写入全0失败")
flag_wrong_11 += 1
io_test_1.close_1()
if flag_right_11 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(9, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_11 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(9, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(9, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
io(self)
def sout(self):
self.ui_start_test.Ptext2.append("\n开始模拟量输出测试")
flag_right_12 = 0
flag_wrong_12 = 0
sout_test_1 = SOutTest()
test_result = sout_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n模拟量输出测试——第一项测试成功")
flag_right_12 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n模拟量输出测试——第一项测试失败")
flag_wrong_12 += 1
sout_test_1.close_1()
if flag_right_12 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(10, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_12 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(10, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(10, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
sout(self)
def sin(self):
self.ui_start_test.Ptext2.append("\n开始模拟量输入测试")
flag_right_13 = 0
flag_wrong_13 = 0
sin_test_1 = SInTest()
test_result = sin_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\n模拟量输入测试——第一项测试成功")
flag_right_13 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\n模拟量输入测试——第一项测试失败")
flag_wrong_13 += 1
sin_test_1.close_1()
if flag_right_13 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(11, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_13 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(11, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(11, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
sin(self)
def spi(self):
self.ui_start_test.Ptext2.append("\n开始SPI接口测试")
flag_right_14 = 0
flag_wrong_14 = 0
spi_test_1 = SPITest()
test_result = spi_test_1.test_1(port='COM4', baudrate=115200, timeout=1)
if test_result == 1:
self.ui_start_test.Ptext2.append("\nSPI接口测试——第一项测试成功")
flag_right_14 += 1
elif test_result == 2:
self.ui_start_test.Ptext2.append("\nSPI接口测试——第一项测试失败")
flag_wrong_14 += 1
spi_test_1.close_1()
if flag_right_14 == 1:
pixmap = QPixmap('Right.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(12, 3, item)
self.excel_checkbox_2.append("正确")
if flag_wrong_14 == 1:
pixmap = QPixmap('Wrong.png')
icon = QIcon(pixmap)
item = QTableWidgetItem()
self.ui_start_test.Pform2.setIconSize(QSize(100, 50))
item.setIcon(icon)
self.ui_start_test.Pform2.setItem(12, 3, item)
item.setBackground(QColor("red"))
self.ui_start_test.Pform2.setItem(12, 3, item)
self.excel_checkbox_2.append("错误")
self.pause_event2.wait()
spi(self)
def timer_event1(self):
self.pause_event1.set()
def timer_event2(self):
self.pause_event2.set()
def pauseButtonClicked1(self):
if self.pause_event1.is_set():
self.pause_event1.clear()
self.timer1.stop()
self.ui_start_test.pause_1.setText("恢复")
else:
self.pause_event1.set()
self.timer1.start()
self.ui_start_test.pause_1.setText("暂停")
def pauseButtonClicked2(self):
if self.pause_event2.is_set():
self.pause_event2.clear()
self.timer2.stop()
self.ui_start_test.pause_2.setText("恢复")
else:
self.pause_event2.set()
self.timer2.start()
self.ui_start_test.pause_2.setText("暂停")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.ui_start_test.show()
sys.exit(app.exec_())