Page 1 of 1
LightweightTag indexing
Posted: Tue Feb 04, 2020 3:14 pm
by Aurimas94
Hello iX developers!
Spent almost 3 weeks on this so nearly gave up.. Problem is that I want to read and write array tags like:
tag1[0] = 10;
I have Tags numbered like:
- Tags.PNG (13 KiB) Viewed 14881 times
So I need to have lets say 10 tags with array size of 3 (type of INT). Then I need to loop through each of Tag and Tag index like for example:
To explain more, I was able to get FieldInfo of all Tag names which contains a string "Tag" at the beginning. Then By using LightweightTag and method defined in Tags script window "StringToTag<>"
Code: Select all
LightweightTag tag2 = Tags.StringToTag<LightweightTag>(tagField[i].Name.ToString());
where:
tagField.Name.ToString()
sets the available Tag name.
So if I try to set the value like:
it gives me an error:
- error.PNG (6.49 KiB) Viewed 14881 times
I attached my project.
Any Help will be appreciated!
Aurimas
Re: LightweightTag indexing
Posted: Wed Feb 05, 2020 4:42 pm
by Russ C.
You can access array tags index, by using this format:
Code: Select all
Globals.Tags.Tag1.Values[0].Value = 1;
Re: LightweightTag indexing
Posted: Thu Feb 06, 2020 11:31 am
by Aurimas94
Thanks for the reply.
I have tried this format earlier, but it gives compilation error like below:
- error1.PNG (92.89 KiB) Viewed 14857 times
So it seems that "LightweightTags" cannot be used like that. However when using GlobalDataItem like:
Code: Select all
FieldInfo[] tagField = typeof(Neo.ApplicationFramework.Generated.Tags).GetFields(BindingFlags.Public|BindingFlags.Instance);
for(int i = 0; i < tagField.Length; i++)
{
if(tagField[i].Name.Contains("Tag"))
{
GlobalDataItem tag = Tags.StringToTag<GlobalDataItem>(tagField[i].Name.ToString());
tag.Values[0].Value = 10;
if (tag == null)
{
/*
LightweightTag tag2 = Tags.StringToTag<LightweightTag>(tagField[i].Name.ToString());
tag2.Values[0].Value=10;
//Globals.Tags.Tag1.Values[0].Value = 10;
if (tag2 == null)
{
MessageBox.Show("Error");
}
else
{
MessageBox.Show(tag2.Value.ToString());
}
*/
}
else
{
MessageBox.Show(tag.Value.ToString());
}
}
else
return;
}
It compiles and even shows one of the Tag values yet there is 3 of them...
I don't really understand difference of LightweightTag and "normal" tag... How can I make all of them the same, lets say not the LightweightTag?
Thanks.
Re: LightweightTag indexing
Posted: Fri Feb 07, 2020 8:34 am
by Russ C.
The "LightWeight" tag means that tag isn't doesn't have any additional properties for being used in special cases such as: Non-Volatile, has a Gain or Offset, Data Exchange, Array, etc...
So your issue is your forcing it to always be a LightWeightTag which doesn't have a "Values" property because LightWeightTags can't be an ArrayTag.
Code: Select all
LightweightTag tag2 = Tags.StringToTag<LightweightTag>(tagField[i].Name.ToString());
Why are you using GlobalDataItem on the lines above and LightWeightTag on this one?
Have you already tried using it like:
Code: Select all
GlobalDataItem tag2 = Tags.StringToTag<GlobalDataItem>(tagField[i].Name.ToString());
Re: LightweightTag indexing
Posted: Fri Feb 07, 2020 10:02 am
by Aurimas94
Last time I tried I couldn't get array values while using:
Code: Select all
GlobalDataItem tag2 = Tags.StringToTag<GlobalDataItem>(tagField[i].Name.ToString());
Today I noticed really stupid mistake...
Instead of passing in MessageBox the same array index as I am writing to I was passing nothing, so resulting value always equals to 0...
All in all, that was my mistake and I was sooo close
I really appreciate your help, Russ C. You are the man!
I attached project files if someone come across the same issue.
And here is the results:
- Capture.PNG (5.99 KiB) Viewed 14849 times
cheers!
Re: LightweightTag indexing
Posted: Fri Feb 21, 2020 5:27 pm
by Russ C.
Awesome!! Glad you were able to get it up and running!!