Auto Control Module : Multichannel Trigger between specific time

Forum Home Forums Understanding the Software Auto Control Module : Multichannel Trigger between specific time

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #16753
    rapidscadaaks
    Participant

    Hi

    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?

    #16760
    Mikhail
    Moderator

    Hi,
    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.

    #16761
    Mikhail
    Moderator

    Alternatively, you can create a channel that can be 0 or 1 depending on the time, and use it in a multichannel trigger.

    #16763
    rapidscadaaks
    Participant

    This scenario is better. Please advise how to create a channel that can be 0 or 1 depending on time.

    Thanks in advance

    #16766
    rapidscadaaks
    Participant

    Hi

    I tried creating a calculated channel with following formula and Rapid Scada stopped working:

    if(hour() >= 8 && hour() < 20, 1, 0)

    Please advise

    Thanks

    #16767
    manjey73
    Participant

    if(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 ???

    #16768
    manjey73
    Participant

    It 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.
    #16770
    rapidscadaaks
    Participant

    Hi
    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

    #16771
    manjey73
    Participant
    public 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.

    #16772
    manjey73
    Participant

    Add it to the script table.
    In the Calculated channel, write the input formula CheckHour(8, 20)

    #16776
    Mikhail
    Moderator

    I 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.

    #16777
    rapidscadaaks
    Participant

    The solution works.
    Many thanks for the guidance.

    #16778
    rapidscadaaks
    Participant

    Hi

    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

    #16779
    manjey73
    Participant

    There 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

    #16781
    rapidscadaaks
    Participant

    Hi
    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

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