[開源]FreeSCADA的數據庫存儲方式(Archiver)探究[MySQL為例]


1.我們先新建一個FreeSCADA的工程實例,看下實際的存儲效果:

a) 建立幾個數據通道作為數據源(Communication菜單編輯,Channels Tree下顯示):

b) 建立一個數據庫存檔(工具欄的Archiver Settings):

c) 定義數據庫連接屬性(Project菜單下的Database settings子菜單):

d) 編譯項目,並運行,查看數據庫存儲結果:

2.存儲過程探究(FreeSCADA2解決方案下的Archiver工程):

我們主要分析Archiver工程下Archiver.cs文件內的的幾個方法:

Start方法:

public bool Start()
{
    dbWriter = new DbWriter();
    if (dbWriter.Open() == false)
    return false;

    channelUpdaterThread = new Thread(new ParameterizedThreadStart(ChannelUpdaterThreadProc));
    channelUpdaterThread.Start(this);

    dbReader = new DbReader();
    if (dbReader.Open() == false)
    return false;

    return IsRunning;
}

ChannelUpdaterThreadProc方法:

private static void ChannelUpdaterThreadProc(object obj)
{
    ArchiverMain self = (ArchiverMain)obj;

    try
    {
        for (; ; )
        {
            //System.Console.WriteLine("{0} ChannelUpdaterThreadProc: Start loop", System.DateTime.Now);
            foreach (Rule rule in self.channelSettings.Rules)
            {
                if (rule.Enable)
                {
                    foreach (BaseCondition cond in rule.Conditions)
                      cond.Process();

                    if (rule.Archive) // 判斷是否需要將本規則下對應的各個數據通道數據存入數據庫(通過判斷是否使能了本項存儲規則、並且存儲規則對應的存儲條件的參數:間隔時間是否已經到了)
                      self.dbWriter.WriteChannels(rule.Channels);
                }
            }
            Thread.Sleep(100); // 線程休眠100ms。所以FreeSCADA的查詢各個數據通道的間隔就是100ms。
        }
    }
    catch (ThreadAbortException)
    {
    }

    if (self.dbWriter != null)
    self.dbWriter.Close();
}

Stop方法:

public void Stop()
{
    if (channelUpdaterThread != null)
    {
        channelUpdaterThread.Abort();
        channelUpdaterThread.Join();
        channelUpdaterThread = null;

        if (dbWriter != null)
            dbWriter.Close();
    }
    if (dbReader != null)
        dbReader.Close();
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM