Calculated Channel computing current minimum value of multiple channels

Forum Home Forums Understanding the Software Using Formulas Calculated Channel computing current minimum value of multiple channels

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #16970
    rapidscadaaks
    Participant

    Hi

    Please assist for making a formula to calculate minimum value of current date of several channels.

    I excel, one would have used min(aa:xx)

    Thanks in advance

    #16971
    rapidscadaaks
    Participant

    Hi

    Please assist for making a formula to calculate minimum value of current date of several channels.

    I excel, one would have used min(aa:xx)

    Thanks in advance

    #16976
    rapidscadaaks
    Participant

    Hi

    I used formula below in a calculated channel and it did not work:

    Min(Val(1601),Val(1602),Val(1603))

    Server returned following error:

    2025-09-08 09:16:30 [SCADA][SCADA$][ERR] Error compiling the source code of the scripts and formulas:
    (929,53): error CS1501: No overload for method ‘Min’ takes 3 arguments
    Check the source code in Z:\SCADA\ScadaServer\Log\CalcEngine.cs
    2025-09-08 09:16:30 [SCADA][SCADA$][ERR] Normal execution is impossible

    Please help

    Thanks in advance

    #16977
    rapidscadaaks
    Participant

    Found a solution by using following script

    public double GetMinValue(params int[] channelNumbers)
    {
    if (channelNumbers == null || channelNumbers.Length == 0)
    return double.NaN;

    double minVal = double.MaxValue;

    foreach (int cnlNum in channelNumbers)
    {
    minVal = Math.Min(minVal, Val(cnlNum));
    }

    return minVal;
    }

    #16985
    Mikhail
    Moderator

    Hi,
    Creating formulas is a development service and is outside the scope of support. If you have a specific question about the syntax or features of formulas, please ask.

    #16986
    Mikhail
    Moderator

    Note that is is not efficient to pass an array as a function argument. Because a new array is created each iteration.
    It’s better to make a function like

    public double GetMinValue(int cnl1, int cnl2, int cnl3)
    {
    ...
    }
    #16989
    rapidscadaaks
    Participant

    Noted Mikhail.

    Thanks

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