Forum Replies Created
-
AuthorPosts
-
manjey73
ParticipantYou’ve voiced the problem, but you haven’t provided a single script that you think could lead to this.
manjey73
Participantso 10 times per second is about a 100ms cycle 🙂
manjey73
ParticipantPlease show me your script.
When calling the script directly, it should run faster than when called through EverySec.manjey73
ParticipantI don’t understand how your script works fast when using the limit of once per second (everysecond) and at the same time runs for 10 seconds with a direct call?
Show your script that behaves this way.
manjey73
Participant1. How does your script run for a few seconds without using EverySec?
How did you determine that?manjey73
ParticipantYou can use it inside your scripts. Someone also has to set the timer so that it starts working.
manjey73
ParticipantWhat’s wrong with processing a script in a loop, which also requires a timer of less than a second?
To be honest, I haven’t implemented timers for such a task. I usually use them for other purposes, for example, to delay triggering the device status.
What exactly is your goal? Can you draw a flowchart for understanding?An example of a TON timer from CodeSys or similar.
// IEC timers and others public static long Ticks() { DateTime now = DateTime.Now; long time = now.Ticks/10000; return time; } protected class UtilTimer { public long et; public bool flag; public bool q; } protected Dictionary<string, UtilTimer> TonTimer = new Dictionary<string, UtilTimer>(); protected Dictionary<int, UtilTimer> TofTimer = new Dictionary<int, UtilTimer>(); protected Dictionary<int, UtilTimer> TpTimer = new Dictionary<int, UtilTimer>(); // Timer with a delay of turning on TON public double TON(double IN, double PT, double Q, string str = "", int idx = 0) { var ut = new UtilTimer() {et = 0L, flag = false, q = false}; string keys = $"{CnlNum}_{idx}"; // The key is the channel number plus the timer index, zero by default. Allows you to use multiple timers inside a formula. long ET = 0L; long _pt = Convert.ToInt64(PT); bool q = Q > 0; bool _in = IN > 0; string s = str.ToLower(); if (s == "s" || s == "sec") _pt = Convert.ToInt64(PT) * 1000; if (s == "m" || s == "min") _pt = Convert.ToInt64(PT) * 60000; if (s == "h" || s == "hour") _pt = Convert.ToInt64(PT) * 3600000; if (!TonTimer.ContainsKey(keys)) { TonTimer.Add(keys, ut); } if (!_in) { TonTimer[keys].q = false; TonTimer[keys].flag = false; TonTimer[keys].et = 0L; } else { if (!TonTimer[keys].flag) { TonTimer[keys].flag = true; TonTimer[keys].et = Ticks(); } else { if (!q) ET = Ticks() - TonTimer[keys].et; } if (ET >= _pt) q = true; TonTimer[keys].q = q; } q = TonTimer[keys].q; return Convert.ToDouble(q); } // -------------------------------------------- // Timer with delayed shutdown of TOF public double TOF(double IN, double PT) { var ut = new UtilTimer() {et = 0L, flag = false}; long ET = 0L; long _pt = Convert.ToInt64(PT); bool q = Val(CnlNum) > 0; bool _in = IN > 0; if (!TofTimer.ContainsKey(CnlNum)) { TofTimer.Add(CnlNum, ut); } if (_in) { q = true; TofTimer[CnlNum].flag = true; TofTimer[CnlNum].et = 0L; ET = 0L; } else { if (TofTimer[CnlNum].flag) { TofTimer[CnlNum].flag = false; TofTimer[CnlNum].et = Ticks(); ET = 0L; } else { if (q) ET = Ticks() - TofTimer[CnlNum].et; } if (ET >= _pt) q = false; } return Convert.ToDouble(q); } // -------------------------------------------- // Pulse Timer TP public double TP(double IN, double PT) { var ut = new UtilTimer() {et = 0L, flag = false}; long ET = 0L; long _pt = Convert.ToInt64(PT); bool q = Val(CnlNum) > 0; bool _in = IN > 0; if (!TpTimer.ContainsKey(CnlNum)) { TpTimer.Add(CnlNum, ut); } if (!TpTimer[CnlNum].flag) { if (_in) { TpTimer[CnlNum].flag = true; TpTimer[CnlNum].et = Ticks(); if (ET < _pt) q = true; } } else { if (q) { ET = Ticks() - TpTimer[CnlNum].et; if (ET >= _pt) q = false; } else { if(!_in) { TpTimer[CnlNum].flag = false; ET = 0L; } } } return Convert.ToDouble(q); }
manjey73
ParticipantAll formulas in the channels are executed in a cycle from the smaller channel to the larger one. If you don’t specify every second, then it’s about 10 times per second. And the more channels there are, the longer the pause time will be.
Or don’t use the every second wrapper, or use your own timer for example.manjey73
ParticipantThe automatic control module is quite self-sufficient. It is impossible to build complex scenarios on it, even if you provide for some part. Therefore, for complex scenarios, additional calculation channels are used, for which you already configure the module and perform some actions to send commands.
If it needs to be even more complicated, I wrote a program execution module in which the code is written in C# in Visual Studio and communication with channels is performed. The module has not been finalized yet, but you can look at the example of ModFarm for an example of building programs.manjey73
Participantpublic bool TwoChannel (int chn1, int chn2) { bool chn12 = false; if (Val(chn1) == 1 && Val(chn2) == 2) chn12 = true; return chn12; }
For example, add this formula to Scripts and then use it in an additional Calculated channel.
You can write a more complex formula for comparing channels so that you can even select the comparison values and the type of comparison. And make the script more versatile for different tasks.
manjey73
ParticipantI would wait for the release of a new editor, if it is related to it. Well, or studied PlgMain.
manjey73
ParticipantYou can write your own control module if you are not satisfied with the Automatic Control Module from RapidScada.
Yes, the Automatic Control Module has limitations, especially if you need to control many different parameters. You can get around this by using scripts, creating one channel that will then control the module, but it’s not always that simple.manjey73
ParticipantStatic text is not intended for giving commands, it is just some kind of text.
For control, you must use dynamic text or dynamic drawing. But you can only send one command through them.manjey73
ParticipantThe question is not entirely clear
What do you mean by multiple controls?manjey73
ParticipantNo, scripts don’t have access to send commands to devices. This can only be done by modules. For example, an automatic control module or your own.
-
AuthorPosts