全球优秀企业网站,做营销看的网站有哪些内容,上海公司章程在哪里可以查询打印,做网站总结工具效果如下如所示 下面简单介绍一下操作流程
1.打开PyCharm软件 2.创建一个工程 3.给该工程命名 4.在main.py里面黏贴如下的代码
# This is a sample Python script.
# Press ShiftF10 to execute it or replace it with your code.
# Press Double Shift to search everyw…工具效果如下如所示 下面简单介绍一下操作流程
1.打开PyCharm软件 2.创建一个工程 3.给该工程命名 4.在main.py里面黏贴如下的代码
# This is a sample Python script.
# Press ShiftF10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import serial
import threading
import timefrom tkinter import *
from tkinter.ttk import *
from tkinter import messageboxdef open_serial(a,b,c,d,e):global serprint(串口号:,a)print(波特率:,int(b))print(数据位:,c)print(停止位:,d)print(检验位:,e)bytesize serial.EIGHTBITSif c 7:bytesize serial.SEVENBITSprint(select SEVENBITS)if c 6:bytesize serial.SIXBITSprint(select SIXBITS)if c 5:bytesize serial.FIVEBITSprint(select FIVEBITS)stopbitsize serial.STOPBITS_ONEif d 2:stopbitsize serial.STOPBITS_TWOprint(select STOPBITS_TWO)paritysel serial.PARITY_NONEif e Odd:paritysel serial.PARITY_ODDprint(select Odd)if e Even:paritysel serial.PARITY_EVENprint(select EVEN)serserial.Serial(porta,baudrateint(b),bytesizebytesize,stopbitsstopbitsize,parityparitysel,timeout0.5)# ser serial.Serial(COM4, 9600, timeout1)def print_hi(name):# Use a breakpoint in the code line below to debug your script.print(fHi, {name}) # Press CtrlF8 to toggle the breakpoint.def print_log(log):time_start time.time()date time.strftime(%Y-%m-%d %H:%M:%S, time.localtime())print(f{date}-{log})def recv_hander():while 1:if ser.is_open:data ser.read(1024).decode(gbk)print_log(data)msgshow.insert(END, data)def create_recv_thread():global thth threading.Thread(targetrecv_hander)th.setDaemon(True)th.start()def msg_send():msg msginp.get()print_log(fsend{msg})if ser.is_open:ser.write(msg.encode(gbk))def open_com():print_log(open com)com_val comnum.get()baud_val baud.get() # 获取当前选定项目的值databit_val databit.get()stopbit_var stopbit.get()parity_var parity.get()print(com_val)print(baud_val)open_serial(com_val, baud_val, databit_val, stopbit_var, parity_var)if ser.is_open:messagebox.showinfo(标题,串口打开成功)create_recv_thread()def close_com():print_log(close com)if ser.is_open:ser.close()# Press the green button in the gutter to run the script.
if __name__ __main__:print_hi(PyCharm)root Tk()root.geometry(768x512)root.title(串口工具)comnumvar StringVar()baudvar StringVar()databitvar StringVar()stopbitvar StringVar()parityvar StringVar()lb_com Label(root, text串口号)lb_com.place(relx0.01, rely0.05, relwidth0.1, relheight0.1)comnum Combobox(root, textvariablecomnumvar, values[COM1, COM2, COM3, COM4, ])comnum.place(relx0.08, rely0.075, relwidth0.1)comnum.current(3)lb_baud Label(root, text波特率)lb_baud.place(relx0.01, rely0.12, relwidth0.1, relheight0.1) #add 0.045baud Combobox(root, textvariablebaudvar, values[115200, 38400, 9600, 4800, ])baud.place(relx0.08, rely0.145, relwidth0.1) #add 0.025baud.current(2)lb_databit Label(root, text数据位)lb_databit.place(relx0.01, rely0.19, relwidth0.1, relheight0.1) #add 0.045databit Combobox(root, textvariabledatabitvar, values[8, 7, 6, 5, ])databit.place(relx0.08, rely0.215, relwidth0.1) #add 0.025databit.current(0)lb_stopbit Label(root, text停止位)lb_stopbit.place(relx0.01, rely0.26, relwidth0.1, relheight0.1)stopbit Combobox(root, textvariablestopbitvar, values[1, 2, ])stopbit.place(relx0.08, rely0.285, relwidth0.1)stopbit.current(0)lb_parity Label(root, text校验位)lb_parity.place(relx0.01, rely0.33, relwidth0.1, relheight0.1)parity Combobox(root, textvariableparityvar, values[None,Odd,Even,])parity.place(relx0.08, rely0.355, relwidth0.1)parity.current(0)btnopen Button(root, text打开串口, commandopen_com)btnopen.place(relx0.01, rely0.45, relwidth0.1, relheight0.05)btnclose Button(root, text关闭串口, commandclose_com)btnclose.place(relx0.12, rely0.45, relwidth0.1, relheight0.05)lb1 Label(root, text串口数据接收)lb1.place(relx0.25, rely0.05, relwidth0.7, relheight0.1)msgshow Text(root)msgshow.place(relx0.25, rely0.15, relwidth0.7, relheight0.3)lb2 Label(root, text串口数据发送)lb2.place(relx0.25, rely0.45, relwidth0.7, relheight0.1)msginp Entry(root)msginp.place(relx0.25, rely0.55, relwidth0.7, relheight0.1)btnsend Button(root, text发送, commandmsg_send)btnsend.place(relx0.35, rely0.86, relwidth0.3, relheight0.1)root.mainloop()# See PyCharm help at https://www.jetbrains.com/help/pycharm/
5.执行脚本 6.如果有提示“No module named serial”需要安装 pyserial在终端命令行输入pip install pyserial如下图所示 7.在windows下安装一对虚拟串口可以下载vspd安装最终结果如下所示 8.使用第三方工具进行数据互发测试 9.将该工具打包成exe可执行文件
在命令行终端输入python -m pysimplegui-exemaker.pysimplegui-exemaker 最后点击“Make EXE”生成如下所示的exe文件