• Hi there,

    what am I doing wrong? when I press button A the first time, the routine runs cleanly, i.e. I see the distance from the TOF unit, so we stay in the DO-UNTIL loop until the condition is met. If I then press the button A a second time, the routine will not run cleanly, i.e. we immediately break out of the DO-UNTIL loop. The next time I press button A the DO-UNTIL loop is correct again....etc.

    Thanks for the help.


    Translated with (free version)

    0_1623015178487_Bildschirmfoto 2021-06-06 um 23.31.02.png

  • Hey, the problem of your button handler function is its duration (a good 6 seconds if not more). The problem will be when you call that function again before it finishes its previous action. Uiflow is also a bit weird in automatically generating code based on blocks. And for example all variables declared in functions and callbacks are generated as global variables, not as local as it would look from block vizualization.

    And now your key handler function runs and sets a control variable (global) then conditions its further action on this variable.
    In the meantime you run a second instance of the "same" function which suspends the first one and now this second instance of the function changes the values of your variables (global) which after the end of this instance of the function will still be used by the previously called function. Alternatively, the action of this second function will be determined by what variables were changed by the first function call.

    You can check at the very beginning of the function if the variable is_running (example name) is True, if so, exit the function. Then you set is_running to true, then your code and at the very end of your code in the function you set is_running to false. Then next execution of this function during previous one will break it.

    Something like this

    # initial value of semafor
    # put below line at begining
    # of your program
    is_running = False
    # put this inside your function
    if is_running:
        is_running = True
        # insert
        # your code
        # here
        is running = False

  • Hey robalstona,

    Thanks for your answer. You are right this could be the problem. I will try it out in the near future.