Modifying tagValues using SetValue

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
bjornspockeli
Posts: 4
Joined: Tue Jun 18, 2013 12:33 am

Modifying tagValues using SetValue

Post 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");
}
}

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Modifying tagValues using SetValue

Post 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; 
}
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

bjornspockeli
Posts: 4
Joined: Tue Jun 18, 2013 12:33 am

Re: Modifying tagValues using SetValue

Post 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...

Post Reply