Home AMX User Forum NetLinx Studio

WAIT_UNTIL with a function to check Variable

I have not had a chance to test this, I just thought I would ask some of the more experienced among us.

Thank you, in advance, for any input.

I am curious about how WAIT_UNTIL works with a function as the check.
i.e. WAIT_UNTIL (System_Ready() == True) 'Wait_Until_System_Ready'
Will the Function be called more than once?

Define_Function Integer System_Ready()
{
Stack_Var Integer Result;
Result = True;
if ( (bSystem_Ready and other Variables) == True;
Result = True;
return Result;
}
Define_Function DoSomethingWhenSystemIsReady()
{
WAIT_UNTIL (System_Ready() == True) 'Wait_Until_System_Ready'
{
//Do Something
}
}

Comments

  • mpullinmpullin Posts: 949
    I haven't tried it. It's an interesting question. You could test it yourself by putting a SEND_STRING 0, 'i am here' inside your System_Ready() and looking in diagnostics to see how often that string appears.

    This looks a little suspicious to me and I would probably create a separate variable, say, nSystemReady, and then in my DEFINE_PROGRAM put something like
    wait 10 if(nSystemReady == false){
         if(System_Ready()){
              nSystemReady = true;
              // do stuff
         }
    }
    
    that way we have control over how often the SystemReady flags are checked.
  • viningvining Posts: 4,368
    I thought wait until basically suspends the mainline until it evaluates true which is why it's recommended to use wait until timed. I would suspect it's a loop like while & for and we all know what happens when they never exit. This is one keyword i've never used but it you wanted to test i don't think i do the send string zero exactly as Matt suggested but create local or global var counter and increment it " nVar++" on each call of the function and then just do a send string 0 when it evaluates as true including the count in the string and then reset the counter. My gut says it will run just like any loop and just sending send string 0's that fast would likely kill the system.
  • Well it works the way I would expect, and it does not suspend EVENTS,
    but DEFINE_PROGRAM does not get run.
    CORRECTION: DEFINE_PROGRAM does get run.
    That is OK for me as I do not do much in DEFINE_PROGRAM.

    Thank you all for your input.
    Thank you Vining, for the suggestion for the TIMED_WAIT_UNTIL.

    Results from test:
    GET STATUS
    Line 1 (15:43:56):: Status:
    Line 2 (15:43:56):: SystemOn=0
    Line 3 (15:43:56):: DisplayPower=0
    RUN TIMED_WAIT_UNTIL
    Line 4 (15:44:01):: WAIT_UNTIL Test
    Line 5 (15:44:01):: Checking to see if System Is Ready
    Line 6 (15:44:01):: Checking to see if System Is Ready
    Line 7 (15:44:01):: Checking to see if System Is Ready
    Line 8 (15:44:01):: Checking to see if System Is Ready
    Line 9 (15:44:02):: Checking to see if System Is Ready
    Line 10 (15:44:02):: Checking to see if System Is Ready
    Line 11 (15:44:03):: Checking to see if System Is Ready
    Line 12 (15:44:03):: Checking to see if System Is Ready
    Line 13 (15:44:04):: Checking to see if System Is Ready
    Line 14 (15:44:04):: Checking to see if System Is Ready
    Line 15 (15:44:05):: Checking to see if System Is Ready
    Line 16 (15:44:05):: Checking to see if System Is Ready
    Line 17 (15:44:06):: Checking to see if System Is Ready
    Line 18 (15:44:06):: Checking to see if System Is Ready
    Line 19 (15:44:07):: Checking to see if System Is Ready
    Line 20 (15:44:07):: Checking to see if System Is Ready
    Line 21 (15:44:08):: Checking to see if System Is Ready
    Line 22 (15:44:08):: Checking to see if System Is Ready
    Line 23 (15:44:09):: Checking to see if System Is Ready
    Line 24 (15:44:09):: Checking to see if System Is Ready
    Line 25 (15:44:10):: Checking to see if System Is Ready
    Line 26 (15:44:10):: Checking to see if System Is Ready
    Line 27 (15:44:11):: Checking to see if System Is Ready
    Line 28 (15:44:11):: Checking to see if System Is Ready
    Line 29 (15:44:12):: Checking to see if System Is Ready
    Line 30 (15:44:12):: Checking to see if System Is Ready
    Line 31 (15:44:13):: Checking to see if System Is Ready
    Line 32 (15:44:13):: Checking to see if System Is Ready
    Line 33 (15:44:14):: Checking to see if System Is Ready
    Line 34 (15:44:14):: Checking to see if System Is Ready
    Line 35 (15:44:15):: Checking to see if System Is Ready
    Line 36 (15:44:15):: Checking to see if System Is Ready
    Line 37 (15:44:16):: Checking to see if System Is Ready
    Line 38 (15:44:16):: Checking to see if System Is Ready
    Line 39 (15:44:17):: Checking to see if System Is Ready
    Line 40 (15:44:17):: Checking to see if System Is Ready
    Line 41 (15:44:18):: Checking to see if System Is Ready
    Line 42 (15:44:18):: Checking to see if System Is Ready
    Line 43 (15:44:19):: Checking to see if System Is Ready
    Line 44 (15:44:19):: Checking to see if System Is Ready
    Line 45 (15:44:20):: Checking to see if System Is Ready
    Line 46 (15:44:20):: Checking to see if System Is Ready
    Line 47 (15:44:21):: Checking to see if System Is Ready
    Line 48 (15:44:21):: Checking to see if System Is Ready
    Line 49 (15:44:22):: Checking to see if System Is Ready
    Line 50 (15:44:22):: Checking to see if System Is Ready
    Line 51 (15:44:23):: Checking to see if System Is Ready
    Line 52 (15:44:23):: Checking to see if System Is Ready
    Line 53 (15:44:24):: Checking to see if System Is Ready
    Line 54 (15:44:24):: Checking to see if System Is Ready
    Line 55 (15:44:25):: Checking to see if System Is Ready
    Line 56 (15:44:25):: Checking to see if System Is Ready
    Line 57 (15:44:26):: Checking to see if System Is Ready
    Line 58 (15:44:26):: Checking to see if System Is Ready
    Line 59 (15:44:27):: Checking to see if System Is Ready
    Line 60 (15:44:27):: Checking to see if System Is Ready
    Line 61 (15:44:28):: Checking to see if System Is Ready
    Line 62 (15:44:28):: Checking to see if System Is Ready
    Line 63 (15:44:29):: Checking to see if System Is Ready
    Line 64 (15:44:29):: Checking to see if System Is Ready
    Line 65 (15:44:30):: Checking to see if System Is Ready
    Line 66 (15:44:30):: Checking to see if System Is Ready
    Line 67 (15:44:31):: Checking to see if System Is Ready
    Line 68 (15:44:31):: Checking to see if System Is Ready
    Line 69 (15:44:31):: Checking to see if System Is Ready
    Line 70 (15:44:31):: Checking to see if System Is Ready
    TIMED OUT
    GET STATUS
    Line 71 (15:48:46):: Status:
    Line 72 (15:48:46):: SystemOn=0
    Line 73 (15:48:46):: DisplayPower=0
    RUN TIMED_WAIT_UNTIL
    Line 74 (15:48:56):: WAIT_UNTIL Test
    Line 75 (15:48:56):: Checking to see if System Is Ready
    Line 76 (15:48:56):: Checking to see if System Is Ready
    Line 77 (15:48:56):: Checking to see if System Is Ready
    Line 78 (15:48:56):: Checking to see if System Is Ready
    Line 79 (15:48:57):: Checking to see if System Is Ready
    Line 80 (15:48:57):: Checking to see if System Is Ready
    Line 81 (15:48:57):: Checking to see if System Is Ready
    SET BOTH VARS ON
    ...
    TIMED_WAIT_UNTIL executes code
    Line 82 (15:48:57):: System Is Ready
    GET STATUS
    Line 83 (15:48:57):: Status:
    Line 84 (15:48:57):: SystemOn=1
    Line 85 (15:48:57):: DisplayPower=1


    TP has 6 buttons
    1:Set VARS ON
    2:Set VARS OFF
    3:Toggle System Var
    4:Toggle Display Var
    5:Send Status
    6:Run TIMED_WAIT UNTIL

    Code:
    PROGRAM_NAME='TestSystem'
    (***********************************************************)
    (* FILE CREATED ON: 09/26/2012 AT: 14:36:14 *)
    (***********************************************************)
    (* FILE_LAST_MODIFIED_ON: 09/26/2012 AT: 15:47:31 *)
    (***********************************************************)

    (***********************************************************)
    (* DEVICE NUMBER DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_DEVICE
    dvTP1Main = 10001:1:1;//Misc System Control

    (***********************************************************)
    (* CONSTANT DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_CONSTANT
    SYSTEM_READY_TIMEOUT = 300;//30 Seconds

    (***********************************************************)
    (* VARIABLE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_VARIABLE
    VOLATILE Integer btnsTest [] =
    {
    1, 2, 3, 4, 5, 6
    }
    VOLATILE Integer SystemOn;
    VOLATILE Integer DisplayPower;
    (***********************************************************)
    (* THE FUNCTIONS GO BELOW *)
    (***********************************************************)
    Define_Function Integer TSystem_IsReady()
    {
    Stack_Var Integer Result;
    Result = True;
    Send_String 0, 'Checking to see if System Is Ready';
    if ( !SystemOn || !DisplayPower)
    Result = False;
    return Result;
    }
    (***********************************************************)
    (* THE EVENTS GO BELOW *)
    (***********************************************************)
    DEFINE_EVENT
    Button_Event [dvTP1Main, btnsTest]
    {
    PUSH:
    {
    Switch ( Button.Input.Channel )
    {
    Case 1:
    {
    SystemOn = True;
    DisplayPower = True;
    Break;
    }
    Case 2:
    {
    SystemOn = False;
    DisplayPower = False;
    Break;
    }
    Case 3:
    {
    SystemOn = !SystemOn;
    Break;
    }
    Case 4:
    {
    DisplayPower = !DisplayPower;
    Break;
    }
    Case 5:
    {
    Send_String 0, "'Status:'";
    Send_String 0, "'SystemOn=', itoa(SystemOn)";
    Send_String 0, "'DisplayPower=', itoa(DisplayPower)";
    Break;
    }
    Case 6:
    {
    Send_String 0, 'WAIT_UNTIL Test';
    CANCEL_WAIT_UNTIL 'WAIT_UNTIL Test';
    TIMED_WAIT_UNTIL ( TSystem_IsReady() )
    SYSTEM_READY_TIMEOUT 'WAIT_UNTIL Test'
    {
    Send_String 0, 'System Is Ready';
    };
    Break;
    }
    }
    }
    }

    (***********************************************************)
    (* STARTUP CODE GOES BELOW *)
    (***********************************************************)
    DEFINE_START
    {
    SystemOn = False;
    DisplayPower = False;
    }
    (***********************************************************)
    (* THE ACTUAL PROGRAM GOES BELOW *)
    (***********************************************************)
    DEFINE_PROGRAM
    {
    Wait 5
    {
    Send_String 0, 'Running DEFINE_PROGRAM';
    };
    }
Sign In or Register to comment.