我想通过OBD2使用ELM327记录数据,我是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
在获得每个回复后,它是关闭连接的工作,但它真的很慢......我想在最大值之后获得响应。 1秒。最佳值至少为0.5秒。
有没有人有这个想法或经验? 提前谢谢。
答案 0 :(得分:0)
解决方案是将快速模式设置为false:
connection = obd.OBD(baudrate=38400, fast=False)
功能说明:
fast:允许在发送到汽车之前优化命令。 Python-OBD目前进行了两次这样的优化:
发送回车以重复上一个命令。附加一个 响应限制到命令结束,告诉适配器 在收到N个响应后返回(而不是等待和 最终超时)。可以启用和禁用此功能 个别命令。 禁用快速模式将保证python-OBD为每个请求输出未更改的命令。
来源:LINK