Update asynchronous values โ€‹โ€‹using the GCDAsynSocket api

I am developing one application in which I need to update several parameters at once, such as engine RPM, speed, etc. using the OBD connector. I need to achieve an asynchronous command / response. To do this, I send commands using [gcdAsyncSocket writeData:data withTimeout:-1 tag:uniqueTag]; asynchronously with a unique tag.

But when the gcdAsync delegate method "socketDidReadDatawithTag" is called, it returns data, but it is not correct. eg. If I sent one command "010C \ r" (Read RPM) and "010D \ r" (speed), with tags 263 and 264, respectively, and if I analyze the response with tag 264 in socketDidReadDatawithTag, sometimes it returns me RPM data. (My response gets Mixed up or OBD Device cannot handle asynchronous response)

  NSLog(@"Command Sent for Async : %@",commandString); NSData *data = [commandString dataUsingEncoding:NSASCIIStringEncoding]; long obdObjectTag = [obdObject getPIDTag];//Unique Tag [gcdAsyncSocket writeData:data withTimeout:-1 tag:obdObjectTag]; NSData *readData = [@">" dataUsingEncoding:NSASCIIStringEncoding]; [gcdAsyncSocket readDataToData:readData withTimeout:-1 tag:obdObjectTag]; 

And in socketdidReadDatawithTag data and tag do not match.

+6
source share
1 answer

The OBD-II connector (I believe this is an ELM-327) cannot handle asynchronous calls, as far as I know.

It cannot process multiple requests at once. You send 1 command, and the OBD-II device will collect this information from the OBD bus and return with a response. Then it will process your next command. Of course, the commands you send end in a buffer that will be processed one by one. I think this may be a problem for you, but I'm not sure.

I am not at all familiar with ios programming and what happens to these tags. Have you installed those tags to determine which parameters need data? In the response data, you can also see what parameter it is intended for, so in the answer itself you can see that the data represents RPM or speed, etc.

I hope that part of the OBD-II shed light on it. Most likely, this issue will be discussed for discussion.

0
source

All Articles