Delay that don't delay.. to be or not to be? :D (Multiple AT commands on a BT ELM327)

I'm trying to send a list of elements (AT commands) to a procedure and want to have a delay between each one but it seems that something is not as i think it would be.
The app immediatly goes to the last element on list. I also put some Messages (Notify) to see if something went wrong in the list but it doesn't seems to be.
These are the blocks:



Could someone try to suggest something? Thanks

PS: Bluetooth block is disable so i/you could try to test

You need to copy the lstCAR.Elements to a global temporary list acting as a transmission queue, and a way to know when to send item 1 from the queue and pop it off the queue, depleting the queue as you send.

Does your device return an acknowledgement message that could be used as an okay to send the next message?

Or would you do the depletion and transmission of the next command in a Clock Timer (not as good, it's slower and disregards feedback.)

I did a recent tutorial showing how to use a queue of CloudDB tags to gather their values one by one, using a similar technique.

2 Likes

I would like to add that App Inventor's event model requires that an event handler's blocks must complete before control is returned to the Android or iOS runtime, which includes among other things updating the user interface with new content. If you schedule a UI change, such as a notifier alert, then you won't see them take effect until after the event block ends. This is particularly important if you schedule things in a loop, because what may effectively happen is you will spawn N dialogs where N is the number of iterations of the loop. Importantly with the Notifier component, the Notifier is not a blocking operation, so it doesn't cause the loop to "pause" to show you what is going on.

1 Like

Thanks for your replies.
First thing now i know better what is happening inside the event model of AI (tks ewpatton) PS: i know that Notify doesn' stop the flow but used only for seeing what passes on original "for" cycle :wink:
I follow something similar to what ABG said and now i have what i need. (tks ABG).
I put here my little contribute to all as an example of what to do for a delay between multiple actions in a list (in this case multiple AT commands sent via Bluetooth connection).
Tested and working

blocks (7)



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.