pyserial串口发送的数据大于0x20时,收端接收到的数据显示出来会混乱,就是一些其他符号?

发送端

#send
import serial
import time

ser_s=serial.Serial('/dev/ttyUSB0',115200,timeout=0.5)

flag_s=ser_s.is_open #determine the serial port has been opened
if flag_s:
	print('open success\n')
else:
	print('open failed\n')

data_s=[0xFE,0x06,0x90,0x91,0x76,0x3B,0x12,0x32,0xFF]# only 0x12 and 0x32 are the datas I want to send ,the others are fixed
print(data_s)

while True:
 ser_s.write(data_s)

发送端中的数据只有0x12,0x32是需要发送的数据,其余的为包头包尾和其他的。

 

接收端

#receive
import serial
import time
import struct
import numpy as np

ser_r=serial.Serial('/dev/ttyUSB0',115200,timeout=0.5)

flag_r=ser_r.is_open
if flag_r:
	print('open success\n')
else:
	print('open failed\n')

#while True:
# if ser_r.inWaiting()>9:
data_r=ser_r.read(9)

data=str(data_r)
print(data)

data=data.split('\\')
data.remove("b'")

print(data)

接收端从串口中读取9字节的数据,结果如下:

结果:

open success

b'\xfe\x06\x90\x91\x05\x11\x122\xff'
['xfe', 'x06', 'x90', 'x91', 'x05', 'x11', 'x122', "xff'"]
>>> 

发送的数据0x12和0x32在接收端这边就变成了x122。

我初步判断是接收端接收到的是ascii码,当数据小于0x20时,ascii码和hex码能一一对应,所以显示结果正常,当发送的数据大于或等于0x20时,ascii码就不和hex码对应了,所以显示混乱。要让接受端正确接收数据并显示出来,要怎么解决呢??

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。