python - Using pyUSB to read data from ELM327 OBDII to USB device -


i having problems using pyusb library read data elm327 obdii usb device. know need write command device on write endpoint , read received data on read endpoint. doesn't seem want work me though.

i wrote own class obdusb this:

import usb.core  class obdusb:        def __init__(self,_vend,_prod):      '''handle usb device'''     self.idvendor = _vend     self.idproduct = _prod     self._dev = usb.core.find(idvendor=_vend, idproduct=_prod)       return none   def getdevice(self):     '''must called after constructor'''     return self._dev   def setupendpoint(self):     '''must called after constructor'''     try:          self._dev.set_configuration()      except usb.core.usberror e:         sys.exit("could not set configuration")      self._endpointwrite = self._dev[0][(0,0)][1]     self._endpointread = self._dev[0][(0,0)][0]      #resetting device , setting vehicle protocol (auto)     #20ms required delay between each written command      #atz resets device     self._dev.write(self._endpointwrite.bendpointaddress,'atz',0)     sleep(0.002)     #atsp 0 should set vehicle protocol automatically     self._dev.write(self._endpointwrite.bendpointaddress,'atsp 0',0)      sleep(0.02)      return self._endpointread   def getdata(self,strcommand):      data = []     self._dev.write(self._endpintwrite.bendpointaddress,strcommand,0)     sleep(0.002)     data = self._dev.read(self._endpointread.bendpointaddress, self._endpointread.wmaxpacketsize)      return data 

so use class , call getdata method using code:

import obdusb  #setting library,device , endpoint lib = obdusb.obdusb(0x0403,0x6001) mydev = lib.getdevice() endp = lib.setupendpoint()  #testing getdata function random obd command #0902 vin number of vehicle being requested dataarr = lib.getdata('0902') printresults(dataarr)  raw_input("press key")  def printresults(arr):      size = len(arr)      print "data in buffer:"      in range(0,size):         print "[" + str(i) + "]: " + str(make[i]) 

this ever prints numbers 1 , 60 [0] , [1] element in array. no other data has been return command. case whether device connected car or not. don't know these 2 pieces of information are. expecting return string of hexadecimal numbers. know doing wrong here?

if don't use atst or atat, have expect timeout of 200ms @ start, between every write/read combination.

are sending '\r' after each command? looks don't, it's forever waiting carriage return.

and hint: test 010d or 010c or something. 09xx might difficult expect.

update: can both ways. long 'seperate' each command carriage return.

http://elmelectronics.com/elm327/at_commands.pdf http://elmelectronics.com/dsheets/elm327ds.pdf (expanded list).

that command list quite usefull me.

atat can used adjust timeout. when send 010d, elm chip wait 200 ms, possible reactions. can more returns, waits 200 ms.

what can do, , it's mystery scantools tend implement this:

'010d1/r'

the 1 after command, specifies elm should report back, when has 1 reply bus. reduces delay quite efficiently, @ cost of not able more values address '010d'. (which speed!)

sorry english, hope send in right direction.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -