/// <summary> /// Loads all Tags from the SmartTag Table in SQL into Memory by creating a S7LINK.Tag for each SmartTag entry /// </summary> public void LoadTagsOnlineFromSQL() { try { // // Select all tags from SQL // using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) { sqlConn.Open(); SqlCommand cmd = sqlConn.CreateCommand(); cmd.CommandText = "SELECT ObjectNo, st.Tagname, TagDescription, DBOffset, ParMsgType, FB, RecOnTick, RecOnChange, RecTrend, ISNULL(Property,'-') Property, GroupNo FROM SmartTags st LEFT OUTER JOIN TagLinks tl on st.Tagname = tl.TagName WHERE st.GcProTag = 1 ORDER BY st.TagName"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MyObjectInfo moi = new MyObjectInfo(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetInt32(6), reader.GetInt32(7), reader.GetInt32(8), reader.GetString(9), reader.GetString(10)); Tag t = new Tag(); t.Name = reader.GetString(3); t.DataType = S7Link.Tag.ATOMIC.WORD; t.MyObject = moi; t.Controller = PLC1_R; t.Changed += new EventHandler(INGEARS7_Tag_Changed); //Adds event handler to each tag for "Tag Value Changed Event" tagroupSmartTags.AddTag(t); if (moi.RecOnTick == 1) { htRecTickTagValues.Add(moi.TagName, 0); } } sqlConn.Close(); } } catch (Exception ex) { MessageBox.Show("Load SmartTags --> " + ex.Message, "Error Loading Tags", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Loads all SmartTags that are marked as a User tag from SQL into memory /// </summary> /// <summary> /// Loads all SmartTags that are marked as a User tag from SQL into memory /// </summary> public void LoadAdditionalTagsOnlineFromSQL() { string thisCurrentTag = ""; try { // // Select all tags from SQL // using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) { sqlConn.Open(); SqlCommand cmd = sqlConn.CreateCommand(); cmd.CommandText = "SELECT st.Tagname, DBOffset, RecOnTick, RecOnChange, RecTrend FROM SmartTags st WHERE UserTag = 1 ORDER BY TagName"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MyObjectInfo moi = new MyObjectInfo(reader.GetString(0), reader.GetString(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4)); Tag t = new Tag(); thisCurrentTag = t.Name; // // Check special features of tag // bool IsRealDataType = false; bool IsIntDataType = false; bool IsDoubleIntDataType = false; string tmpSpecialTagName = ""; if (moi.DBOffset.ToString().Contains("{R}")) //This tag contains special features { IsRealDataType = true; tmpSpecialTagName = "" + moi.DBOffset.ToString().Remove(moi.DBOffset.ToString().IndexOf('{'), 3); } if (moi.DBOffset.ToString().Contains("{I}")) //This tag contains special features { IsIntDataType = true; tmpSpecialTagName = "" + moi.DBOffset.ToString().Remove(moi.DBOffset.ToString().IndexOf('{'), 3); } if (moi.DBOffset.ToString().Contains("{D}")) //This tag contains special features { IsDoubleIntDataType = true; tmpSpecialTagName = "" + moi.DBOffset.ToString().Remove(moi.DBOffset.ToString().IndexOf('{'), 3); } if (IsRealDataType || IsIntDataType || IsDoubleIntDataType) { t.Name = tmpSpecialTagName; } else { t.Name = moi.DBOffset.ToString(); } // // Check datatype of tag // int iPosOfPoint = t.Name.IndexOf('.'); string sRightOfPoint = t.Name.Substring((iPosOfPoint + 1), 3); if (sRightOfPoint.ToUpper() == "DBX") { t.DataType = S7Link.Tag.ATOMIC.BOOL; } else if (sRightOfPoint.ToUpper() == "DBB") { t.DataType = S7Link.Tag.ATOMIC.BYTE; } else if (sRightOfPoint.ToUpper() == "DBW") { if (IsIntDataType) { t.DataType = S7Link.Tag.ATOMIC.INT; } else { t.DataType = S7Link.Tag.ATOMIC.WORD; } } else if (sRightOfPoint.ToUpper() == "DBD") { // // DBD is used to read Double Word as well as Real // if (IsRealDataType) { t.DataType = S7Link.Tag.ATOMIC.REAL; } else if (IsDoubleIntDataType) { t.DataType = S7Link.Tag.ATOMIC.DINT; } else { t.DataType = S7Link.Tag.ATOMIC.DWORD; } } else { MessageBox.Show("Datatype : " + sRightOfPoint + " is not supported!", "Invalid Datatype!", MessageBoxButton.OK, MessageBoxImage.Error); } t.MyObject = moi; t.Controller = PLC1_R; t.Changed += new EventHandler(INGEARS7_AdditionalTag_Changed); tagroupAdditionalSmartTags.AddTag(t); //htAdditionalTagCurrentValues.Add(moi.TagName, 0); //Default value of 0; if (moi.RecOnTick == 1) { htRecTickTagValues.Add(moi.TagName, 0); } } sqlConn.Close(); } } catch (Exception ex) { MessageBox.Show("Load AdditionalTags --> " + ex.Message, "Error Loading Tags", MessageBoxButton.OK, MessageBoxImage.Error); } }