lemberg / obd2-swift-lib Goto Github PK
View Code? Open in Web Editor NEWcar onboard diagnostic swift library
License: MIT License
car onboard diagnostic swift library
License: MIT License
Hi there,
Thanks so much for this awesome library, great work!
I think there is only one problem where the re-connection doesn't seem to work, every time after I done obd.disconnect() , I won't be able to connect back again unless unplugging the OBD dongle and put it back in.
By tracing the code found that the reconnect fail at InitScannerOperation where it return error "ELM error", I've tried different combination like pauseScan, stopScan, resumeScan doesn't seem to make any difference on this issue. Maybe I've missed something, could you help?
Thank you,
Jack Roderick
Hi all!
Thanks for a great OBD lib.
I just start investigate it and I have a question:
For example I want to get car temperature, using custom comand:
obd.request(command: Command.Custom.digit(mode: 01, pid: 05)) { (descr) in
if let response = descr?.response {
print(response)
}
}
In logs I recieve such data:
Write to OBD Optional("01 05\r")
Wrote 6 bytes
Read 10 bytes
Read 10 bytes
Read 2 bytes
Read complete
41 05 80
41 05 81
Using lib I receive descriptor:
from descriptor I can get Response.
What next steps???
How can I get such command : 41 05 80 ??
desc?.gerResponse = nil
I can get only : desc.response
But : Response has interface:
public var strigDescriptor: String?
public static func ==(lhs: Response, rhs: Response) -> Bool
public var hasData: Bool { get }
Hi @MaxVitruk I encountered an issue about re-connecting OBD. Could you please help?
It's OK to connect -> disconnect -> connect -> ... ->connect without any OBD request in between.
But if I trigger some repeated request, i.e. engine speed, then disconnect and connect, it will fail to re-connect and be blocked in .openingConnection state.
I did a little debugging, looks like OpenOBDConnectionOperation not executed when re-connect. Maybe the repeated requests still in the obdQueue, blocking OpenOBDConnectionOperation to be executed.
-------> Connecting OBD
isExecuting true
-------> OBD current state: .openingConnection
Input stream opened
Output stream opened
isExecuting false
isFinished true
isFinished true
-------> OBD current state: .initializing
open operation completed without errors
Write to OBD Optional("AT WS\r")
Wrote 6 bytes
Read 16 bytes
Read complete
ELM327 v1.5
Write to OBD Optional("AT E0\r")
Wrote 6 bytes
Read 11 bytes
Read complete
AT E0
OK
Write to OBD Optional("AT I\r")
Wrote 5 bytes
Read 14 bytes
Read complete
ELM327 v1.5
Write to OBD Optional("01 00\r")
Wrote 6 bytes
Read 19 bytes
Read 2 bytes
Read complete
41 00 BE 1F A8 13
Set new pid group 0
Set new pid group 0
Write to OBD Optional("AT DP\r")
Wrote 6 bytes
Read 27 bytes
Read complete
ISO 15765-4 (CAN 11/500)
Set OBD protocol to Optional(OBD2.ScanProtocol.CAN29bit250KB)
-------> OBD current state: .connected
-------> Connection success
-------> Disconnect OBD
-------> OBD current state: .none
-------> Connecting OBD
isExecuting true
-------> OBD current state: .openingConnection
Input stream opened
Output stream opened
isExecuting false
isFinished true
isFinished true
open operation completed without errors
Write to OBD Optional("AT WS\r")
-------> OBD current state: .initializing
Wrote 6 bytes
Read 16 bytes
Read complete
ELM327 v1.5
Write to OBD Optional("AT E0\r")
Wrote 6 bytes
Read 11 bytes
Read complete
AT E0
OK
Write to OBD Optional("AT I\r")
Wrote 5 bytes
Read 14 bytes
Read complete
ELM327 v1.5
Write to OBD Optional("01 00\r")
Wrote 6 bytes
Read 19 bytes
Read 2 bytes
Read complete
41 00 BE 1F A8 13
Set new pid group 0
Set new pid group 0
Write to OBD Optional("AT DP\r")
Wrote 6 bytes
Read 27 bytes
Read complete
ISO 15765-4 (CAN 11/500)
Set OBD protocol to Optional(OBD2.ScanProtocol.CAN29bit250KB)
-------> OBD current state: .connected
-------> Connection success
Write to OBD Optional("01 0c\r")
Wrote 6 bytes
Read 13 bytes
Read 2 bytes
Read complete
41 0C 0A 34
Request operation completed
Observer : Optional(OBD2.Mode01Descriptor)
Write to OBD Optional("01 05\r")
Wrote 6 bytes
Read 10 bytes
Read 2 bytes
Read complete
41 05 86
Request operation completed
Write to OBD Optional("01 0c\r")
Wrote 6 bytes
Read 13 bytes
Read 2 bytes
Read complete
41 0C 0A 44
Observer : Optional(OBD2.Mode01Descriptor)
Request operation completed
Write to OBD Optional("01 05\r")
Wrote 6 bytes
Read 10 bytes
Read 2 bytes
Read complete
41 05 86
Request operation completed
Write to OBD Optional("01 0c\r")
Wrote 6 bytes
Read 13 bytes
-------> Disconnect OBD
-------> OBD current state: .none
-------> Connecting OBD
-------> OBD current state: .openingConnection
Hi,
I am trying to get the list of available pids by requesting pid 0x00. However, there is no property of Mode01Descriptor or Response that provides the raw data. Is it possible to access raw data from a request using this library? If not, how can I access the list of available pids?
Thanks
let command = Command.Mode01.pid(number: 00)
obd.request(command: command) { [weak self] (descriptor) in
OperationQueue.main.addOperation {
if let response = descriptor?.response {
// Parse response
}
}
}
Hi @OverSwift @hellensoloviy @MaxVitruk @sergiyloza , I'd like to leverage your lib in my app. My concern is:
Do you have any suggestion?
When I connect to the ELM327 device it sometimes gives me a bus init error like this BUS INIT: ...ERROR
. This means I am connected to the device but the ECU will not accept commands. How do I handle this error state? The ignition is of course on.
Here is the full log
ELM327 v2.1
Write to OBD Optional("AT E0\r")
Wrote 6 bytes
Read 11 bytes
Read complete
AT E0
OK
Write to OBD Optional("AT I\r")
Wrote 5 bytes
Read 14 bytes
Read complete
ELM327 v2.1
Write to OBD Optional("01 00\r")
Wrote 6 bytes
Read 10 bytes
Read 1 bytes
Read 1 bytes
Read 1 bytes
Read 8 bytes
Read complete
BUS INIT: ...ERROR <----------------------------------------
Set new pid group 0
Set new pid group 0
Write to OBD Optional("AT DP\r")
Wrote 6 bytes
Read 13 bytes
Read complete
ISO 9141-2
Set OBD protocol to Optional(OBD2.ScanProtocol.CAN29bit250KB)
------------------------------------
Successfully connected to OBD device
------------------------------------
Attempted the CocoaPods installation but had too many issues with the installation. Then focused on attempting to follow the embedded framework installation, this is where the issues started to become clear, in the main folder there is no 'OBD2Swift.xcodeproj' file however there was one with the same name in the Example folder which I decided to use and continue. I proceeded with the install instructions and went to add the 'OBD2 Swift.framework' to the embedded binaries but cannot find the file anywhere. I also attempted to open the example project and run it as is, but it still failed to have a working import.
'import OBD2_Swift'
This was the import written in the example file so I also tried to change it to 'OBD2Swift' as listed in the installation instructions, but it did not fix anything. Could someone please help attempt to fix the issue so I can use this framework in my product.
I tried this function and do not get the right trouble codes from this function.
func getTroubleCodes() -> [String]
How to connect device using OBD II-swift-lib ? is it possible to connect without device ?
I wanted to know if you support Bluetooth 4.0 LE devices?
Change .defaultRunLoopMode to RunLoop.Mode.default in library
First of all, great work with the library!
I tried out the demo app, and when I press connect, it crashes after some time. The output from the the console says it connects and communicates, see debug output below:
Input stream opened
Output stream opened
isFinished true
isExecuting false
isFinished true
open operation completed without errors
Write to OBD Optional("AT WS\r")
Wrote 6 bytes
Read 16 bytes
Read complete
ELM327 v2.1
Write to OBD Optional("AT E0\r")
Wrote 6 bytes
Read 11 bytes
Read complete
AT E0
OK
Write to OBD Optional("AT I\r")
Wrote 5 bytes
Read 14 bytes
Read complete
ELM327 v2.1
Write to OBD Optional("01 00\r")
Wrote 6 bytes
Read 10 bytes
Read 1 bytes
Read 1 bytes
Read 1 bytes
Read 22 bytes
Read 2 bytes
Read complete
BUS INIT: ...OK
41 00 BE 3E B8 11
Set new pid group 0
Set new pid group 0
Write to OBD Optional("AT DP\r")
Wrote 6 bytes
Read 13 bytes
Read complete
ISO 9141-2
(lldb)
The breakpoint jumps to InitScanerOperation.swift:157 as shown in the screenshot below.
Do you have any idea why it crashes? The debugger does not give much information.
/cheers
Hi there! Can you help me? I wanna know how can I detect if connection wifi device is lost...
Thanks a lot!
Method calculateStringForData(data:) in Descriptor01 class have some problems. Case 1D is returning an empty string.
func calculateStringForData(data : Data) -> String? {
switch pid {
case 0x03:
return calculateFuelSystemStatus(data)
case 0x12:
return calculateSecondaryAirStatus(data)
case 0x13:
return calculateOxygenSensorsPresent(data)
case 0x1C:
return calculateDesignRequirements(data)
case 0x1D:
return ""
case 0x1E:
return calculateAuxiliaryInputStatus(data)
default:
return nil
}
}
As this article says
1D Oxygen sensors present (in 4 banks)
And it is almost like case 0x13
, but there 4 banks instead of 2.
And I can see a not used method calculateOxygenSensorsPresentB()
in Descriptor01. This method is very similar to calculateOxygenSensorsPresent()
which used for case 0x13
.
I recommend to use of to delete calculateOxygenSensorsPresentB()
method, and fix case 0x1D
.
Hi there, when I try to use an AT commando (like At.voltage), the Framework prints on the console the info, but looks like it doesn't store it on the DATA variable...
Set OBD protocol to Optional(OBD2.ScanProtocol.CAN29bit250KB)
Write to OBD Optional("AT RV\r")
Wrote 6 bytes
Read 10 bytes
Read complete
12.4V
Optional(OBD2.Response(timestamp: 2018-01-01 23:22:58 +0000, mode: OBD2.Mode.none, pid: 0, data: nil, rawData: [49, 50, 46, 52, 86, 13, 10, 0, 10, 62], strigDescriptor: nil))
Thanks...
After cloning the repository, there is no OBD2Swift.xcodeproj in the OBD2-Swift folder.
How can I manually install the library?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.