Wonderware Historian Servers 操作

1、概述   

  工控软件Wonderware System Platform带有Historian实时归档数据库,采用SQL Server+本地文件形式管理和存储归档数据。数据的元数据(包括标签名、说明、采样频率等)存储在SQL Server的Runtime库中,归档的结果数据存储在本地。

2、Historian架构

   Historian架构图如下:

3、Microsoft SQL Server Management Studio

      数据库的分析等,可以使用Microsoft SQL Server Management Studio直接操作,主要是数据在视图中。可以使用标准SQL语法,但需要注意相关约束。

Wonderware Historian Servers 操作_第1张图片

4、插入和查询语法示例

INSERT INSQL.Runtime.dbo.AnalogHistory (DateTime, TagName, Value,
QualityDetail)
VALUES ('1999-11-11 16:05:10', 'NonIOTag1', 56, 192)

INSERT INTO INSQL.Runtime.dbo.StringHistory (DateTime, TagName, Value,
wwTimeZone, wwVersion)
VALUES ('1999-11-11 16:05:10', 'IOstring1', 'Batch 10', 'Eastern Standard
Time', 'latest')

INSERT v_History (TagName, QualityDetail, Value, DateTime)Importing, Inserting, or Updating History Data Wonderware Historian Administration Guide
Version 17.3.100 163
VALUES ('NonIOtag1', 192, 56, '1999-11-11 16:05:10')

INSERT INTO v_History (TagName, DateTime, Value, QualityDetail)
SELECT 'ManualReactTemp', DateTime, 32 + Value * 9 / 5, 192 FROM
v_AnalogHistory
WHERE TagName = 'ReactTemp'
AND DateTime >= dateadd(mi, -50, getdate())
AND DateTime < dateadd(mi, -10, getdate())
AND wwRetrievalMode = 'Delta'

DECLARE @Value float
DECLARE @DateTime DateTime
SET @Value = 1.2345
SET @DateTime = DateAdd(Minute, -10, GetDate())
INSERT v_History (DateTime, TagName, Value, QualityDetail)
VALUES (@DateTime, 'NonIOTag1', @Value, 192)

5、编程开发

     在本机连接和操作数据,C#参考代码段如下:
 
       private string SqlServerConnString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=runtime;server=(local)";

        using (SqlConnection conn = new SqlConnection())
        {
            String sql = "SELECT TagName,Description,AcquisitionType,ItemName,TagType FROM _Tag";
            conn.ConnectionString = SqlServerConnString;
            conn.Open();
            SqlCommand cmd_query = new SqlCommand(sql, conn);
            cmd_query.ExecuteNonQuery();
            using (SqlDataReader reader = cmd_query.ExecuteReader())
            {
                while (reader.Read())
                {
                    String TagName = reader["TagName"].ToString();
                    String Description = reader["Description"].ToString();
                    String AcquisitionType = reader["AcquisitionType"].ToString();
                    String ItemName = reader["ItemName"].ToString();
                    String TagType = reader["TagType"].ToString();

                    System.Console.WriteLine($"{TagName},{Description},{AcquisitionType},{ItemName},{TagType}");
                }
            }
        }

其他语言代码可以参考上面的进行修改。

Historian默认是仅允许本机访问,如果需要提供远程访问,需要修改SQL Server的相关配置

你可能感兴趣的:(IoT,编程,时序数据库,c#,sqlserver,.net)