main UI :
# encoding: UTF-8
'''
Created on 2017-03-06
@author: Harbor
'''
import wx
from serial import Serial
from wx.lib.pubsub import pub
import MySerialThread
class MainUI(wx.Frame):
def ON_btn_openCOM_Clicked(self,evt):
print "ON_btn_openCOM_Clicked===>"
print self.COM_NO.GetValue()
print self.BandRate.GetValue()
print self.DataBit.GetValue()
print self.StopBit.GetValue()
print self.ParityBit.GetValue()
print self.FlowControl.GetValue()
#=======================================================================
# 1.判断串口是否开启
# 2.获取串口相关参数 波特率 数据位 停止位 校验位 流控制
# 3.开启串口
# 4.设置按钮状态
#=======================================================================
if not self.ser.isOpen():
try:
self.ser.timeout = 1
self.ser.xonxoff = 0
self.ser.port = self.COM_NO.GetValue()
self.ser.baudrate = int(self.BandRate.GetValue())
self.ser.bytesize = int(self.DataBit.GetValue())
self.ser.stopbits = int(self.StopBit.GetValue())
self.ser.parity = self.ParityBit.GetValue()[0]
self.ser.open()
except Exception , e:
print 'COMM Open Fail!!',e
else:
self.btn_openCOM.SetLabel(u"关闭串口")
print "=====>串口已开启"
else:
self.ser.close()
# while self.Ser.isOpen(): pass
self.btn_openCOM.SetLabel(u"打开串口")
print "=====>串口已关闭"
def OnDisplayListenner(self,log):
self.display_log.AppendText(log)
def ON_btn_clearCOM_Clicked(self,log):
self.display_log.Clear()
def ON_btn_closeLog_Clicked

本文介绍如何利用Python构建一个简单的串口通信工具KKCOM,主要涉及Python编程和串口通信技术,适用于进行设备调试和数据交互。
最低0.47元/天 解锁文章
2720

被折叠的 条评论
为什么被折叠?



