python中串口数据的处理

import serial

ser=serial.Serial("COM3",115200,timeout=0.5)	#打开串口

print("我要开始了:")
while (1):
	ch=ser.read()

	str1=ch.decode("iso-8859-15")	#bytes转str

	if(str1):	#判断数据是否为空,很重要
		l=ord(str1)		#str转int,方便数据计算和处理
		print("%x" % l)	


	pass

猜你喜欢

转载自blog.csdn.net/HES_C/article/details/80497844