@@ -117,7 +117,7 @@ bool ELM327::initializeELM(const char &protocol, const byte &dataTimeout)
117117 // the timeout value to 30 seconds, then restore the previous value.
118118 uint16_t prevTimeout = timeout_ms;
119119 timeout_ms = 30000 ;
120-
120+
121121 int8_t state = sendCommand_Blocking (" 0100" );
122122
123123 if (state == ELM_SUCCESS)
@@ -203,6 +203,8 @@ void ELM327::formatQueryArray(uint8_t service, uint16_t pid, uint8_t num_respons
203203 Serial.println (pid);
204204 }
205205
206+ isMode0x22Query = (service == 0x22 && pid <= 0xFF ); // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
207+
206208 query[0 ] = ((service >> 4 ) & 0xF ) + ' 0' ;
207209 query[1 ] = (service & 0xF ) + ' 0' ;
208210
@@ -616,7 +618,7 @@ double ELM327::processPID(const uint8_t &service, const uint16_t &pid, const uin
616618 {
617619 nb_query_state = SEND_COMMAND; // Reset the query state machine for next command
618620
619- findResponse ();
621+ findResponse (service, pid );
620622
621623 return conditionResponse (numExpectedBytes, scaleFactor, bias);
622624 }
@@ -2312,7 +2314,7 @@ int8_t ELM327::get_response(void)
23122314}
23132315
23142316/*
2315- uint64_t ELM327::findResponse()
2317+ uint64_t ELM327::findResponse(uint8_t &service )
23162318
23172319 Description:
23182320 ------------
@@ -2326,7 +2328,7 @@ int8_t ELM327::get_response(void)
23262328 -------
23272329 * uint64_t - Query response value
23282330*/
2329- uint64_t ELM327::findResponse ()
2331+ uint64_t ELM327::findResponse (const uint8_t &service, const uint8_t &pid )
23302332{
23312333 uint8_t firstDatum = 0 ;
23322334 char header[7 ] = {' \0 ' };
@@ -2344,8 +2346,18 @@ uint64_t ELM327::findResponse()
23442346 {
23452347 header[0 ] = query[0 ] + 4 ;
23462348 header[1 ] = query[1 ];
2347- header[2 ] = query[2 ];
2348- header[3 ] = query[3 ];
2349+ if (isMode0x22Query) // mode 0x22 responses always zero-pad the pid to 4 chars, even for a 2-char pid
2350+ {
2351+ header[2 ] = ' 0' ;
2352+ header[3 ] = ' 0' ;
2353+ header[4 ] = query[2 ];
2354+ header[5 ] = query[3 ];
2355+ }
2356+ else
2357+ {
2358+ header[2 ] = query[2 ];
2359+ header[3 ] = query[3 ];
2360+ }
23492361 }
23502362
23512363 if (debugMode)
@@ -2359,7 +2371,7 @@ uint64_t ELM327::findResponse()
23592371
23602372 if (firstHeadIndex >= 0 )
23612373 {
2362- if (longQuery)
2374+ if (longQuery | isMode0x22Query )
23632375 firstDatum = firstHeadIndex + 6 ;
23642376 else
23652377 firstDatum = firstHeadIndex + 4 ;
0 commit comments