First let me preface with I am new to python, no ego here. I have this code I cobbled together from various sites the ultimate goal of which being that it would output a hex code to an OBD-II chip and wait for a response. This response, also HEX, is converted to decimal processed and sent to the output. Pretty simple right?

Well, there are two problems.

One of which being that .readline() removes the first letter of the response.

For instance if I wanted ">Elm327" I would get back ">lm327".

The other problem the bigger of the two is when I use .readline() I only get the request that I sent for instance if I use this code below:

serialport.write("01 0D \r")
speed_hex = serialport.readline().split(' ')
speed = float(int('0x'+speed_hex[6:8], 0 ))
print 'Speed: ', speed, 'km/h'`  

I want to .readline to return 41 0D 15 instead I get something like E\r\r01 0D \r \r"

speed_hex = serialport.readline().split(' ')  

This also returns an error but I'll make a separate post for that.

Any thoughts? Thanks

有帮助吗?

解决方案

I suspect that your serial port settings don't exactly match those of the board try playing with a terminal until you get the exact settings and then use those.

NB you do not need to prepend the 0x to convert a hex value you can use int(s, 16) where s is your substring.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top