Forum Home › Forums › Understanding the Software › Using Internal variables/channels
- This topic has 15 replies, 3 voices, and was last updated 1 month, 1 week ago by
Mikhail.
-
AuthorPosts
-
July 11, 2025 at 2:53 am #16643
WayneS
ParticipantGreetings 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…
July 11, 2025 at 4:14 am #16644manjey73
Participantyou 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
July 11, 2025 at 4:29 am #16645WayneS
ParticipantThank 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.
July 11, 2025 at 6:48 am #16646manjey73
ParticipantAn 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); }
July 11, 2025 at 6:49 am #16647manjey73
ParticipantTry different options, as different channel processing scripts are required for different tasks.
July 11, 2025 at 7:08 am #16648manjey73
Participantpublic 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"))
July 11, 2025 at 7:10 am #16649manjey73
ParticipantCheckComm – The multiplier formula
CheckComm1 – The formula is without using a multiplier, in fact, the multiplier is 1 if you use the first oneJuly 11, 2025 at 7:35 am #16650manjey73
ParticipantSetVal(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.
July 11, 2025 at 9:31 am #16651WayneS
ParticipantThanks, That’s great. I will have try this 🙂
July 11, 2025 at 10:18 am #16652WayneS
ParticipantThanks @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
July 11, 2025 at 10:51 am #16655Mikhail
ModeratorHello,
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()
July 12, 2025 at 12:12 am #16658WayneS
ParticipantHello,
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
July 14, 2025 at 11:06 am #16668Mikhail
ModeratorHello,
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)); }
July 14, 2025 at 8:00 pm #16675WayneS
ParticipantThanks,
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.
July 15, 2025 at 5:52 am #16676manjey73
Participant1. ModDiffCalculator – One of the options that solves this problem.
2. Channel 1, to save the total reading every hourEveryHour(() => 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.
-
AuthorPosts
- You must be logged in to reply to this topic.