Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how can i make lightweighttag to get read() function
PostPosted: Sun May 27, 2018 9:33 pm 

Joined: Sun May 27, 2018 9:11 pm
Posts: 7

Offline
I can get value of tag using dynamic tag name script. But the problem is tag value was not updated. I need to use tag.read() function and I don't know how to do that.
Anyone can help me!


 Profile  
 
 Post subject: Re: how can i make lightweighttag to get read() function
PostPosted: Fri Jun 01, 2018 9:17 am 
User avatar

Joined: Thu Nov 16, 2017 3:32 pm
Posts: 44

Offline
I may need a bit more context on what you're trying to do, but it sounds like you should just be able to read the tag value using the Globals.Tags.<YourTagName>.Value

_________________
iX Quick Links:
iX Reference Manual: http://beijerinc.com/download/index.php?id=ix/referencemanual
iX Video Tutorials: https://www.beijerelectronics.com/en/Products/software/ix-hmi-software/Vimeo___video___page


 Profile  
 
 Post subject: Re: how can i make lightweighttag to get read() function
PostPosted: Tue Jun 05, 2018 3:43 pm 

Joined: Thu Dec 03, 2015 2:48 pm
Posts: 2

Offline
You need to do the following...

add...

using Interfaces.Tag;

and then access the tag as below.

((IBasicTag)Globals.Tags.Auto_BatchEndOkToSaveData).Read();


Regards


 Profile  
 
 Post subject: Re: how can i make lightweighttag to get read() function
PostPosted: Thu Jun 14, 2018 1:46 am 

Joined: Sun May 27, 2018 9:11 pm
Posts: 7

Offline
Russ C. wrote:
I may need a bit more context on what you're trying to do, but it sounds like you should just be able to read the tag value using the Globals.Tags.<YourTagName>.Value


I just try to use dynamic string tag and when I use in script module, I notice that lightweighttag doesn't update value which real value in plc. I made some script that use dynamic tag script to read value and send to remote server using mqtt. So, some tags were freeze. Datalogger tags and Alarm tag go working. So, I force to use read() and send to mqtt broker. But I can't use on lightweighttag. Right now my stupid solution is I make script that initial with if clause that always false and write Globals.Tags.tag.Read(); for everytag. The purpose is make every tag change to GlobalDataTag while compile time. But Globals.Tags.tag.Read(); function never fire coz of if(false) condition. Any Idea?
Thanks you.


 Profile  
 
 Post subject: Re: how can i make lightweighttag to get read() function
PostPosted: Fri Jun 15, 2018 4:10 am 

Joined: Sun May 27, 2018 9:11 pm
Posts: 7

Offline
Nightf1y wrote:
You need to do the following...

add...

using Interfaces.Tag;

and then access the tag as below.

((IBasicTag)Globals.Tags.Auto_BatchEndOkToSaveData).Read();


Regards

Hi Nightf1y
I am using below script to get dynamic tag value

public string Str2Tags(string TagName)
{
//string to tagName and get relative value, if unavilable return NaN
string strb;
try
{
double bb = double.Parse(getVal(TagName).Value.ToString());
strb = bb.ToString("0.##");
return strb;

}
catch(Exception)
{
return "NaN";
}
}

public static T StringToTag<T>(string tagName) where T : class
{
Type type = typeof(T);
FieldInfo[] props = Globals.Tags.GetType().GetFields();
foreach (FieldInfo prop in props) {
if (prop.FieldType.Equals(type)) {
if (prop.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase)) {
return (T)prop.GetValue(Globals.Tags);
}
}
}
return null;
}

public VariantValue getVal(string tagName)
{
GlobalDataItem GDI = StringToTag<GlobalDataItem>(tagName);
if (GDI == null)
{
LightweightTag LWT = StringToTag<LightweightTag>(tagName);
if (LWT == null)
return null;
else
{
return LWT.Value;
}
}
else
{
GDI.Read();
return GDI.Value;
}
}

I used GDI.Read(); to get actual value in plc. But I don't know how to get LWT value when screen is not openned which has lightweighttag.


 Profile  
 
 Post subject: Re: how can i make lightweighttag to get read() function
PostPosted: Tue Jun 26, 2018 12:34 am 

Joined: Sun May 27, 2018 9:11 pm
Posts: 7

Offline
artistmonkey wrote:
Nightf1y wrote:
You need to do the following...

add...

using Interfaces.Tag;

and then access the tag as below.

((IBasicTag)Globals.Tags.Auto_BatchEndOkToSaveData).Read();


Regards

Hi Nightf1y


Hi Nightf1y,
it's working. I put ((IBasicTag)LWT).Read();
Thank You very much.


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: