Page 1 of 1

Modifying tagValues using SetValue

Posted: Mon Jul 08, 2013 7:43 am
by bjornspockeli
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");
}
}

Re: Modifying tagValues using SetValue

Posted: Mon Jul 08, 2013 7:58 am
by Edmund
Try get the tag object instead.


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;
}

And then modify the value

Code: Select all

void Button1_Click(System.Object sender, System.EventArgs e)
{
	var myTag = GetGlobalDataItem("Tag1");
	myTag.Value = 123; 
}

Re: Modifying tagValues using SetValue

Posted: Tue Jul 09, 2013 12:26 am
by bjornspockeli
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...