• 大小: 26.49MB
    文件类型: .7z
    金币: 2
    下载: 2 次
    发布日期: 2024-03-04
  • 语言: Python
  • 标签: python  com  gui  

资源简介

边学边写的。有收发 定时发 时间戳 功能。 还包含QT designer 生成的 .ui文件。画的很丑 还有图标文件

资源截图

代码片段和文件信息

import sys
import datetime
from PyQt5 import QtCore QtGui QtWidgets
# from PyQt5.QtWidgets import QApplication QMainWindow
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMessageBox

from Ui_MainWindow_0124 import Ui_MainWindow
import serial
import serial.tools.list_ports

class MainWindow(QtWidgets.QMainWindow Ui_MainWindow):
    def __init__(self parent=None):
        super(MainWindow self).__init__(parent)
        self.setupUi(self)

        # 设置应用程序的窗口图标
        self.setWindowIcon(QIcon(‘C:\\Users\\Jour\\Documents\\Vscode Workspace\\com.png‘))
        #(‘C:\\Users\\Jour\\Documents\\Vscode Workspace\\com.png‘))

        #串口无效
        self.ser = None
        self.send_num = 0
        self.receive_num = 0
        
        self.now_time = datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S‘)

        dis = ‘ ‘+self.now_time+‘     ‘

        dis = dis + ‘发送:‘+ ‘{:d}‘.format(self.send_num) + ‘  接收: ‘ + ‘{:d}‘.format(self.receive_num)
   
        self.statusbar.showMessage(dis)
        #刷新一下串口的列表
        self.refresh()
       
        #波特率控件
        self.comboBox_2.addItem(‘115200‘)
        self.comboBox_2.addItem(‘57600‘)
        self.comboBox_2.addItem(‘56000‘)
        self.comboBox_2.addItem(‘38400‘)
        self.comboBox_2.addItem(‘19200‘)
        self.comboBox_2.addItem(‘14400‘)
        self.comboBox_2.addItem(‘9600‘)
        self.comboBox_2.addItem(‘4800‘)
        self.comboBox_2.addItem(‘2400‘)
        self.comboBox_2.addItem(‘1200‘)

        #校验位控件
        self.comboBox_3.addItem(‘NONE‘)
        self.comboBox_3.addItem(‘ODD‘)
        self.comboBox_3.addItem(‘EVEN‘)

        #数据位控件
        self.comboBox_4.addItem(‘8‘)
        self.comboBox_4.addItem(‘7‘)
        self.comboBox_4.addItem(‘6‘)
        self.comboBox_4.addItem(‘5‘)

        #停止位控件
        self.comboBox_5.addItem(‘1‘)
        self.comboBox_5.addItem(‘1.5‘)
        self.comboBox_5.addItem(‘2‘)

        #对testEdit进行事件过滤
        # self.textEdit.installEventFilter(self)

        #时钟显示
        self.timer_now = QTimer(self)
        self.timer_now.start(1000)
        self.timer_now.timeout.connect(self.readtime)

        #实例化一个定时器
        self.timer = QTimer(self)

        self.timer_send= QTimer(self)
        self.timer_send_2= QTimer(self)
        self.timer_send_3= QTimer(self)
        
        #定时器调用读取串口接收数据
        self.timer.timeout.connect(self.recv)

        #刷新串口
        self.pushButton.clicked.connect(self.refresh)

        #清空接收
        self.pushButton_2.clicked.connect(self.clear)

        #打开关闭串口按钮
        self.pushButton_3.clicked.connect(self.open_close)

        #主窗口发送-------------------------------------------
        self.pushButton_4.clicked.connect(self.send)
        #定时发送
        self.timer_send.timeout.connect(self.send)
        self.checkBox_4.clicked.connect(self.send_timer_box)

        #主窗口发送_2--------------------------

评论

共有 条评论