Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When does queryPid return true? #248

Open
Ryccoo opened this issue May 1, 2024 · 4 comments
Open

When does queryPid return true? #248

Ryccoo opened this issue May 1, 2024 · 4 comments

Comments

@Ryccoo
Copy link

Ryccoo commented May 1, 2024

Looking at the code for queryPid method, the docs states:

ELMduino/src/ELMduino.cpp

Lines 575 to 579 in 5d04161

Return:
-------
* bool - Whether or not the query was submitted successfully
*/
bool ELM327::queryPID(const uint8_t &service, const uint16_t &pid, const uint8_t &num_responses)

It seems to return the value of connected

ELMduino/src/ELMduino.cpp

Lines 579 to 585 in 5d04161

bool ELM327::queryPID(const uint8_t &service, const uint16_t &pid, const uint8_t &num_responses)
{
formatQueryArray(service, pid, num_responses);
sendCommand(query);
return connected;
}

Looking into the sendCommand method that is called by queryPid

void ELM327::sendCommand(const char *cmd)

it sets connected to false

connected = false;

never setting it back to true.

This looks like queryPid would always return false ?

@PowerBroker2
Copy link
Owner

There are a couple places where the class can detect a good connection:

In get_response() we have:

connected = true;

And in initializeELM() we have:

connected = true;

connected = true;

connected = true;

@PowerBroker2
Copy link
Owner

Looking closer, it seems queryPid() returns before calling get_response(), so it will return false all the time. Let me look into this and see if there's a good work around. I may simply turn queryPid() into a void return function since the determination as to if the ELM327 is connected or not happens during the parsing - not querying. Therefore returning the connected status may be irrelevant here.

@Ryccoo
Copy link
Author

Ryccoo commented May 1, 2024

Yeah that is the case, the docs threw me off
* bool - Whether or not the query was submitted successfully
and also I was using an example from 4 years ago that someone else made, which was prior to the non-blocking / blocking commands, when queryPid used to have get_response code still in it, meaning it read stuff and also returned proper boolean

jimwhitelaw added a commit to jimwhitelaw/ELMduino that referenced this issue May 18, 2024
- change return type for queryPID() methods
- update code comments for queryPID()
- update README document
- update code comments for conditionResponse()
@jimwhitelaw
Copy link
Collaborator

@Ryccoo I just committed a fix for this inconsistency. As suggested by @PowerBroker2, queryPID() now returns void. The code comments and documentation now reflect this. Thanks for finding the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants