Writing tag values to a file
-
- Posts: 26
- Joined: Fri Jan 20, 2012 12:55 pm
Re: Writing tag values to a file
While generating a list of the Global.Tags, is there a possibility to find out if the particular tag is marked as a Bit, Bool, string etc.?
Is there also a way to find out if the tag is marked as Read, Write or Readwrite?
Is there also a way to find out if the tag is marked as Read, Write or Readwrite?
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: Writing tag values to a file
There is no way that I know of to access the data type or tag access type through scripting.
Best Regards,
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
-
- Posts: 26
- Joined: Fri Jan 20, 2012 12:55 pm
Re: Writing tag values to a file
Ok. Thanks anyway for your help on this subject.
-
- Posts: 22
- Joined: Fri May 25, 2012 7:44 am
- Location: Charlotte, NC. USA
Re: Writing tag values to a file
Let us reference back to my previous post [HERE] near the bottom you will find this code snippet...hans gerritsen wrote:Hi Patrick,
I have already a working version but your solution would much much better!!
But I only need those tags which are ReadWrite or Write and I have to know what kind of type it is (Bool, INT16, etc). I can't find how to do that.
Thanks in advance.
Code: Select all
ListBox1.Items.Clear();
foreach(GlobalDataItem gdi in Globals.Tags.GetTags<GlobalDataItem>()){
ListBox1.Items.Add(string.Format("{0}={1}",gdi.Name, gdi.Value));
}
Other properties of interest are .AccessRight, .DataType, and .GlobalDataType.
To determine if a tag is Read, Write or ReadWrite you can access the AccessRight property which returns an enum of type Neo.ApplicationFramework.Interfaces.AccessRights ... [gdi.AccessRight]
Simply checking if it is AccessRights.Write, or AccessRights.ReadWrite should indicate if the value can be changed as a result of a "load from CSV" (Assuming you get the VariantValue conversion correct).
GlobalDataType and DataType are both enums of type Neo.ApplicationFramework.Interop.DataSource.BEDATATYPE and pertain to columns A and C respectively. Column B is determined by the afformentioned .AccessRight property. see next image.
and using this updated bit of code...
Code: Select all
ListBox1.Items.Clear();
foreach(GlobalDataItem gdi in Globals.Tags.GetTags<GlobalDataItem>()){
ListBox1.Items.Add(string.Format("{0,5}={1,15} [{2,12}, {3,10}, {4,12}]",
gdi.Name,
gdi.Value,
gdi.GlobalDataType,
gdi.AccessRight,
gdi.DataType));
}
I'm sure with a little trial and error you should be able to figure out the other enumeration options (i.e. DT_* enum values for other data types).
Best Regards,
Patrick Hall
Patrick Hall
-
- Posts: 26
- Joined: Fri Jan 20, 2012 12:55 pm
Re: Writing tag values to a file
Perfect!
Thanks a lot Patrick
Thanks a lot Patrick
Re: Writing tag values to a file
Really helpfull, Patrick
-
- Posts: 26
- Joined: Fri Jan 20, 2012 12:55 pm
Re: Writing tag values to a file
I can read the GlobalDataType, AccessRight etc as described in previous topics.
How can I read if the tag is an array and the size of this array?
For example: tag 'Test' is of DataType=Bool[8]. The array size =8.
How can I read if the tag is an array and the size of this array?
For example: tag 'Test' is of DataType=Bool[8]. The array size =8.
-
- Posts: 1
- Joined: Thu Apr 13, 2017 12:07 am
Re: Writing tag values to a file
At runtime, the Reflection mechanism uses the Portable Executable file to read information about the assembly and it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. Reflection generally begins with a call to a method present on every object in the .NET framework, GetType(). The GetType() is a member of the System.Object class, and the method returns an instance of System.Type.
Type type = refCls.GetType();
The classes in the System.Reflection namespace, together with Type, enable you to get information about loaded assemblies and the types defined within them, such as classes, interfaces, and value types.
Source: .Net Reflection
Rino
Type type = refCls.GetType();
The classes in the System.Reflection namespace, together with Type, enable you to get information about loaded assemblies and the types defined within them, such as classes, interfaces, and value types.
Source: .Net Reflection
Rino
Re: Writing tag values to a file
Hello!!
What is the path you use to write on the panel? I tried using "C: /" but I can not then access that file via FTP
Can anybody help me?
Thank you!
[quote="hans gerritsen"]
public void SaveSettings(string path)
{
try {
using (StreamWriter Saving = new StreamWriter(path))
{
Saving.WriteLine(Globals.Tags.<tagname>.FullName.ToString()); Saving.WriteLine(Globals.Tags.<tagname>.Value.ToString());
}
}
catch{
MessageBox.Show("Error while saving");
}
}
What is the path you use to write on the panel? I tried using "C: /" but I can not then access that file via FTP
Can anybody help me?
Thank you!
[quote="hans gerritsen"]
public void SaveSettings(string path)
{
try {
using (StreamWriter Saving = new StreamWriter(path))
{
Saving.WriteLine(Globals.Tags.<tagname>.FullName.ToString()); Saving.WriteLine(Globals.Tags.<tagname>.Value.ToString());
}
}
catch{
MessageBox.Show("Error while saving");
}
}
Re: Writing tag values to a file
I know this is an older thread, however I am running into an issue with trying to use this code - specifically
I am testing this code exactly as described - yet no tags are added to the listbox. Through some debugging I have found out that
Code: Select all
public IEnumerable<T> GetTags<T>() where T:GlobalDataItem {
// Gets PropertyInfo array using reflection
PropertyInfo[] props = this.GetType().GetProperties();
// Process all PropertyInfo objects found
foreach (PropertyInfo prop in props) {
if (prop.PropertyType == typeof(T)) {
yield return (T)prop.GetValue(this, null);
}
}
}
Wereasprop.PropertyType is Neo.ApplicationFramework.Tools.OpClient.GlobalDataItems
When did this change? If i try to change the functions or any of the GlobalDataItem instances to GlobalDataItems the code will not build.typeof(T) is Neo.ApplicationFramework.Tools.OpClient.GlobalDataItem