Continuing a calcuation after restart ?

Forum Home Forums Understanding the Software Using Formulas Continuing a calcuation after restart ?

Viewing 4 posts - 16 through 19 (of 19 total)
  • Author
    Posts
  • #7916
    manjey73
    Participant

    Retain Formula for writing a variable to a file retain.txt

    string pathRet = @"/opt/scada/ScadaServer/Config/retain.txt";
    Dictionary<int, double> DictRet = new Dictionary<int, double>();
    public double Retain (double ret)
    {
    DictRet[CnlNum] = ret;
    return ret;
    }

    Example of applying the formula in the input channel database. Retain(Val(150))
    The control channel can contain setval(150, Cmd)

    The lowest input channel uses the load_retain formula
    Recording in the loadret channel()

    bool initRet = false;
    double LoadRet()
    {
    if (!initRet)
    {
    
    if (System.IO.File.Exists(pathRet))
    {
    string[] RetLoad = System.IO.File.ReadAllLines(pathRet, Encoding.UTF8);
    for (int i = 0; i < RetLoad.Length; i++)
    {
    SetVal(Convert.ToInt32(RetLoad[i].Substring(RetLoad[i].IndexOf("[")+1, RetLoad[i].IndexOf(", ")-(RetLoad[i].IndexOf("[")+1)),10),Convert.ToDouble(RetLoad[i].Substring(RetLoad[i].IndexOf(", ")+2,RetLoad[i].IndexOf("]")-(RetLoad[i].IndexOf(", ")+2))));
    }
    initRet = true;
    }
    
    }
    return Convert.ToDouble(initRet);
    }

    Executed once at server startup

    The most recent channel uses the save_retain formula
    Entry in the saveret channel formula()

    double SaveRet()
    {
    string[] RetSave = new string[DictRet.Count];
    bool eq = false;
    for (int i = 0; i < DictRet.Count; i++)
    {
    RetSave[i] = Convert.ToString(System.Linq.Enumerable.ElementAt(DictRet, i));
    }
    
    if (!System.IO.File.Exists(pathRet))
    {
    System.IO.File.WriteAllLines(pathRet, RetSave, Encoding.UTF8);
    return 0;
    }
    else
    {
    string[] RetOld = System.IO.File.ReadAllLines(pathRet, Encoding.UTF8);
    eq = System.Linq.Enumerable.SequenceEqual(RetOld, RetSave);
    if (!eq)
    {
    System.IO.File.WriteAllLines(pathRet, RetSave, Encoding.UTF8);
    }
    }
    return Convert.ToDouble(eq);
    }

    The path to Raspberry specify your own in the first formula.
    An example file retain.txt

    [450, 23]
    [451, 51]
    [452, 51,5]
    [453, 46]

    The first digit is the channel number, the second is the channel value.
    The file is written when the variable specified as Retain is changed.
    You can also initialize the necessary variables when starting the server.

    For changing variables in the process of work, but which need to be saved, it is better to add probably another timer and record no more than x minutes. I think so.
    For configuration variables that rarely change, you can use as-is.

    #7917
    manjey73
    Participant

    1st input channel use the formula – LoadRet()

    Channels that require saving – Retain(Val(43))
    Retain(here there can be a formula that returns necessarily double)

    In the last channel, the formula – SaveRet()
    65535 use the formula – SaveRet()

    Any solution can lose value during a hard reboot, but if the variables do not change often, then you can use different options.

    • This reply was modified 3 years, 2 months ago by manjey73.
    #7918
    athes
    Participant

    Wow, really impressive.
    Far more advanced then my solution 🙂

    #7920
    manjey73
    Participant

    I do not know how advanced it is, it is better of course to use third-party applications for organizing RAM disk, which independently saves data to disk. Unlike tmpfs, as there are some limitations.

    For example var stuffed into tmpfs does not allow xrdp to run

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