【发布时间】:2017-02-26 13:57:51
【问题描述】:
我想使用 ELM327 通过 OBD2 记录数据,我是 Python 新手。
我可以发送命令并得到响应。但我无法发送更多查询并获得响应,仅针对第一个命令,其余响应为“无”。
我的代码:
import obd, time
connection = obd.OBD(baudrate=38400, fast=True) # auto-connects to USB or RF port
while True:
for i in commands_list:
cmd1 = obd.commands.RPM # select an OBD command (sensor)
response1 = connection.query(cmd1) # send the command, and parse the response
print(response1.value) # returns unit-bearing values thanks to Pint
# connection.close()
cmd2 = obd.commands.COOLANT_TEMP # select an OBD command (sensor)
response2 = connection.query(cmd2) # send the command, and parse the response
print(response2.value)
# connection.close()
time.sleep(0.5)
输出是:(发动机停止,点火)
0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None
预期输出:
0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC
在获得每个响应后关闭连接是可行的,但它真的很慢......我希望在 max 之后获得响应。 1秒。最佳值至少为 0.5 秒。
有人对此有想法或经验吗? 提前致谢。
【问题讨论】: