进展有点慢了,还是先把调试好的部分代码分享给大家。接收部分代码
def SerRead(self):
while self.ser.alive:
n = self.ser.serSer.inWaiting()
#print ("n=%s" % n)
try:
self.receive_data = ''
if n:
#print u"开始读取"
self.receive_data += self.ser.serSer.read(n).replace(binascii.unhexlify("00"), "")
print ("receive_data is %s" % ord(self.receive_data))
if self.m_rcvBox.GetValue() == 1:
print 'hex16'
self.receive_data = self.space_b2a_hex(self.receive_data)
print 'read5'
#以下没有实现
self.m_rcvtext.AppendText("end", self.receive_data + "n")
print 'read6'
self.m_rcvtext.see("end")
self.receive_data = ""
print 'read end'
except Exception as e:
#logging.error(e)
print 'read error'
self.receive_data = ""
self.ser.stop()
self.ser = None
发送部分代码
def m_send1butOnButtonClick( self, event ):
if self.ser.alive:
send_data = ''
send_data += str(self.m_textCtrl5.GetValue())
print ("send_data is %s" % ord(send_data))
#send_data += chr(97)
#send_data += chr(0x64)
if self.m_rcvBox.GetValue() == 1:
self.ser.write(send_data, isHex=True)
else:
self.ser.write(send_data)
如有高手看到此贴,麻烦指点一下,谢谢!!
发稿与2018年1月26日凌晨
更多回帖