Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag Data Type Modification #14

Closed
Ryushi5 opened this issue Mar 21, 2024 · 2 comments
Closed

Tag Data Type Modification #14

Ryushi5 opened this issue Mar 21, 2024 · 2 comments

Comments

@Ryushi5
Copy link

Ryushi5 commented Mar 21, 2024

Hey, I just started checking out your project and it looks really great! I'm trying to use it for some simple things, and I've run into something that I can't quite figure out.

I am opening an existing L5X that has AOIs defined already. What I would like to do is simply create a tag, and set it's data type to that AOI. From what I can see, the DataType is just read-only for the tag. Looking into your code, it seems like I might have to replicate the AOI in C# class form to be able to get it to work is that right?

Is there a way to simply create a new tag and have it's DataType set to a string value?

@tnunnink
Copy link
Owner

tnunnink commented Mar 21, 2024

Hi there,

Yes, you just need to set Value to an instance of a ComplexType.

var tag = new Tag { Name = "Test", Value = new ComplexType("My_AOI_Type_Name") };

This may look weird, but it keeps DataType in sync with the actual type of Value for a given tag (so ultimately you have less work to do). ComplexType is a "generic" data type class you can use to build up a data structure dynamically. Meaning, you can add/remove members to ComplexType in order to load data into Logix upon import.

var aoi = new ComplexType("MyAoi");
aoi.Add(new LogixMember("Member01", new DINT(100)));
aoi.Add(new LogixMember("Member02", new TIMER { PRE = 3000 }));
aoi.Add(new LogixMember("Member03", new ComplexType("SubType")));

Or you can do this more concisely from Tag itself.

var tag = new Tag { Name = "Test", Value = new ComplexType("My_AOI_Type_Name") }; 
tag.Add("Member01", new DINT(100));
tag.Add("Member02", new TIMER { PRE = 3000 });
tag.Add("Member03", new ComplexType("SubType"));

Of course, you could create your AOI type using a C# class and derive from ComplexType, but it is not strictly necessary. It just lets you new up instances of your custom type without have to always add all the members this way.

Hopefully this makes sense. Let me know if you need any further clarification.

@Ryushi5
Copy link
Author

Ryushi5 commented Mar 21, 2024

5 Stars man! That was a very detailed answer in a very short time.

That's exactly what I'm looking for. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants