Page 1 of 1
Arrays 2
Posted: Thu Aug 23, 2012 10:49 am
by daoa80
Help!!!
this is an example of a tag list that I have created seen in the Design view:
Tag Controllers
Name DataType AccessRight DataType EMCP1
SPNFMI_0 UNIT32 Read UNIT32 41511
....
....
SPNFMI_39 UNIT32 Read UNIT32 41890
1. I have to go through every tag (EMCP1 value) to get some info
2. Insted of manually changing the tag name, can it be done using an array,
e.g
for(int x=0; x < 40; x++)
{
value [x] = (Globals.Tags.SPNFMI_[x].Value>>5) & (0x7FFFF);
}
So when x=0, it will get the info from SPNFMI_0
when x=1, it will get the info from SPNFMI_1 and so on.
Any hints? is it possible?
Re: Arrays 2
Posted: Mon Aug 27, 2012 1:18 am
by LordMonty
I got this tip for concatinating strings to read tag values from the support guys in Sweden.
Just include the method GetGlobalDataItem in your code and these using statements.
using Neo.ApplicationFramework.Tools.OpcClient;
using System.Reflection
int number = 1;
decimal val = GetGlobalDataItem("Tag" + number.ToString()).Value.Decimal;
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;
}
Re: Arrays 2
Posted: Mon Aug 27, 2012 4:20 pm
by daoa80
Does it work for you?
I've been trying with no success; found another link with different approach:
http://ixtalk.beijerelectronics.com/vie ... tring#p126
Re: Arrays 2
Posted: Thu Sep 20, 2012 1:20 pm
by mark.monroe
See below for a working example on Screen1 with a button.
Code: Select all
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 Neo.ApplicationFramework.Tools.OpcClient;
using System.Reflection;
public partial class Screen1
{
void Button1_Click(System.Object sender, System.EventArgs e)
{
//Number at end of tag.
//Tag name should look like Tag1, Tag2, TagX
int number = 2;
decimal val = GetGlobalDataItem("Tag" + number.ToString()).Value.Decimal;
this.Text1.Text = val.ToString();
}
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;
}
}
}