mickeyl / LTSupportAutomotive

An iOS / watchOS / macOS support library for OBD2, VIN-Decoding, and more.
MIT License
212 stars 59 forks source link

How to Connect to ODB with USB? (help wanted) #16

Closed theUnnamed2 closed 5 years ago

theUnnamed2 commented 5 years ago

Hello I wanted to transform the ios code to mOS. So that there is also a simple example for mOS I saw now that the application connects via Bluetooth. Is it also possible to connect via USB and how would it be done?

mickeyl commented 5 years ago

One of the design goals of LTSupportAutomotive was to encode the protocol logic completely independent from the transport engine, that's why LTOBD2Adapter has the signature:

-(nullable instancetype)initWithInputStream:(NSInputStream*)inputStream outputStream:(NSOutputStream*)outputStream NS_DESIGNATED_INITIALIZER;

As far as I know, USB-OBD2 cables mount themselves as serial tty devices, hence to connect to an USB adapter, all you have to do is open an NSInputStream and an NSOutputStream and feed them into the constructor of an LTOBD2Adapter subclass.

Can you give that a try and please give some feedback?

(In any case, I plan to buy an USB OBD2 adapter over the next months (in preparation to write an OBD2 app for macOS), so if you can wait a couple of weeks, I'll take care of it.)

theUnnamed2 commented 5 years ago

First: Thank you for your reply :D I will try it once i find the time and then write my results here. I also tried this python lib (https://github.com/brendan-w/python-OBD) to connect over odb2 and it worked fine. After it worked i got excited about odb2 and i wanted to learn more about it and enlarge the lib with more commands. But idk where to find documentations and information on the topic. Most pages look shady or have just basic information. Maybe you can know where to find some good information? I am just curious and want to see what things you can do on the car. By the way i am mech engineering student and have access to norms at Perinorm. Maybe you can tell me which norms i have to look up? The car of my dad is a opel astra caravan H and i read that it uses CAN_500KBPS. I would be thankful if you can tell me where to find information on the topic :D

mickeyl commented 5 years ago

OBD2 is quite well standardized. Everything interesting for one who is developing OBD2 software can be found in SAE1979 and SAE1979_DA. If you have these standard documents, you're quite well equipped. The Wikipedia pages are a good source as well, but they contain only excerpts of the official standard documentations and are a bit outdated. Unfortunately SAE charges money for these documents, that's why they're not on the internet. They're not too expensive though (ISO documents are often way more expensive) and worth the money IMO.

mickeyl commented 5 years ago

I have bought the OBDLINK SX USB/OBD2 adapter. As expected, this mounts as a usbserial device node:

% ls -l /dev/*usbserial*
crw-rw-rw-  1 root  wheel   21,   7 13 Aug 14:08 /dev/cu.usbserial-113010893810
crw-rw-rw-  1 root  wheel   21,   6 13 Aug 13:40 /dev/tty.usbserial-113010893810

With a tiny bit of configuration glue (done in ref 81c6453f2ae89b518f120497589465a9f3eee89c), I could talk with this USB adapter.