Forum Home › Forums › Understanding the Software › Using Formulas › Hourly countdown formula
- This topic has 14 replies, 2 voices, and was last updated 9 months, 2 weeks ago by
Mikhail.
-
AuthorPosts
-
September 7, 2024 at 12:56 pm #15326
PVO
ParticipantPerhaps 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?
September 9, 2024 at 10:03 am #15336Mikhail
ModeratorHi,
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.
November 4, 2024 at 3:32 pm #15574PVO
ParticipantThank 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(),….)
November 5, 2024 at 11:46 am #15577Mikhail
ModeratorThe
Timestamp
variable is not available in v5. UseDateTime.UtcNow
instead.-
This reply was modified 9 months, 4 weeks ago by
Mikhail.
November 9, 2024 at 3:11 pm #15595PVO
ParticipantThank 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?
November 10, 2024 at 8:25 am #15599PVO
ParticipantProblem solved 🙂
November 10, 2024 at 10:16 am #15600PVO
ParticipantSorry, one more question:
How can I set the timestamp channel to undefined in version 5?
November 11, 2024 at 12:41 pm #15607November 12, 2024 at 2:35 pm #15608PVO
ParticipantI’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?
November 12, 2024 at 5:05 pm #15609PVO
ParticipantSome 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…
November 13, 2024 at 11:51 am #15611Mikhail
ModeratorFormulas 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?
November 13, 2024 at 12:12 pm #15612PVO
Participantok, 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)
November 13, 2024 at 12:24 pm #15613PVO
ParticipantI tried to make my script smarter by using PrevVal() but I’m afraid that PrevVal is not supported in version 5…
November 13, 2024 at 2:15 pm #15614PVO
ParticipantHi 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.
November 14, 2024 at 9:01 am #15615Mikhail
ModeratorHi,
Thank you for the update. -
This reply was modified 9 months, 4 weeks ago by
-
AuthorPosts
- You must be logged in to reply to this topic.