How to use EveryPeriod Function?

Forum Home Forums Understanding the Software Using Formulas How to use EveryPeriod Function?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14098
    CCKOH
    Participant

    Hi Mikhail,
    I’m need to execute My Function () at a time interval specific by the user (thru input channel 140). Understand that Rapid SCADA have a Timer function
    EveryPeriod(Func<CnlData> getDataFunc, long period, long execSpan)

    Please advise me how to use this funtion to achieve my Task.

    In addition, I’m notice that under EverySec(Func<CnlData> getDataFunc), EveryPeriod function is calling
    EveryPeriod(getDataFunc, TimeSpan.TicksPerSecond, TimeSpan.TicksPerMillisecond * 500);
    Why TimeSpan.TicksPerMilisecond need multiply by 500? Or actually what is the «execSpan» meaning?
    I’m sorry if my question look silly as my programming skills are very very basic.
    Thank you.

    #14104
    Mikhail
    Moderator

    Hi,
    EveryPeriod is defined as protected. You can change it to public and try using it directly. The period argument would be taken from a channel value, for example.
    The execSpan parameter provides a flexible period when getDataFunc can be executed. Note that EveryPeriod is called many times a second by the Server engine, and you don’t know the particular moment when it is called.

    #14105
    Mikhail
    Moderator

    Probably, it’s better to create your own function that uses the EveryPeriod method.
    execSpan can be equal to period / 10

    #14108
    CCKOH
    Participant

    Hi Mikhail,

    Thank for the explanation.

    If I’m need to execute my function “Compute()” every 5 second define by user thru channel 140 for example, can I’m write the formula as EveryPeriod (Compute(), Val(140), Val(140)/10) at the channel of output formula column?

    I’m still confusing why we still need execSpan argument? As we already define function Compute() only can be execute when the time specific (5s in this example) elapsed. Really hope you can help elaborate more on it.

    #14124
    Mikhail
    Moderator

    Hi,
    Add a function like that:

    public CnlData Every5Sec(Func getDataFunc)
    {
        return EveryPeriod(getDataFunc, TimeSpan.TicksPerSecond * 5, TimeSpan.TicksPerMillisecond * 500 * 5);
    }
    

    > I’m still confusing why we still need execSpan argument?
    It is needed to avoid unnecessary calls of getDataFunc.

    #14132
    CCKOH
    Participant

    Hi Mikhail,

    Thank for the function example and the explanation.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.