Wisors / OBD2Connect

This is a simple implementation of a socket connection to OBD2 adapter.
MIT License
24 stars 7 forks source link

'data' in Viewcontroller.swift return null, but 'requestResponse' in 'func handleReceived' show data. #3

Closed autoMD closed 3 years ago

autoMD commented 3 years ago

I see issue in OBDConnection.swift When i connected and send 0100.

self.connection.send(data: "\(String(describing: cmd))\r".data(using: .ascii)!) { data in data.onSuccess { data in print("data:" + data) } }

data return null.

But I print("handleReceived: " + requestResponse) support data of Response

`private func handleReceived(data: Data) {

    pthread_rwlock_wrlock(&self.requestLock)
    defer { pthread_rwlock_unlock(&self.requestLock) }
    guard let response = String(bytes: data, encoding: String.Encoding.ascii) else {
        finishTransmission(result: .failure(.responseIsInvaid)); return
    }

    requestResponse = requestResponse + response

    print("handleReceived: " + requestResponse)
    if requestResponse.hasSuffix(">") {
        finishTransmission(result: .success(requestResponse))
    }
}`

Log: Transmitting data between host and adapter handleReceived: 0100

Connection ready to send data data:0100 -----> data on Viewcontroller.swift

handleReceived: 41 00 BE 3E B8 11 --------> requestResponse on func handleReceived

handleReceived:

Transmitting data between host and adapter handleReceived: 0100

Connection ready to send data data:0100 -----> data on Viewcontroller.swift

handleReceived: 41 00 BE 3E B8 11 --------> requestResponse on func handleReceived

handleReceived:

I think "requestResponse" not asSuffix(">"). Could you fix get response again? I think requestResponse timer low. I am auto locksmith, do not master for fix.hihi. Please help update.

autoMD commented 3 years ago

Could you custom time get response ? B/c every OBD2 adapter have time response different

We rate the minimal response time using the following rough scale:

Minimal response time, ms Rating Reachable in
0...9 Excellent OBDLink MX, CanTieCar, some ELM327 USB devices (depends on USB-UART chip)
10...34 Good ELM327 USB and some ELM327 Bluetooth
35...59 Average ELM327 Bluetooth
60 and higher Bad ELM327 WiFi


Wisors commented 3 years ago

Hey @autoMD, I'm no longer working on this library and can't help you with debuging.

The ">" is the expected ending character of a valid request. It indicates that the device is in the idle state, ready to receive the next command.

You can set a custom timeout for your request by passing a OBDConnectionConfiguration to OBDConnection.init method. The default configuration has a timeout of 1 second.

autoMD commented 3 years ago

Ok thanks @Wisors . I will debug and setting it