I want to load values of specific tags back into the panel after exporting a list (tagName,value) and modifying the values.
However i am having troubles with the SetValue function, could you guys point out what i am doing wrong?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.IO;
using Neo.ApplicationFramework.Generated;
using System.Reflection;
using Neo.ApplicationFramework.Tools.OpcClient;
public partial class ImportMenu
{
void LoadSettings(string path)
{
try {
string line;
string tagName;
int tagVal;
using (StreamReader Load = new StreamReader(path))
{
while(( line = Load.ReadLine())!= null)
{
for (int i = 0; i < line.Length; i++)
{
if( line == ',')
{
tagName = line.Substring(0,i);
tagVal = Convert.ToInt16(line.Substring(i+1));
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
PropertyInfo tagProperty =
typeof(Neo.ApplicationFramework.Generated.Tags).GetProperty(tagName);
tagProperty.SetValue(this,tagVal,null);
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
}
}
}
}
MessageBox.Show("Load complete!");
}
catch{
MessageBox.Show("Error while loading");
}
}
Modifying tagValues using SetValue
Re: Modifying tagValues using SetValue
Try get the tag object instead.
Use this function to get the tag
And then modify the value
Use this function to get the tag
Code: Select all
private GlobalDataItem GetGlobalDataItem(string propertyName)
{
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(propertyName);
if(tagProperty == null)
return null;
else
return tagProperty.GetValue(Globals.Tags, null) as GlobalDataItem;
}
Code: Select all
void Button1_Click(System.Object sender, System.EventArgs e)
{
var myTag = GetGlobalDataItem("Tag1");
myTag.Value = 123;
}
-
- Posts: 4
- Joined: Tue Jun 18, 2013 12:33 am
Re: Modifying tagValues using SetValue
Ok, im able to get the tag object and modify the value without any errors, but if i export the list of tags and their values(which I set to zero) they appear unchanged...