python,解析CAN协议--------随意写

#coding:utf-8   #是用来指定文件编码为utf-8的
import os
import codecs#涉及到文件目录有中文日文英文,其ASCII格式不一样


from tkinter import *
from tkinter import messagebox   #导入tkMessageBox
from tkinter.filedialog import askdirectory     #返回文件夹路径,不是文件路径使用
import tkinter.filedialog
import tkinter.messagebox
import tkinter as tk
from tkinter import ttk

import re 
import time #定时使用


#以下是将docx文件转为doc文件实用。需要调用office中的API
import win32com
from win32com.client import Dispatch
import shutil


from PIL import Image,ImageTk


#调试用
import traceback 

import shutil   #实现文件的复制

    


class Application(Frame):
    filename2 = ''
    filename3 = ''
    WordApp =''
    ButtonLSX = ['']
    CAN_ID = ''
    byteL = 0
    byteH = 0
    combox = ('762',)
    


    def __init__(self,master = None):
        Frame.__init__(self,master)
        self.grid(row = 0,column = 5)
        self.path2 = StringVar()#先在此处定义,在函数selectDocx()被调用时赋值
        self.path3 = StringVar()#先在此处定义,在函数selectDocx()被调用时赋值
        self.path4 = StringVar()#先在此处定义,在函数selectDocx()被调用时赋值

        self.txt1 =StringVar()
        self.txt2 =StringVar()
        self.txt3 =StringVar()
        self.txt4 =StringVar()
        self.txt5 =StringVar()
        self.txt6 =StringVar()
        self.txt7 =StringVar()
        self.txt8 =StringVar()
        self.abs = StringVar()
        self.sas = StringVar()
        self.CanID = StringVar() #can id 下拉菜单
        self.createWidgets()
        
        
        
        
    def createWidgets(self):
        global ButtonLS
        #cfg路径选择标签
        self.DocxPathLabel = Label(self,text = "选择CAN CFG 文件", bg = '#f0fff0',height = 1,width = 18)
        self.DocxPathLabel.grid(row = 0, column = 0,pady = 5,sticky=N+S+N+S)  #sticky=N+S上下对齐
        
        #entry内容设置
        self.DocxPathEntry = Entry(self, textvariable = self.path2,bg = '#f0fff0',selectbackground  = 'red') #entry 的text属性不可以设置文本格式,在Entry中设定初始值,使用textvariable将变量与Entry绑定
        self.DocxPathEntry.grid(row = 0, column = 1,columnspan =8,pady = 5,sticky=N+S+W+E)#padx=2,与前一个控件水平距离
        self.DocxPathEntry.insert(0,'点击<cfg选择>按键,显示所选cfg文件路径……')
        #cfg选择按钮设置
        self.ProButton = Button(self, text = "cfg文件选择", bg = '#fff8dc',height = 1,width = 13,command = self.selectDocx)
        self.ProButton.grid(row = 0, column = 9,pady = 5,sticky=N+S+W+E)

        #设置Can Id
        #self.Get_CanId_Label = Label(self,text = "Can Id", bg = '#f0fff0',height = 1,width = 6)
        #self.Get_CanId_Label.grid(row = 1, column = 0,pady = 5,sticky=E)  #sticky=N+S上下对齐
        ##self.Get_CanId_Entry = Entry(self, textvariable = self.path3,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        ##self.Get_CanId_Entry.grid(row = 1, column = 1,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        #self.Get_CanId_Entry.insert(0,'输入Can Id')
        ##self.Get_CanID_Button = Button(self, text = "设置CanID", fg='red',bg = '#fff8dc',height = 1,command = self.getCanId)
        ##self.Get_CanID_Button.grid(row = 1, column = 3,columnspan =2,pady = 5,sticky=N+S+W+E)

        """
        options = ['8','9','7','6','3']
        self.CanID.set(options[0])
        self.CanIDchose = OptionMenu(self, self.CanID,*options)
        #self.CanIDchose['values'] = (12,6,3,4,5)
        self.CanIDchose.grid(row = 15, column = 3,columnspan =2,pady = 5,sticky=N+S+W+E)
        #self.CanIDchose.current(2)
        """
        #self.Get_CanId_Label = Label(self,text = "选择Can Id", bg =  'orange',fg = 'red',height = 1,width = 6)
        #self.Get_CanId_Label.grid(row = 1, column = 9,pady = 5,sticky=N+S+W+E)  #sticky=N+S上下对齐
        
        self.CanIDchose = ttk.Combobox(self, textvariable = self.CanID,width = 5)

        f = open(r'.\cfg\CAN协议总结.cfg')          
        for line in f:
            if line[5:10] =="CANID":
                self.combox = self.combox + (line[11:14],)
        f.close()

        
        self.combox = tuple(set(self.combox))  #去重
        self.CanIDchose['values'] = sorted(self.combox)  #sorted 只能排序字符串
        self.CanIDchose.grid(row = 1, column = 9,columnspan =1,pady = 5,sticky=N+S+E)
        self.CanIDchose.current(3)  
        self.Get_CanID_Button = Button(self, text = "设置CanID", fg='red',bg = 'pink',height = 1,width = 8,command = self.getCanId)
        self.Get_CanID_Button.grid(row = 1, column = 10,columnspan =1,pady = 5,sticky=N+S)

        self.Write_File = Button(self, text = "写入txt", fg='blue',bg = 'pink',height = 1,width = 9,command = self.WriteFile)
        self.Write_File.grid(row = 1, column = 11,columnspan =1,pady = 5,sticky=N+S+W)
        
        """
        #画图框架图1
        self.canvas1 = Canvas(self, width = 900, height = 600, bg = "#f0fff0")
        load1 = Image.open(r".\cfg\sys")
        render1 = ImageTk.PhotoImage(load1)
        img1 = load1.resize((int(load1.size[0]/3*2),int(load1.size[1]/3*2)),Image.ANTIALIAS)
        render1 = ImageTk.PhotoImage(img1)
        self.canvas1.image =render1  #这里会让图片显示出来
        self.canvas1.create_image(412,200,image = render1)  #中心位置
        self.canvas1.grid(row = 13, column = 1,columnspan=8,sticky=W+E)
        myText=self.canvas1.create_text(280,95,text='0')
        myText=self.canvas1.create_text(370,95,text='0')
        """
        

        #64bit button set        fg='blue',bg = '#ff0000'
        self.Button0 = Button(self, text = "0",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(0))
        self.Button0.grid(row = 4, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button1 = Button(self, text = "1",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(1))
        self.Button1.grid(row = 4, column = 7,pady = 5,padx =5,sticky=N+S)
        
        self.Button2 = Button(self, text = "2",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(2))
        self.Button2.grid(row = 4, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button3 = Button(self, text = "3",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(3))
        self.Button3.grid(row = 4, column = 5,pady = 5,padx =5,sticky=N+S)
        
        self.Button4 = Button(self, text = "4",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(4))
        self.Button4.grid(row = 4, column = 4,pady = 5,padx =5,sticky=N+S)

                
        self.Button5 = Button(self, text = "5",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(5))
        self.Button5.grid(row = 4, column = 3,pady = 5,padx =5,sticky=N+S)

        self.Button6 = Button(self, text = "6",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(6))
        self.Button6.grid(row = 4, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button7 = Button(self, text = "7",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(7))
        self.Button7.grid(row = 4, column = 1,pady = 5,padx =5,sticky=N+S)

        self.Button8 = Button(self, text = "8",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(8))
        self.Button8.grid(row = 5, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button9 = Button(self, text = "9",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(9))
        self.Button9.grid(row = 5, column = 7,pady = 5,padx =5,sticky=N+S)
      
      
        self.Button10 = Button(self, text = "10",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(10))
        self.Button10.grid(row = 5, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button11 = Button(self, text = "11",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(11))
        self.Button11.grid(row = 5, column = 5,pady = 5,padx =5,sticky=N+S)
        
        self.Button12 = Button(self, text = "12",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(12))
        self.Button12.grid(row = 5, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button13 = Button(self, text = "13",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(13))
        self.Button13.grid(row = 5, column = 3,pady = 5,padx =5,sticky=N+S)
        
        self.Button14 = Button(self, text = "14",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(14))
        self.Button14.grid(row = 5, column = 2,pady = 5,padx =5,sticky=N+S)

                
        self.Button15 = Button(self, text = "15",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(15))
        self.Button15.grid(row = 5, column = 1,pady = 5,padx =5,sticky=N+S)

        self.Button16 = Button(self, text = "16",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(16))
        self.Button16.grid(row = 6, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button17 = Button(self, text = "17",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(17))
        self.Button17.grid(row = 6, column = 7,pady = 5,padx =5,sticky=N+S)
        
        
        
        
        self.Button18 = Button(self, text = "18",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(18))
        self.Button18.grid(row = 6, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button19 = Button(self, text = "19",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(19))
        self.Button19.grid(row = 6, column = 5,pady = 5,padx =5,sticky=N+S)

        self.Button20 = Button(self, text = "20",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(20))
        self.Button20.grid(row = 6, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button21 = Button(self, text = "21",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(21))
        self.Button21.grid(row = 6, column = 3,pady = 5,padx =5,sticky=N+S)
        
        self.Button22 = Button(self, text = "22",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(22))
        self.Button22.grid(row = 6, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button23 = Button(self, text = "23",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(23))
        self.Button23.grid(row = 6, column = 1,pady = 5,padx =5,sticky=N+S)
        
        self.Button24 = Button(self, text = "24",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(24))
        self.Button24.grid(row = 7, column = 8,pady = 5,padx =5,sticky=N+S)

                
        self.Button25 = Button(self, text = "25",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(25))
        self.Button25.grid(row = 7, column = 7,pady = 5,padx =5,sticky=N+S)

        self.Button26 = Button(self, text = "26",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(26))
        self.Button26.grid(row = 7, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button27 = Button(self, text = "27",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(27))
        self.Button27.grid(row = 7, column = 5,pady = 5,padx =5,sticky=N+S)
        
        
        
        
        self.Button28 = Button(self, text = "28",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(28))
        self.Button28.grid(row = 7, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button29 = Button(self, text = "29",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(29))
        self.Button29.grid(row = 7, column = 3,pady = 5,padx =5,sticky=N+S)
      
        self.Button30 = Button(self, text = "30",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(30))
        self.Button30.grid(row = 7, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button31 = Button(self, text = "31",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(31))
        self.Button31.grid(row = 7, column = 1,pady = 5,padx =5,sticky=N+S)
        
        self.Button32 = Button(self, text = "32",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(32))
        self.Button32.grid(row = 8, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button33 = Button(self, text = "33",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(33))
        self.Button33.grid(row = 8, column = 7,pady = 5,padx =5,sticky=N+S)
        
        self.Button34 = Button(self, text = "34",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(34))
        self.Button34.grid(row = 8, column = 6,pady = 5,padx =5,sticky=N+S)

                
        self.Button35 = Button(self, text = "35",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(35))
        self.Button35.grid(row = 8, column = 5,pady = 5,padx =5,sticky=N+S)

        self.Button36 = Button(self, text = "36",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(36))
        self.Button36.grid(row = 8, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button37 = Button(self, text = "37",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(37))
        self.Button37.grid(row = 8, column = 3,pady = 5,padx =5,sticky=N+S)
        
        
        
        
        self.Button38 = Button(self, text = "38",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(38))
        self.Button38.grid(row = 8, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button39 = Button(self, text = "39",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(39))
        self.Button39.grid(row = 8, column = 1,pady = 5,padx =5,sticky=N+S)
      
        self.Button40 = Button(self, text = "40",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(40))
        self.Button40.grid(row = 9, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button41 = Button(self, text = "41",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(41))
        self.Button41.grid(row = 9, column = 7,pady = 5,padx =5,sticky=N+S)
        
        self.Button42 = Button(self, text = "42",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(42))
        self.Button42.grid(row = 9, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button43 = Button(self, text = "43",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(43))
        self.Button43.grid(row = 9, column = 5,pady = 5,padx =5,sticky=N+S)
        
        self.Button44 = Button(self, text = "44",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(44))
        self.Button44.grid(row = 9, column = 4,pady = 5,padx =5,sticky=N+S)

                
        self.Button45 = Button(self, text = "45",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(45))
        self.Button45.grid(row = 9, column = 3,pady = 5,padx =5,sticky=N+S)

        self.Button46 = Button(self, text = "46",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(46))
        self.Button46.grid(row = 9, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button47 = Button(self, text = "47",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(47))
        self.Button47.grid(row = 9, column = 1,pady = 5,padx =5,sticky=N+S)
        
        
        
        
        self.Button48 = Button(self, text = "48",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(48))
        self.Button48.grid(row = 10, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button49 = Button(self, text = "49",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(49))
        self.Button49.grid(row = 10, column = 7,pady = 5,padx =5,sticky=N+S)
      


        self.Button50 = Button(self, text = "50",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(50))
        self.Button50.grid(row = 10, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button51 = Button(self, text = "51",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(51))
        self.Button51.grid(row = 10, column = 5,pady = 5,padx =5,sticky=N+S)
        
        self.Button52 = Button(self, text = "52",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(52))
        self.Button52.grid(row = 10, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button53 = Button(self, text = "53",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(53))
        self.Button53.grid(row = 10, column = 3,pady = 5,padx =5,sticky=N+S)
        
        self.Button54 = Button(self, text = "54",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(54))
        self.Button54.grid(row = 10, column = 2,pady = 5,padx =5,sticky=N+S)

                
        self.Button55 = Button(self, text = "55",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(55))
        self.Button55.grid(row = 10, column = 1,pady = 5,padx =5,sticky=N+S)

        self.Button56 = Button(self, text = "56",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(56))
        self.Button56.grid(row = 11, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button57 = Button(self, text = "57",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(57))
        self.Button57.grid(row = 11, column = 7,pady = 5,padx =5,sticky=N+S)

        self.Button58 = Button(self, text = "58",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(58))
        self.Button58.grid(row = 11, column = 6,pady = 5,padx =5,sticky=N+S)

        self.Button59 = Button(self, text = "59",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(59))
        self.Button59.grid(row = 11, column = 5,pady = 5,padx =5,sticky=N+S)
      
        self.Button60 = Button(self, text = "60",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(60))
        self.Button60.grid(row = 11, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button61 = Button(self, text = "61",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(61))
        self.Button61.grid(row = 11, column = 3,pady = 5,padx =5,sticky=N+S)
        
        self.Button62 = Button(self, text = "62",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(62))
        self.Button62.grid(row = 11, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button63 = Button(self, text = "63",height = 1,width = 3,relief=FLAT,fg='blue',bg = 'green',cursor = "heart",command = lambda :self.bit_info(63))
        self.Button63.grid(row = 11, column = 1,pady = 5,padx =5,sticky=N+S)


        self.Button64 = Button(self, text = "1\nbit 0",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button64.grid(row = 12, column = 8,pady = 5,padx =5,sticky=N+S)

        self.Button65 = Button(self, text = "2\nbit 1",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button65.grid(row = 12, column = 7,pady = 5,padx =5,sticky=N+S)

        self.Button66 = Button(self, text = "4\nbit 2",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button66.grid(row = 12, column = 6,pady = 5,padx =5,sticky=N+S)
        
        self.Button67 = Button(self, text = "8\nbit 3",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button67.grid(row = 12, column = 5,pady = 5,padx =5,sticky=N+S)
      
        self.Button68 = Button(self, text = "1\nbit 4",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button68.grid(row = 12, column = 4,pady = 5,padx =5,sticky=N+S)

        self.Button69 = Button(self, text = "2\nbit 5",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button69.grid(row = 12, column = 3,pady = 5,padx =5,sticky=N+S)
        
        self.Button70 = Button(self, text = "4\nbit 6",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button70.grid(row = 12, column = 2,pady = 5,padx =5,sticky=N+S)

        self.Button71 = Button(self, text = "8\nbit 7",height = 1,width = 3,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button71.grid(row = 12, column = 1,pady = 5,padx =5,sticky=N+S)       
        

        self.Button72 = Button(self, text = "H← Byte0 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button72.grid(row = 4, column = 0,pady = 5,padx =5,sticky=N+S+E)

        self.Button73 = Button(self, text = "H← Byte1 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button73.grid(row = 5, column = 0,pady = 5,padx =5,sticky=N+S+E)

        self.Button74 = Button(self, text = "H← Byte2 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button74.grid(row = 6, column = 0,pady = 5,padx =5,sticky=N+S+E)
        
        self.Button75 = Button(self, text = "H← Byte3 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button75.grid(row = 7, column = 0,pady = 5,padx =5,sticky=N+S+E)
      
        self.Button76 = Button(self, text = "H← Byte4 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button76.grid(row = 8, column = 0,pady = 5,padx =5,sticky=N+S+E)

        self.Button77 = Button(self, text = "H← Byte5 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button77.grid(row = 9, column = 0,pady = 5,padx =5,sticky=N+S+E)
        
        self.Button78 = Button(self, text = "H← Byte6 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button78.grid(row = 10, column = 0,pady = 5,padx =5,sticky=N+S+E)

        self.Button79 = Button(self, text = "H← Byte7 →L",height = 1,width = 10,relief=FLAT,fg='red',bg = 'yellow',cursor = "heart",state = DISABLED,command = self.helpdoc)
        self.Button79.grid(row = 11, column = 0,pady = 5,padx =5,sticky=N+S+E)


        self.Button80 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte1)
        self.Button80.grid(row = 4, column = 9,pady = 5,padx =5,sticky=N+S)

        self.Button81 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte2)
        self.Button81.grid(row = 5, column = 9,pady = 5,padx =5,sticky=N+S)

        self.Button82 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte3)
        self.Button82.grid(row = 6, column = 9,pady = 5,padx =5,sticky=N+S)
        
        self.Button83 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte4)
        self.Button83.grid(row = 7, column = 9,pady = 5,padx =5,sticky=N+S)
      
        self.Button84 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte5)
        self.Button84.grid(row = 8, column = 9,pady = 5,padx =5,sticky=N+S)

        self.Button77 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte6)
        self.Button77.grid(row = 9, column = 9,pady = 5,padx =5,sticky=N+S)
        
        self.Button85 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte7)
        self.Button85.grid(row = 10, column = 9,pady = 5,padx =5,sticky=N+S)

        self.Button86 = Button(self, text = "bit to byte→0x",height = 1,width = 12,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.bitToByte8)
        self.Button86.grid(row = 11, column = 9,pady = 5,padx =5,sticky=N+S)

        self.Button87 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit1)
        self.Button87.grid(row = 4, column = 10,pady = 5,padx =5,sticky=N+S)

        self.Button88 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit2)
        self.Button88.grid(row = 5, column = 10,pady = 5,padx =5,sticky=N+S)

        self.Button89 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit3)
        self.Button89.grid(row = 6, column = 10,pady = 5,padx =5,sticky=N+S)
        
        self.Button90 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit4)
        self.Button90.grid(row = 7, column = 10,pady = 5,padx =5,sticky=N+S)
      
        self.Button91 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit5)
        self.Button91.grid(row = 8, column = 10,pady = 5,padx =5,sticky=N+S)

        self.Button92 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit6)
        self.Button92.grid(row = 9, column = 10,pady = 5,padx =5,sticky=N+S)
        
        self.Button93 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit7)
        self.Button93.grid(row = 10, column = 10,pady = 5,padx =5,sticky=N+S)

        self.Button94 = Button(self, text = "←byte to bit",height = 1,width = 10,relief=FLAT,fg='red',bg = 'gray',cursor = "heart",command = self.byteToBit8)
        self.Button94.grid(row = 11, column = 10,pady = 5,padx =5,sticky=N+S)

        #速度和方向盘转角计算####################################################################################################################################
        
        self.Button95 = Button(self, text = "↑sped to byte",height = 1,width = 10,relief=FLAT,fg='red',bg = 'olive',cursor = "heart",command = self.SpeedTobyte)
        self.Button95.grid(row = 14, column = 11,pady = 5,padx =5,sticky=N+S)

        self.Button96 = Button(self, text = "byte to sped↓",height = 1,width = 10,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.byteToSpeed)
        self.Button96.grid(row = 14, column = 14,pady = 5,padx =5,sticky=N+S+E)

        self.Button97 = Button(self, text = "↑angle to byte",height = 1,width = 10,relief=FLAT,fg='red',bg = 'olive',cursor = "heart",command = self.AngleTobyte)
        self.Button97.grid(row = 15, column = 11,pady = 5,padx =5,sticky=N+S)

        self.Button98 = Button(self, text = "byte to angle↓",height = 1,width = 10,relief=FLAT,fg='red',bg = 'cyan',cursor = "heart",command = self.byteToAngle)
        self.Button98.grid(row = 15, column = 14,pady = 5,padx =5,sticky=N+S+E)
        ###########################################################################################################################################################

        self.Etxt1 = Entry(self, textvariable = self.txt1,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt1.grid(row = 4, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离

        self.Etxt2 = Entry(self, textvariable = self.txt2,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt2.grid(row = 5, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt3 = Entry(self, textvariable = self.txt3,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt3.grid(row = 6, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt4 = Entry(self, textvariable = self.txt4,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt4.grid(row = 7, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt5 = Entry(self, textvariable = self.txt5,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt5.grid(row = 8, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt6 = Entry(self, textvariable = self.txt6,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt6.grid(row = 9, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt7 = Entry(self, textvariable = self.txt7,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt7.grid(row = 10, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        
        self.Etxt8 = Entry(self, textvariable = self.txt8,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Etxt8.grid(row = 11, column = 11,columnspan =8,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离
        

         #速度和方向盘转角计算####################################################################################################################################

        self.Eabs = Entry(self, textvariable = self.abs,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Eabs.grid(row = 14, column = 12,columnspan =1,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离

        self.Esas = Entry(self, textvariable = self.sas,width = 10,fg ='red',bg = '#f0fff0',selectbackground  = 'red')
        self.Esas.grid(row = 15, column = 12,columnspan =1,pady = 5,sticky=W+N+S)#padx=2,与前一个控件水平距离

        self.absLabel = Label(self,text = "速度计算Km/h:(double)Byte*0.05625", bg = 'lime',height = 1,width = 30)
        self.absLabel.grid(row = 14, column = 8,pady = 5,columnspan =3,sticky=N+S+N+S)  #sticky=N+S上下对齐
        self.sasLabel = Label(self,text = "角度计算:((double)Byte/16-2048)/14", bg = 'lime',height = 1,width = 30)
        self.sasLabel.grid(row = 15, column = 8,pady = 5,columnspan =3,sticky=N+S+N+S)  #sticky=N+S上下对齐

         ###########################################################################################################################################################
        #帮助按钮设置
        self.HelpButton = Button(self, text = "Help",height = 1,width = 3,relief=FLAT,fg='blue',bg = '#ff0000',cursor = "heart",command = self.helpdoc)
        self.HelpButton.grid(row = 28, column = 18,pady = 5,sticky=E)


        ButtonLS = [self.Button0,self.Button1,self.Button2,self.Button3,self.Button4,self.Button5,self.Button6,self.Button7,self.Button8,self.Button9,\
                    self.Button10,self.Button11,self.Button12,self.Button13,self.Button14,self.Button15,self.Button16,self.Button17,self.Button18,self.Button19,\
                    self.Button20,self.Button21,self.Button22,self.Button23,self.Button24,self.Button25,self.Button26,self.Button27,self.Button28,self.Button29, \
        self.Button30,self.Button31,self.Button32,self.Button33,self.Button34,self.Button35,self.Button36,self.Button37,self.Button38,self.Button39,\
                    self.Button40,self.Button41,self.Button42,self.Button43,self.Button44,self.Button45,self.Button46,self.Button47,self.Button48,self.Button49,\
                    self.Button50,self.Button51,self.Button52,self.Button53,self.Button54,self.Button55,self.Button56,self.Button57,self.Button58,self.Button59,\
                    self.Button60,self.Button61,self.Button62,self.Button63]


    def WriteFile(self):
        WriteStr =""
        data1 = ""
        data2 = ""
        data3 = ""
        data4 = ""
        data5 = ""
        data6 = ""
        data7 = ""
        data8 = ""
        print("get= ",end = '')
        print(self.Etxt1.get())
        if self.Etxt1.get()=="0x0" or self.Etxt1.get()=="":
            data1 = "00 "
        else:
            data1 = self.Etxt1.get()[2:4] + " "
            
        if self.Etxt2.get()=="0x0" or self.Etxt2.get()=="":
            data2 = "00 "
        else:
            data2 = self.Etxt2.get()[2:4]+ " "
            
        if self.Etxt3.get()=="0x0" or self.Etxt3.get()=="":
            data3 = "00 "
        else:
            data3 = self.Etxt3.get()[2:4]+ " "
            
        if self.Etxt4.get()=="0x0" or self.Etxt4.get()=="":
            data4 = "00 "
        else:
            data4 = self.Etxt4.get()[2:4]+ " "
            
        if self.Etxt5.get()=="0x0" or self.Etxt5.get()=="":
            data5 = "00 "
        else:
            data5 = self.Etxt5.get()[2:4] + " "
            
        if self.Etxt6.get()=="0x0" or self.Etxt6.get()=="":
            data6 = "00 "
        else:
            data6 = self.Etxt6.get()[2:4]+ " "
            
        if self.Etxt7.get()=="0x0" or self.Etxt7.get()=="":
            data7 = "00 "
        else:
            data7 = self.Etxt7.get()[2:4]+ " "
            
        if self.Etxt8.get()=="0x0" or self.Etxt8.get()=="":
            data8 = "00 "
        else:
            data8 = self.Etxt8.get()[2:4]   + " "         
        
        try:    
            WriteStr = CAN_ID + "    "+ data1+ data2 +data3 +data4+data5 + data6+ data7+ data8 +"    std    data\n"
        except:
             tkinter.messagebox.showwarning(title='CAN ID和Byte检查',message='☞请检查CAN ID是否设置成功!\nByte值是否正确 !\n')
        else:
            
            f = open("./cfg/CanCommand.txt", "a+")
            #print(f.read())
            f.write(WriteStr)
            f.seek(0, 0)# 把文件指针从末尾移到开头,没有这句话下面的read()就读不到正确的东西
            #print(f.read())
            f.close()


        
    def byteToSpeed(self):
        #if CANID ==
            speedF = int(ButtonLS[43]['text'])*1+\
                    int(ButtonLS[44]['text'])*2+\
                    int(ButtonLS[45]['text'])*4+\
                    int(ButtonLS[46]['text'])*8+\
                    int(ButtonLS[47]['text'])*16+\
                    int(ButtonLS[32]['text'])*32+\
                    int(ButtonLS[33]['text'])*64+\
                    int(ButtonLS[34]['text'])*128+\
                    int(ButtonLS[35]['text'])*256+\
                    int(ButtonLS[36]['text'])*512+\
                    int(ButtonLS[37]['text'])*1024+\
                    int(ButtonLS[38]['text'])*2048+\
                    int(ButtonLS[39]['text'])*4096
            speedB = speedF * 0.05625
            print("speedF =",end ='')
            print(speedF)
            print("speedB =",end ='')
            print(speedB)

            self.abs.set(str(speedB))

    def SpeedTobyte(self):
        #print(self.Eabs.get())
        byte = float(self.Eabs.get())/0.05625
        #print("byte =",end ='')
        #print(int(byte))
        #print(hex(int(byte)))
        b = '{:013b}'.format(int(byte),16)
        #print("b =",end ='')
        #print(b)
        
        ButtonLS[43]['text'] = b[12:13]
        ButtonLS[44]['text'] = b[11:12]
        ButtonLS[45]['text'] = b[10:11]
        ButtonLS[46]['text'] = b[9:10]
        ButtonLS[47]['text'] = b[8:9]
        ButtonLS[32]['text'] = b[7:8]
        ButtonLS[33]['text'] = b[6:7]
        ButtonLS[34]['text'] = b[5:6]
        ButtonLS[35]['text'] = b[4:5]
        ButtonLS[36]['text'] = b[3:4]
        ButtonLS[37]['text'] = b[2:3]
        ButtonLS[38]['text'] = b[1:2]
        ButtonLS[39]['text'] = b[0:1]


        ButtonLS[43]['bg'] = 'black'
        ButtonLS[44]['bg'] = 'black'
        ButtonLS[45]['bg']= 'black'
        ButtonLS[46]['bg']= 'black'
        ButtonLS[47]['bg'] = 'black'
        ButtonLS[32]['bg'] = 'black'
        ButtonLS[33]['bg'] = 'black'
        ButtonLS[34]['bg'] = 'black'
        ButtonLS[35]['bg']= 'black'
        ButtonLS[36]['bg'] = 'black'
        ButtonLS[37]['bg'] = 'black'
        ButtonLS[38]['bg'] = 'black'
        ButtonLS[39]['bg'] = 'black'

    def byteToAngle(self):

        AngleH = 0
        AngleL = 0
        try:
            for i in range(0,8):
                AngleH = AngleH + int(ButtonLS[i]['text'])*2**(8+i)
            for i in range(0,8):
                AngleL = AngleL + int(ButtonLS[i+8]['text'])*2**(i)
        except:
            tkinter.messagebox.showwarning(title='总线数据转换为方向盘转角',message='☞请检查byte0和byte1各个bit位是否正确\n')
        else:
            AngleF = AngleH + AngleL
            AngleB = (AngleF/16 -2048)/14
            self.sas.set(str(AngleB))
        
    def AngleTobyte(self):
        print(self.Esas.get())
        byte = (float(self.Esas.get())*14+2048)*16
        print("byte =",end ='')
        print(int(byte))
        print(hex(int(byte)))
        b = '{:016b}'.format(int(byte),16)
        print("b =",end ='')
        print(b)
        ButtonLS[7]['text'] = b[0:1]
        ButtonLS[6]['text'] = b[1:2 ]
        ButtonLS[5]['text'] = b[2:3 ]
        ButtonLS[4]['text'] = b[3:4 ] 
        ButtonLS[3]['text'] = b[4:5 ]         
        ButtonLS[2]['text'] = b[5:6 ]
        ButtonLS[1]['text'] = b[6:7 ]
        ButtonLS[0]['text'] = b[7:8 ]
        ButtonLS[15]['text'] = b[8:9 ]
        ButtonLS[14]['text'] = b[9:10 ]
        ButtonLS[13]['text'] = b[10:11 ]
        ButtonLS[12]['text'] = b[11:12 ]
        ButtonLS[11]['text'] = b[12:13 ]
        ButtonLS[10]['text'] = b[13:14 ]
        ButtonLS[9]['text'] = b[14:15 ]
        ButtonLS[8]['text'] = b[15:16 ]

        for i in range(0,16):
            ButtonLS[i]['bg'] = 'black'

     
    def getByteData(self,num,var):
        print(var)
        if var =='':
           tkinter.messagebox.showwarning(title='请检查数据',message='☞Byte值为空,请填入想要的Byte值。\n\n默认为0x00\n')
           var = '0x00'
        print(int(var,16))
        #b=bin(int(var,16))
        b = '{:08b}'.format(int(var,16))
        print(b)
        print(len(b))
        strBin = b
        for  i in range(0,8):
            ButtonLS[num*8 +7-i ]['text']=strBin[i:i+1]
            ButtonLS[num*8 +i]['fg'] = 'pink'

    def byteToBit1(self):
        self.getByteData(0,self.Etxt1.get())
        
    def byteToBit2(self):
        self.getByteData(1,self.Etxt2.get())
        
    def byteToBit3(self):
        self.getByteData(2,self.Etxt3.get())
        
    def byteToBit4(self):
        self.getByteData(3,self.Etxt4.get())
        
    def byteToBit5(self):
        self.getByteData(4,self.Etxt5.get())
        
    def byteToBit6(self):
        self.getByteData(5,self.Etxt6.get())
        
    def byteToBit7(self):
        self.getByteData(6,self.Etxt7.get())
        
    def byteToBit8(self):
        self.getByteData(7,self.Etxt8.get())

    def getBitData(self,num):
        bit_str = ""
        bit_info = False
        global byteL
        global byteH
        bit0 = 0
        bit1 = 0
        bit2 = 0
        bit3 = 0
        bit4 = 0
        bit5 = 0
        bit6 = 0
        bit7 = 0
        for  i in range(0,8):
            #print("num =",end ='')
            #print(num)
            #print("i =",end ='')
            print(i)
            if ButtonLS[num*8 +i]['bg'] == 'black':
                if i ==0:
                    bit0 =(int(ButtonLS[num*8 +0 ]['text'])*1)
                if i ==1:
                    bit1 =(int(ButtonLS[num*8 +1 ]['text'])*2)
                    
                if i ==2:
                    bit2 =(int(ButtonLS[num*8 +2 ]['text'])*4)
                    
                if i ==3:
                    bit3 =(int(ButtonLS[num*8 +3 ]['text'])*8)
                    
                if i ==4:
                    bit4 =(int(ButtonLS[num*8 +4 ]['text'])*16)

                if i ==5:
                    bit5 =(int(ButtonLS[num*8 +5 ]['text'])*32)
                    
                if i ==6:
                    bit6 =(int(ButtonLS[num*8 +6 ]['text'])*64)
                    
                if i ==7:
                    bit7 =(int(ButtonLS[num*8 +7 ]['text'])*128)
            else:
                bit_str = bit_str + str(i) + '、'
                print(bit_str)
                bit_info =True
                
            if i==7 and bit_info ==True:
                tkinter.messagebox.showwarning(title='请检查数据',message='☞bit: '+str(bit_str)+'位被该CAN ID使用。\n\n默认为:0\n')
                    
        byteL =bit0 + bit1 + bit2 + bit3
        byteH = bit4 + bit5 + bit6 + bit7

        
    def bitToByte1(self):
        
        self.getBitData(0)
        self.txt1.set(str(hex(int(byteL) +int(byteH))))

        
    def bitToByte2(self):
        self.getBitData(1)
        self.txt2.set(str(hex(int(byteL) +int(byteH))))

    def bitToByte3(self):
        self.getBitData(2)
        self.txt3.set(str(hex(int(byteL) +int(byteH))))


    def bitToByte4(self):
        self.getBitData(3)
        self.txt4.set(str(hex(int(byteL) +int(byteH))))

    def bitToByte5(self):
        self.getBitData(4)
        self.txt5.set(str(hex(int(byteL) +int(byteH))))

    def bitToByte6(self):
        self.getBitData(5)
        self.txt6.set(str(hex(int(byteL) +int(byteH))))

    def bitToByte7(self):
        self.getBitData(6)
        self.txt7.set(str(hex(int(byteL) +int(byteH))))

    def bitToByte8(self):
        self.getBitData(7)
        self.txt8.set(str(hex(int(byteL) +int(byteH))))

        
    
    def helpdoc(self):
        
        tkinter.messagebox.showinfo(title='工具帮助1.0',message='☆版本信息:\n    Version1.0\n ')
        print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))


    def selectDocx(self):
        Application.filename=tkinter.filedialog.askopenfilename(filetypes=[('cfg|txt格式','*.cfg;*.txt')])  #获取的docx文件路径
        #Application.filename=askdirectory()
        #Application.filename= r'C:\Users\Desktop\Set_pattern\VSZ210952-DD5.doc'
        print('11编译环境路径 = ',end ='')
        print(Application.filename)
        print('12Static Tool 位置= ',end ='')
        print(Application.filename2)
        print('13BootLoader 位置= ',end ='')
        print(Application.filename3)
        self.path2.set(Application.filename)

    def getCanId(self):
        global CAN_ID
        print('输入的Can Id = ',end ='')
        #CAN_ID = self.Get_CanId_Entry.get()
        CAN_ID = self.CanIDchose.get()
        print(CAN_ID)
        self.ReadCFG()


    def ReadCFG(self):
        # ButtonLS[0]['fg'] = 'red'
        #ButtonLS[0]['text'] = 'red0'

        for i in range(0,64):
            ButtonLS[i]['fg'] = 'blue'
            ButtonLS[i]['bg'] = 'green'
            ButtonLS[i]['text'] = i

        self.txt1.set('')#清空entry的值
        self.txt2.set('')
        self.txt3.set('')
        self.txt4.set('')
        self.txt5.set('')
        self.txt6.set('')
        self.txt7.set('')
        self.txt8.set('')
        f = open(r'.\cfg\CAN协议总结.cfg')          
        for line in f:
            #print(line)
            if line[11:14] ==CAN_ID:              
                 byte = int(line[20:21]) * 8 + int(line[26:27])
                 
                 #print(byte)
                 ButtonLS[byte]['fg'] = 'red'
                 ButtonLS[byte]['bg'] = 'black'
                 ButtonLS[byte]['text'] = line[33:34]#line[44:]
        f.close()

    def bit_info(self,num):
        #print("////////")
        #print(num)
        
        f = open(r'.\cfg\CAN协议总结.cfg')
        for line in f:
            #print(line)
            try:
                if line[11:14] == CAN_ID:
                     #print(line)     
                     byte = int(line[20:21]) * 8 + int(line[26:27])  #byte11-13 bit 26
                     #print(byte)

                     #print(line[44:])  #功能 44
                     if  num == byte:
                          re = tkinter.messagebox.askquestion(title='bit infoとbit值を变更する',message='☆☆☆☆☆☆☆☆☆☆☆☆\n\n ' + line[33:34]+" : "+line[44:]+'\n☆☆☆☆☆☆☆☆☆☆☆☆\n '+'\n是\否变更该bit位值?\n')
                          print(re)
                          if re == 'yes':
                                ButtonLS[byte]['fg'] = 'yellow'
                                print(ButtonLS[byte]['text'])
                                if ButtonLS[byte]['text'] =='1':
                                    print("set 1\n")
                                    ButtonLS[byte]['text'] = '0'#line[33:34]#line[44:] #data 33
                                    break
                                else: 
                                    ButtonLS[byte]['text'] = '1'#line[33:34]#line[44:] #data 33
                                    print("set 0\n")
                                    break
                                
                          if re == 'no':
                              break
                else:
                    if line[0:8] == "#END_CFG":
                        tkinter.messagebox.showwarning(title='请确认该bit位',message='☞请确认该bit位是否被使用?\n未被使用的bit位无相应的bit 信息说明\n')
                          
            except:
                if line[0:8] == "#END_CFG":
                    tkinter.messagebox.showwarning(title='请检查CAN ID',message='☞请设置CAN ID\nCAN ID未设置无法查看bit 信息\n')
        f.close()
        
     
app = Application()
app.master.title('CAN协议解析工具     ' + time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) +'                                                                作成者;タイカイヘイ20180811')
app.master.geometry('939x560')
app.master.resizable(width=True,height=True)   # 固定长宽不可拉伸
app.mainloop()

猜你喜欢

转载自blog.csdn.net/daihuibing389/article/details/81773118
今日推荐