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!
how can i make lightweighttag to get read() function
-
- Posts: 7
- Joined: Sun May 27, 2018 9:11 pm
Re: how can i make lightweighttag to get read() function
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
Best regards,
Russ
(801) 708-6690
Technical Support
Contact Us
Beijer Electronics AB
http://www.beijerelectronics.us
Russ
(801) 708-6690
Technical Support
Contact Us
Beijer Electronics AB
http://www.beijerelectronics.us
Re: how can i make lightweighttag to get read() function
You need to do the following...
add...
using Interfaces.Tag;
and then access the tag as below.
((IBasicTag)Globals.Tags.Auto_BatchEndOkToSaveData).Read();
Regards
add...
using Interfaces.Tag;
and then access the tag as below.
((IBasicTag)Globals.Tags.Auto_BatchEndOkToSaveData).Read();
Regards
-
- Posts: 7
- Joined: Sun May 27, 2018 9:11 pm
Re: how can i make lightweighttag to get read() function
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?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
Thanks you.
-
- Posts: 7
- Joined: Sun May 27, 2018 9:11 pm
Re: how can i make lightweighttag to get read() function
Hi Nightf1yNightf1y 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
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.
-
- Posts: 7
- Joined: Sun May 27, 2018 9:11 pm
Re: how can i make lightweighttag to get read() function
Hi Nightf1y,artistmonkey wrote:Hi Nightf1yNightf1y 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
it's working. I put ((IBasicTag)LWT).Read();
Thank You very much.