Forum Home › Forums › Understanding the Software › Auto Control Module : Multichannel Trigger between specific time
- This topic has 28 replies, 3 voices, and was last updated 2 weeks, 4 days ago by
rapidscadaaks.
-
AuthorPosts
-
July 31, 2025 at 4:26 am #16753
rapidscadaaks
ParticipantHi
My application requires a multichannel trigger to be operational say between 7AM and 10PM everyday.
Is it possible to create a channel showing current time which can be used in the multichannel trigger?July 31, 2025 at 10:54 am #16760Mikhail
ModeratorHi,
The idea of implementing that is to cancel commands if they are sent outside of the allowed period.
A trigger should send commands to the channel. In the channel use the output formula that check time period. To reject a command, return null or double.NaN from the formula.July 31, 2025 at 10:55 am #16761Mikhail
ModeratorAlternatively, you can create a channel that can be 0 or 1 depending on the time, and use it in a multichannel trigger.
July 31, 2025 at 11:00 am #16763rapidscadaaks
ParticipantThis scenario is better. Please advise how to create a channel that can be 0 or 1 depending on time.
Thanks in advance
August 1, 2025 at 5:34 am #16766rapidscadaaks
ParticipantHi
I tried creating a calculated channel with following formula and Rapid Scada stopped working:
if(hour() >= 8 && hour() < 20, 1, 0)
Please advise
Thanks
August 1, 2025 at 6:51 am #16767manjey73
Participantif(hour() >= 8 && hour() < 20)
– That’s right, but what comes next is completely incomprehensible to the language., 1, 0)
What did you want to get with your record? an analog
? 1:0
???August 1, 2025 at 6:54 am #16768manjey73
ParticipantIt seems to me that you need to do all this inside some kind of script with the return of the value through return.
public bool MyFunc() { bool res = false; if(hour() >= 8 && hour() < 20) res = true; return res; }
And what exactly is hour() here?
-
This reply was modified 3 weeks, 4 days ago by
manjey73.
August 1, 2025 at 7:21 am #16770rapidscadaaks
ParticipantHi
I picked up if(hour()… from google search.From the record I would like an output of 0 or 1 to be able to access from multipoint trigger in automatic control module.
Basically i would like to create a channel that can be 0 or 1 depending on the time, and use it in a multichannel trigger.
Please guide
Thank you in advance
August 1, 2025 at 9:26 am #16771manjey73
Participantpublic double CheckHour(int hourLow, int hourHigh) { bool res = false; if(DateTime.Now.Hour >= hourLow && DateTime.Now.Hour < hourHigh) res = true; return Convert.ToDouble(res); }
I specifically convert to double and apply public double so that I can apply the script inside another script.
Instead of DateTime.Now you can apply DateTime.UtcNow on the situation. You can also remove the hourLow and High ads and specify the required hours instead. But it looks more versatile this way.
I haven’t checked it in action.August 1, 2025 at 9:30 am #16772manjey73
ParticipantAdd it to the script table.
In the Calculated channel, write the input formulaCheckHour(8, 20)
August 1, 2025 at 11:58 am #16776Mikhail
ModeratorI suggest using DateTime.UtcNow.Hour instead of DateTime.Now.Hour because converting universal time to local is slow. Of cause, modern computers don’t notice it.
August 1, 2025 at 11:34 pm #16777rapidscadaaks
ParticipantThe solution works.
Many thanks for the guidance.August 1, 2025 at 11:44 pm #16778rapidscadaaks
ParticipantHi
Just one more guidance.
If a channel is required which should return 0 or 1 at specific time say 6, 8, 10, 12, 14, 16, 18 and 20 hours, what would the script be ?
Appreciate your help and assistance
August 2, 2025 at 9:18 am #16779manjey73
ParticipantThere are scripts that perform functions every hour. For example, returning a value to the channel
EveryHour(() => Val(101))
Here, the channel in which you wrote this script returns the value from channel 101.Instead of Val(101) maybe your function will check the hour value of 6,8, 10, and so on and return the desired value if it matches.
You can also use a time trigger in Auto Control Module
August 4, 2025 at 10:05 am #16781rapidscadaaks
ParticipantHi
I actually need a script that toggles between 0 and 1 at specific times during the day.
I did some search and came across the following script:double ToggleAtSpecificTimes(DateTime currentTime)
{
DateTime[] toggleTimes = new DateTime[]
{
new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 8, 0, 0), // 08:00 AM
new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 12, 0, 0), // 12:00 PM
new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 18, 0, 0), // 06:00 PM
new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 22, 0, 0) // 10:00 PM
};
{
if (currentTime.Hour == toggleTime.Hour && currentTime.Minute == toggleTime.Minute)
{
return 1; // Return 1 at the specified times
}
}
return 0; // Default to 0 at all other times
}I copied the above in the Scripts table and Rapidscada worked without any issues.
However when I added a Channel and in formula used ToggleAtSpecificTimes(DateTime.Now), Rapidscada stopped working.Please guide
Thank you in advance
-
This reply was modified 3 weeks, 1 day ago by
rapidscadaaks.
-
This reply was modified 3 weeks, 4 days ago by
-
AuthorPosts
- You must be logged in to reply to this topic.