473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Re: Help with pyserial and sending binary data?

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
0 1333

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: alastair | last post by:
Hi, I'm using pyserial to transfer data from PC to another device - the data is either from an ASCII file or binary data file. Everything works fine up until I start using files of a particular...
3
by: ouz as | last post by:
hi, I want to transfer 0 bit and 1 bit in order with pyserial.But pyserial only send string data. Can anyone help me? Sorry about my english.. ...
5
by: aladdinm1 | last post by:
Hi All, I have an annoying trouble with binary serialization. I have a windows forms application which works like a server and keeps sending data to its clients. The data is serialized before...
4
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
5
by: Mimi | last post by:
Hi, I use the pyserial to read data from a serial port. My code is in window Xp and python 2.4. when I use Hyperteminal I can read data without try and try again that it is not the case with...
9
by: thorley | last post by:
Greetings, since there was no reponse to my previous post about an existing FastCGI server in python, I've taken to writing my own. (which of course I'll share--*if* there's something to share ;) ...
1
by: Rich | last post by:
Hello, 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...
4
by: Xavier | last post by:
Hi, I try to access to a Bluetooth GPS data-logger with Python. I use pySerial. Sending and receiving little messages (~100 char) works fine. However, when I ask the GPS to dump the trails,...
5
by: zxo102 | last post by:
Hello All, I have a system. An instrument attched to 'com1' is wireless connected to many sensors at different locations. The instrument can forward the "commands" (from pyserial's write()) to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.