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); } } 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(); }
时间: 2024-10-09 17:04:31