Question to Bluetooth, Timer / Clock and Event-Processing

I have a question regarding receiving Bluetooth Data (BT) from an Arduino. Sending and receiving works but I have a question to the logic in AI2 itself. I use a clock to check if there are values available. The clock is set to fire the event every 200ms. Now… when the logic finds out, that there are values available, keeps the logic than in the procedure to receive values means… is the BT buffer read completely and the following logic is processed or can the receive logic in mentioned procedure be interrupted by a new fired event (every 200ms) by the timer? In other words: stops a fired event by a timer the actually processed block (e.g. a procedure) and continues at the stopped position in the block after the event is over or is a event only recognized between other events means if there is no other logic (e.g. a procedure) active? So I think if the logic “if BytesAvailableToReceive > 0 do” must be changed to “while BytesAvailableToReceive > 0 do…”

It is difficult to explain. What I try to understand or what I try to do is: I check with a ping / heartbeat if the Bluetooth connection is valid. If not I disconnect and visualize it on the screen. The user has to establish a new connection. But what happens with the values which were received short before the connection was interrupted and that values are stored in a BT value buffer (where ever it is). Or is this a situation which can not happen as I constructed theoretically. Or should I simply remove the “IF Bluetooth.Client1. isAvailable” logic to ensure to receive all possible values recardless if there is a interrupted connection? But that would mean that the timer which fires the event to call the receive logic can not be stopped (loss of connection) and started (establish a connection) but has to be active all the time…


The ReceiveText(-1 bytes) is meant to work with a BlueTooth Client Delimiter attribute set to 10 (newline).

It grabs just the incoming bytes up to the next newline, and leaves the rest in the buffer for the next receiveText attempt.

AI2 is single threaded, so the next Clock Timer won't fire until this event completes.

For more discussion of the execution model, see

1 Like

Many thanks for your reply. All my questions are answered in an very efficient way. Unfortunately I couldn't answer my question in that pricise way :wink: Thanks also for the addionaly provided links. I hat a first look but will go more into detail on weekend latest. Especially the Async Procedure Extension sound very interesting.

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