我有以下 python 程序,它在命令提示符下显示串行数据。
#!python
import time
import cgi
from serial import Serial
import subprocess
ser = Serial('COM4', 115200, timeout=1)
print("connected to: " + ser.portstr)
while True:
# Read a line and convert it from b'xxx\r\n' to xxx
line = ser.readline().decode('utf-8')[:-2]
if line: # If it isn't a blank line
print(line)
if line == '520':
subprocess.call(["xte", "key Up"])
elif line == '620':
subprocess.call(["xte", "key Down"])
elif line == '110':
break
ser.close()
该程序运行完美。数据不断显示在控制台中。基本上它是显示与我想在网页中显示数据的 ping 传感器的距离http://localhost/distance.html
。我将如何做?只显示最后的数据就可以了。感谢所有的建议