Hourly countdown formula

Forum Home Forums Understanding the Software Using Formulas Hourly countdown formula

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #15326
    PVO
    Participant

    Perhaps a silly question, but I’m a newbie in using formulas…

    I would like to start a countdown from 48h tot 0 (hourly) when an input exceeds a predefined value. When the input drops below this value the countdown needs to be reset. Purpose is to show the countdown on an interface template.

    How can I create the countdown using a formula?

    #15336
    Mikhail
    Moderator

    Hi,

    The idea can be:
    1. If the input changes from low to high value, write a timestamp in a channel of the Calculated type.
    2. Add a channel to calculate the difference between now and stored value.
    3. If the input changes from high to low value, set the timestamp channel to undefined.

    I can answer certain questions about script syntax and available formulas. Creating complex scripts is programming, so it’s a paid service.

    #15574
    PVO
    Participant

    Thank you for this answer, it helps me a lot.

    I have been trying some things, but I wonder…

    I am still working with Version 5.5.2.2 of Rapid Scada: could it be that some time functions are not available in this version? (Timestamp, Now(),….)

    #15577
    Mikhail
    Moderator

    The Timestamp variable is not available in v5. Use DateTime.UtcNow instead.

    • This reply was modified 9 months, 4 weeks ago by Mikhail.
    #15595
    PVO
    Participant

    Thank you.

    Why do I still get errors CS1502 and CS1503 in the definition of the input parameter where I would like to write the timestamp?

    #15599
    PVO
    Participant

    Problem solved 🙂

    #15600
    PVO
    Participant

    Sorry, one more question:

    How can I set the timestamp channel to undefined in version 5?

    #15607
    Mikhail
    Moderator

    Set status to 0 by the 2nd part of the formula. Docs

    #15608
    PVO
    Participant

    I’m almost there… However, I still have a little problem…

    As you suggested, when input changes from low to hi I write a timestamp in a calculated channel.

    This works for 1 minute. For some reason, he writes a new timestamp after exactly one minute even if the input did not change.

    What can be the reason that he writes a new timestamp after one minute and what can I do to fix this?

    #15609
    PVO
    Participant

    Some additional information about the question above:

    I use the following script in the input channel 167 that determines is the timer is active or not:

    double Timer48hactief()
    {
    if (Cnl==1)
    {
    SetVal(193,EncodeDate(DateTime.Now));
    }
    else
    {
    SetVal(193,0);
    }
    return Cnl;
    }

    Correct me if I’m wrong, but I suppose that the server should only execute the script when the input of the channel changes (from low to hi or from hi to low).

    So I don’t understand why the server writes a timestamp in input 193 every minute, even when the input on channel 167 does not change…

    #15611
    Mikhail
    Moderator

    Formulas of the calculated channels are called many times a second.
    Formulas of the input channels are called when data comes from Communicator. By default, Communicator sends all device data every minute. May be this is the cause.

    For what channel number do you use the function Timer48hactief?

    #15612
    PVO
    Participant

    ok, that is probably the cause, but how can I fix that in a way that the timestamp is only written when the input changes from lo to hi?

    The function Timer48hactief is used as formulaname in channel 167 (= the actual input channel)

    #15613
    PVO
    Participant

    I tried to make my script smarter by using PrevVal() but I’m afraid that PrevVal is not supported in version 5…

    #15614
    PVO
    Participant

    Hi Mikhail,

    Problem solved, by using an extra input channel, independent of data coming from communicator where I write status of the timer (running or not). This in combination with some extra boolean logic in the script makes it working perfectly.

    Thank you for your help! This is my first experience in script writing and I learned a lot.

    #15615
    Mikhail
    Moderator

    Hi,
    Thank you for the update.

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