用python写一段代码,实现串口通信编程

print("开始串口通信编程") import serial

打开串口

ser = serial.Serial("COM3", 115200, timeout=1)while True: # 读取接收到的数据 data = ser.read_all() if data != b'': print("收到数据:",data) # 发送数据 ser.write("Hello".encode())ser.close() # 关闭串口

猜你喜欢

转载自blog.csdn.net/weixin_35753431/article/details/129518018