资源简介

一个用python3的Tkinter模块和pyserial模块写的串口调试助手,想学习上位机串口编程的要参考一下,Tkinter做的界面不够qt炫酷,但也够用

资源截图

代码片段和文件信息

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import time
import logging
import datetime
import binascii
import platform
import threading
import tkinter.ttk as ttk
import tkinter.font as tkFont
import tkinter as tk

from UI.MainFrm import Mainframe
from Utils.SerialHelper import SerialHelper

# 根据系统 引用不同的库
if platform.system() == “Windows“:
    from serial.tools import list_ports
else:
    import glob
    import os
    import re

logging.basicConfig(level=logging.DEBUG
                    format=‘%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s‘
                    datefmt=‘%a %d %b %Y %H:%M:%S‘)

# 结束符(16进制)CR 13(\r - 0x0D); NL(LF) 10(\n - 0x0A)
END_HEX = “0D0A“


class MainSerialTool(Mainframe):
    ‘‘‘
    main func class
    ‘‘‘

    def __init__(self master=None):
        super(MainSerialTool self).__init__(master)
        self.root = master

        self.serial_receive_count = 0
        self.serial_recieve_data = ““
        self.serial_listbox = list()

        self.find_all_devices()

    def find_all_devices(self):
        ‘‘‘
        线程检测连接设备的状态
        ‘‘‘
        self.find_all_serial_devices()
        self.start_thread_timer(self.find_all_devices 1)

    def find_all_serial_devices(self):
        ‘‘‘
        检查串口设备
        ‘‘‘
        try:
            if platform.system() == “Windows“:
                self.temp_serial = list()
                for com in list(list_ports.comports()):
                    strCom = com[0] + “: “ + com[1][:-7]
                    self.temp_serial.append(strCom)
                for item in self.temp_serial:
                    if item not in self.serial_listbox:
                        self.serial_frm.frm_left_listbox.insert(“end“ item)
                for item in self.serial_listbox:
                    if item not in self.temp_serial:
                        size = self.serial_frm.frm_left_listbox.size()
                        index = list(self.serial_frm.frm_left_listbox.get(
                            0 size)).index(item)
                        self.serial_frm.frm_left_listbox.delete(index)

                self.serial_listbox = self.temp_serial

            elif platform.system() == “Linux“:
                self.temp_serial = list()
                self.temp_serial = self.find_usb_tty()
                for item in self.temp_serial:
                    if item not in self.serial_listbox:
                        self.serial_frm.frm_left_listbox.insert(“end“ item)
                for item in self.serial_listbox:
                    if item not in self.temp_serial:
                        index = list(self.serial_frm.frm_left_listbox.get(
                            0 self.serial_frm.frm_left_listbox.size())).index(item)
                        self.serial_frm.frm_left_listbox.delete(index)
                self.serial_listbox = self.temp_serial
        except Exception as e:
            logging.error(e)

    def Toggle(self event=None):
        ‘‘‘
        打开/关闭 设备
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        315  2018-01-16 11:13  Serial-Tool\.gitignore

     文件        185  2018-04-10 15:41  Serial-Tool\.idea\misc.xml

     文件        274  2018-04-10 15:41  Serial-Tool\.idea\modules.xml

     文件        398  2018-04-10 15:42  Serial-Tool\.idea\Serial-Tool.iml

     文件        180  2018-04-10 15:41  Serial-Tool\.idea\vcs.xml

     文件      37380  2018-04-12 18:13  Serial-Tool\.idea\workspace.xml

     文件        382  2018-04-02 10:35  Serial-Tool\.project

     文件        315  2018-04-02 10:35  Serial-Tool\.pydevproject

     文件        315  2018-04-02 10:35  Serial-Tool\.pydevproject.bak

     文件         55  2018-04-02 10:35  Serial-Tool\.settings\org.eclipse.core.resources.prefs

     文件      23558  2018-01-16 11:13  Serial-Tool\Images\serial_tool.png

     文件      11117  2018-01-16 11:14  Serial-Tool\main.py

     文件      65704  2018-01-16 11:13  Serial-Tool\MONACO.TTF

     文件       2635  2018-01-16 11:14  Serial-Tool\README.md

     文件       3697  2018-01-16 11:14  Serial-Tool\UI\MainFrm.py

     文件       7711  2018-01-16 11:14  Serial-Tool\UI\PyTkinter.py

     文件      12470  2018-01-16 11:14  Serial-Tool\UI\SerialFrm.py

     文件          0  2018-01-16 11:13  Serial-Tool\UI\__init__.py

     文件       4623  2018-01-16 11:19  Serial-Tool\UI\__pycache__\MainFrm.cpython-35.pyc

     文件       8014  2018-01-16 11:19  Serial-Tool\UI\__pycache__\PyTkinter.cpython-35.pyc

     文件       8914  2018-01-16 11:19  Serial-Tool\UI\__pycache__\SerialFrm.cpython-35.pyc

     文件        147  2018-01-16 11:19  Serial-Tool\UI\__pycache__\__init__.cpython-35.pyc

     文件       5451  2018-04-11 18:13  Serial-Tool\Utils\SerialHelper.py

     文件          0  2018-01-16 11:13  Serial-Tool\Utils\__init__.py

     文件       5726  2018-04-11 18:14  Serial-Tool\Utils\__pycache__\SerialHelper.cpython-35.pyc

     文件        150  2018-01-16 11:19  Serial-Tool\Utils\__pycache__\__init__.cpython-35.pyc

     文件      37503  2018-04-17 15:18  Serial-Tool\界面.png

     目录          0  2018-04-10 15:41  Serial-Tool\.idea\inspectionProfiles

     目录          0  2018-04-17 15:17  Serial-Tool\UI\__pycache__

     目录          0  2018-04-17 15:17  Serial-Tool\Utils\__pycache__

............此处省略9个文件信息

评论

共有 条评论