473,890 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Help with pyserial and sending binary data?

En Fri, 02 May 2008 16:50:46 -0300, Rich <ri*********@ya hoo.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(0 x80)+chr(0x10)+ chr(0xF0)+chr(0 x01)+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\xB F\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 1371

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

Similar topics

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 size on Linux, around 1.3MB. When I send the data on windows everything is ok - on Linux I get the following traceback:
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.. _________________________________________________________________ Depolama alani sikintisindan kurtulun - hemen Hotmail'e üye olun! http://odeme.hotmail.com.tr
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 being sent using BinaryFormatter and a serializable object. When using a windows forms application as a client, everything works just fine and deserialized data can be received intact. When the client application is is embedded in Internet Explorer (I...
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. I need to be able to print shipping labels from a web page within this application. The shipping label data is pulled from a 3rd party application and comes in binary format specific for certain brands of label printers. I have a class library...
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 pyserial library. anyone can help me ? this is a part of my code: self.ser = serial.Serial() self.ser.baudrate = 9600
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 ;) My problem now, is that I need to send certain binary data over a socket. That is, I want to make some bytes, and stuff them in a TCP packet, send them down the pipe, and then listen for a response. socket.send, as best I can tell, will only...
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 protocol. There are a few open source programs that do this already (http://romraider.com/ , http://jdash.sourceforge.net/ , http://tari.co.za/downloads/software/source/ ), but they are written in Java or C++. I have never done anything with serial...
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, it returns some Mbytes and here is the problem : in the stream of bytes, I randomly losts chunks of ~100bytes.
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 those sensors. Based on the "commands", the sensors keep sending corresponding data back to the instrument which wraps up those data and put into "com1" . The readlines() of pyserial pick up those data for processing. The data ’string' does...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.