By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Re: Help with pyserial and sending binary data?

P: n/a
En Fri, 02 May 2008 16:50:46 -0300, Rich <ri*********@yahoo.comescribió:
I am working on a python library for sending and receiving data from a
Subaru's ECU (the fuel injection computer) via the OBD-II port and an
OBD to USB cable, with the Subaru Select Monitor protocol. There are a
#--------------------------
import serial, string
output = " "
ser = serial.Serial('/dev/ttyUSB0', 4800, 8, 'N', 1, timeout=1)
ser.write(chr(0x80)+chr(0x10)+chr(0xF0)+chr(0x01)+ chr(0xBF)+chr(0x40))
while output != "":
output = ser.read()
print hex(ord(output))
#--------------------------

The only problem is that when I send the ECU init command, it just echos
back the data I sent it, which, from my understanding, means that I sent
an invalid request packet.[...]
My best guess I have heard is that chr() isn't encoding the hex value
properly to a byte value the ECU understands (wrong endianness?), or
chr() encoding isn't always representing hex as an 8-bit byte. chr()
should always encode to an 8-bit byte (not 7-bit ASCII or anything,
correct)? Is there any way to switch byte endianness, or ensure I am
encoding 8-bit bytes? Any help is much appreciated. Thanks!
No, chr works as it should. The same thing can be written as
ser.write("\x80\x10\xF0\x01\xBF\x40")
Are you sure you're talking to the right device, /dev/ttyUSB0? Are the
comm parameters correct?
(BTW, if you get more than a single character per loop, the print
statement will fail - try with ser.read(1))

--
Gabriel Genellina

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.