Using Internal variables/channels

Forum Home Forums Understanding the Software Using Internal variables/channels

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #16643
    WayneS
    Participant

    Greetings from NZ where its Friday Afternoon now,

    I’m really enjoying rapid scada and now I would like to start building screens ahead of the actual IO being available. I have tried to make channels which aren’t linked to any device/communication lines, but haven’t had much success. What I would like is to create channel(s) which I can set to any value – many will be digital so only 1 or 0, but others will be integer or doubles – How do setup channels like this?

    I will use these channels to drive dynamic graphics and test that these and notifications etc function correctly.

    Many thanks for reading…

    #16644
    manjey73
    Participant

    you need to use formulas in channels. the simplest is Val() for input and SetVal(CnlNum, Cmd) for output formulas.

    well, there is also the possibility of using more complex formulas. The channel must be Calculated/Output

    #16645
    WayneS
    Participant

    Thank you for your reply. I have tried that wihout success. If I want to have a channel that I can set from any value from 0-100, what exactly do I put in the input/output formulas so that I can set the value from the web site. For example if I use channel 500. I can set this to a fixed value (e.g. 34) by having channel 501 output formula saying SetVal(500,34). I would like to be able to set it a range of values without having to create a channel for each value.

    Of interest I note that for the channel SetVal(500,34) to work, I first need to set channel to a value by using a input formula in channel 500 with a value in it. Otherwise the SetVal(500,34) does not work, i.e. does nothing.

    Thanks once again.

    #16646
    manjey73
    Participant

    Input and Outputs Scrips

    An example of using formulas in Calculated channels

    The Val() formula allows you to show the value after you enter it, but it will reset on reboots.
    There is a formula that allows you to use the default value for reboots, suggested by Mikhail.

    // Set the default setpoint value. 
    // For channels of the Calculated/output type
    public CnlData GetDefaultData(double val)
    {
      return Stat() > 0 ? Data() : NewData(val, 1);
    }
    
    #16647
    manjey73
    Participant

    Try different options, as different channel processing scripts are required for different tasks.

    #16648
    manjey73
    Participant
    public double CheckComm(double min, double max, double mult, string str = "" )
    {
    if (Cmd < min || Cmd > max) throw new Exception($"The value must be within {min} - {max} {str}");
    return Cmd*mult;
    }
    
    public double CheckComm1(double min, double max, string str = "" )
    {
    if (Cmd < min || Cmd > max) throw new Exception($"The value must be within {min} - {max} {str}");
    return Cmd;
    }
    

    You can also use formulas with verification to control the input parameters.
    I’ve been making universal ones for myself here.

    The method of application in the output formula of the channel

    Output channel
    CheckComm(16, 32, 10, "degrees")

    Calculated/Output
    SetVal(CnlNum, CheckComm(16, 32, 10, "degrees"))

    #16649
    manjey73
    Participant

    CheckComm – The multiplier formula
    CheckComm1 – The formula is without using a multiplier, in fact, the multiplier is 1 if you use the first one

    #16650
    manjey73
    Participant

    SetVal(500.34) does not work, presumably because the Val() formula cannot display the channel value without a status. I also came across this. There is also the Data() formula, but I haven’t tried it yet, somehow it wasn’t necessary. It works a little differently, if I understood correctly.
    You can change the values from the range directly in the channel formula, try using the combined CheckComm formulas inside the SetVal formula as shown above.

    If you plan to use formulas inside other formulas, make it a rule to convert to double yourself, even if returning bool is enough for you. Then it becomes possible.

    #16651
    WayneS
    Participant

    Thanks, That’s great. I will have try this 🙂

    #16652
    WayneS
    Participant

    Thanks @manjey73,

    Thanks to your help, I managed to make it work. A channel of calculated/output type with an output formula of SetData(417,Cmd,1) where 417 is the channel number works well.

    cheers

    #16655
    Mikhail
    Moderator

    Hello,

    I have tried to make channels which aren’t linked to any device/communication lines

    I suggest to add a device in the Devices table that has no a real device under it. It is useful for grouping channels.

    SetData(417,Cmd,1)

    If that output formula is used in the channel 417 itself, it can be simplified to SetData()

    #16658
    WayneS
    Participant

    Hello,

    That is all working well. Is it possible to make a script or formula to change two channels at the same time. Something like SetData(501,Val(500),1) and SetData(502,Val(501)-Val(500), where the order of the calculation is important.

    regards

    Wayne

    #16668
    Mikhail
    Moderator

    Hello,
    To do that, add a new function in the Scripts table, and then use it in a channel.

    public void MyFunc()
    {
      SetData(501, Val(500), 1);
      SetData(502, Val(501)-Val(500));
    }
    #16675
    WayneS
    Participant

    Thanks,

    Thats useful for calculating production/energy use etc in last hour where you have a running total, e.g. kWh. By string the value every hour then just before storing the new value subtracting the previous value from current total you get kWh in last hour.

    regards

    Wayne.

    #16676
    manjey73
    Participant

    1. ModDiffCalculator – One of the options that solves this problem.
    2. Channel 1, to save the total reading every hour EveryHour(() => Data(327))
    (Channel 327 – Total Energy from device)
    Channel 2 – EveryHour(() => Val(360) - PrevVal(360)) (Difference. Channel 360 here is Channel 1)

    There may be different approaches.

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