Pyserial, Getting extra info from OBD Device

邮差的信 提交于 2019-12-08 03:09:55

问题


I am new at programming and am trying to communicate with my vehicle with an OBD II device. Serial to USB. I've done what I want it to do but I get the command I entered to print out. How do I just get the information from the device?

Heres my code. I am using Python 3.2.3

import serial
import time
import string
import io
import os
import sys
ser = serial.Serial("/dev/ttyUSB1")
ser.baudrate = 38400
s = input('Enter AT command --> ')
print ('AT command = ' + s)
ser.write(bytes(s + '\r\n', encoding = 'utf-8'))
ser.timeout = 1
response = ser.read(999).decode('utf-8')
print(response)
ser.close()  

And here is what prints out when I enter the command 'atrv'.

>>> 
Enter AT command --> atrv
AT command = atrv
atrv
0.1V
>>>

How do I prevent the 'atrv' above the 0.1V from printing out?


回答1:


Send ATE0 to the ELM-device.

This disables the echo, so atrv won't be send back to you!

Have a look into this: http://elmelectronics.com/DSheets/ELM327DS.pdf , collection of lots of AT commands, could be helpful!




回答2:


on a raspberry PI i had to modify the code to:

import serial
import time
import string
import io
import os
import sys

ser = serial.Serial("/dev/rfcomm0")
ser.baudrate = 115200
s = input('Enter AT command --> ')
print ('AT command = ' + s)
ser.flushInput();
ser.write(bytes(s + '\r\n', encoding = 'utf-8'))
ser.flush();
ser.timeout = 1
response = ser.read(999).decode('utf-8')
print(response)
ser.close()


来源:https://stackoverflow.com/questions/19455969/pyserial-getting-extra-info-from-obd-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!