How the non-blocking execution model works
masterELMduino uses a non-blocking execution model. When you call a PID query function (e.g., myELM327.rpm()), the function returns immediately without waiting for the hardware response. This allows your main loop() to continue executing other tasks.
To retrieve the data, you must monitor the nb_rx_state property. You should repeatedly call the PID query function and check the state until it reaches a terminal state:
ELM_SUCCESS: The data has been successfully received and is ready to use.ELM_GETTING_MSG: The library is still waiting for a response from the ELM327. Continue your loop and check again later.- Error State: If
nb_rx_stateis neitherELM_SUCCESSnorELM_GETTING_MSG, an error has occurred. UsemyELM327.printError()to diagnose the issue.
CRITICAL RULE: Do not attempt to query more than one PID at a time. You must wait for the current PID query to reach ELM_SUCCESS or an error state before initiating the next query.
// Example of the non-blocking pattern
rpm = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
// Use the data
} else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
// Handle error
myELM327.printError();
}