manjey73

Forum Replies Created

Viewing 15 posts - 121 through 135 (of 904 total)
  • Author
    Posts
  • in reply to: Using Internal variables/channels #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);
    }
    
    in reply to: Using Internal variables/channels #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

    in reply to: Faster thread #16642
    manjey73
    Participant

    Start with scripts in which you read or write to files, and the like. That is, some more complex scripts that you use.

    in reply to: Faster thread #16635
    manjey73
    Participant

    You’ve voiced the problem, but you haven’t provided a single script that you think could lead to this.

    in reply to: Faster thread #16633
    manjey73
    Participant

    so 10 times per second is about a 100ms cycle 🙂

    in reply to: Faster thread #16629
    manjey73
    Participant

    Please show me your script.
    When calling the script directly, it should run faster than when called through EverySec.

    in reply to: Faster thread #16627
    manjey73
    Participant

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

    in reply to: Faster thread #16624
    manjey73
    Participant

    1. How does your script run for a few seconds without using EverySec?
    How did you determine that?

    in reply to: Faster thread #16622
    manjey73
    Participant

    You can use it inside your scripts. Someone also has to set the timer so that it starts working.

    in reply to: Faster thread #16621
    manjey73
    Participant

    What’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);
    }
    
    in reply to: Faster thread #16619
    manjey73
    Participant

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

    in reply to: Send Commond #16616
    manjey73
    Participant

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

    in reply to: Send Commond #16614
    manjey73
    Participant
    public 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.

    in reply to: Where should I start looking at the code? #16605
    manjey73
    Participant

    I would wait for the release of a new editor, if it is related to it. Well, or studied PlgMain.

    in reply to: Send Commond #16595
    manjey73
    Participant

    Logic Module Development

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

Viewing 15 posts - 121 through 135 (of 904 total)