[feat] add recv speed test by FT232H

This commit is contained in:
zhji 2025-02-20 12:08:42 +08:00
parent 857c57be81
commit e3d0aedd5d

29
python/serial/ft232h.py Normal file
View File

@ -0,0 +1,29 @@
import serial
import time
# 配置串口参数
com_port = 'COM14' # 串口号
baud_rate = 9600 # 波特率,根据下位机配置调整
timeout = 1 # 超时时间
# 打开串口
ser = serial.Serial(com_port, baud_rate, timeout=timeout)
try:
while True:
start_time = time.perf_counter()
data_received = 0
# 在1秒内持续接收数据
while time.perf_counter() - start_time < 1:
data = ser.read(ser.in_waiting or 1)
data_received += len(data)
# 计算并打印接收速率
print(f"接收速率: {data_received} 字节/秒")
except KeyboardInterrupt:
print("程序终止")
finally:
ser.close()