Showing results 1 to 6 of 6

Thread: Time Delay in Script execution

  1. #1
    Join Date
    04.09.2009
    Posts
    84

    Default Time Delay in Script execution

    Hi there,

    Can I introduce time delay in function execution of a particular script. Suppose I have 2 functions in a script, one function is executed and I want the other function to be executed after a certain amount of delay. Possible?

  2. #2

    Default Re: Time Delay in Script execution

    there are currently no direct delays possible with a group of functions in a a script. But maybe you can explain which functions should be executed with a delay, and why you require the delay. There may be other solutions for this

    There are a few ways however, with which you can achieve such steps with delays at executing functions.

    The most flexible way is by using straton and a small SFC (sequential function chart) program. Here you can define conditions and transitions for each step (state) in the program. By using boolean variables at each step, you can execute functions in zenon. For the change to the next state, e.g. you could start a timer and wait until the timer is finished.

    If you need just a single delay between two functions, you could add the first function to the script, and instead of the second function, use a function "set value" to a boolean variable of the internal driver. At the limit of the boolean variable you can specify a delay of e.g. 2 seconds, and execute a script at this limit, to reset the boolean variable and execute the delayed function.

  3. #3
    Join Date
    05.01.2012
    Posts
    29

    Beitrag AW: Time Delay in Script execution

    for everybody who is interested in VBA "sleep" function, I solved it this way:

    In VBA script I set a BOOL variable to value 1. This BOOL variable has a REMA where value 1 is configured for Counter 1.
    With a MATH statistic variable "Time Counter" the time (in seconds) will be count when BOOL variable has value 1.
    The "Time Counter" has a upper limit e.g. 25 (sec) that execute a Script function.
    In my case the Script function inkludes
    - the same VBA script from the beginning, but here I have to check that "Time Counter".value is >0
    - reset value of BOOL variable to 0
    - reset value of Time Counter to 0

    --- VBA code example ----
    if BOOLvar.value = 0 then
    ___BOOLvar.value = 1
    ___do what else (before sleep time)
    else
    ___if TimeCounter.value > 0 then
    ______do what else (after sleep time)
    ___end if
    end if

  4. #4

    Default Re: Time Delay in Script execution

    Hi wrs402,

    Thank you for the example

    Another way you could do this, is by making use of the limit delay. You set the boolean variable to "1", and at the limit for 1, where you link the function to execute your VBA macro again, you define a delay for e.g. 25 seconds.

    This way the function can execute the macro, and you can reset your boolean in the VBA code, this way saving the script execute function, the script, and the counter


    Where it might not be obvious to other readers, I would like to point out that this is not a "sleep" in actual sense.

    Basically a VBA macro is executed, some action is performed in the VBA macro, and then a boolean variable is set to "1". The VBA macro at this stage completes (is no longer executed.

    By setting the boolean variable to "1", it is triggered that the same VBA macro will be executed again after the defined delay time. So the delay is handled in zenon, and VBA is IDLE.

    Thanks again for sharing I'm sure this will be helpful to others.

    Regards,
    Mark

  5. #5
    Join Date
    05.01.2012
    Posts
    29

    Beitrag AW: Time Delay in Script execution

    Hi Mark,

    the limit delay is a good idea.
    In my project I show the counter value as gauge (scale circle) as a kind of countdown that the operator knows how long he has to wait for.
    Sometimes a few seconds seems to be a long time and you could became impatient. But when you see an indicator the time much runs faster.

    brst regards

  6. #6
    Join Date
    11.04.2017
    Posts
    23

    Daumen hoch Re: Time Delay in Script execution

    Hi,
    limit value is a very good idea if I have 2 function and I want insert a delay like this:

    - function 1
    - wait
    - function 2

    Thank You 

Similar Threads

  1. delay in I-bit when the Communication fail occure
    By shahramkh59 in forum zenon Network
    Replies: 2
    Last Post: 6th April 2010, 22:48
  2. Replies: 3
    Last Post: 17th October 2008, 12:43
  3. Edit Variable limit (Delay)
    By rloureiro in forum VBA
    Replies: 5
    Last Post: 12th September 2008, 09:25
  4. compare time variable with system time
    By flajoso in forum VBA
    Replies: 7
    Last Post: 25th August 2008, 06:47

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •