libplctag-csharp
libplctag-csharp copied to clipboard
Accessing UTD
I have the following UDT. Is there way I can access the week[0].day[0] and so on... to read and write to it. I have tried using the following tag but gives me out of bounds error. ("IPAddress", "1, 0", CpuType.LGX, "Week[0].Day", DataType.Float32, 100); var TstTag1 = client.GetFloat32Value(tag, (elementnumber * tag.ElementSize));
Akhil.
You seem to be requesting 100 elements from an array which has 78 elements. If you lower the number of elements to 78 or below then test it with either "Week[0].Day" or "Week[0].Day[0]".
You should definitely check the AdvancedHMI forum website which has lots of highly functional software, including a tag browser program (free registration is required to access it). See this message:
https://www.advancedhmi.com/forum/index.php?topic=2670.msg16843#msg16843
It is currently in the form of a standalone Windows package which should provide a little bit more UDT related info.
You should use something like the following ` private Tag<RealPlcMapper, float> generateRealTag(string tagName, string tagData) {
var tag = new Tag<RealPlcMapper, float>()
{
Name = $"{tagName}.{tagData}",
Gateway = IPAddress,
Path = $"1,{Path}",
PlcType = PlcType.ControlLogix,
Protocol = Protocol.ab_eip,
Timeout = TimeSpan.FromSeconds(3)
};
return tag;
}`
You should pass in generateRealTag("Week[0]","Day[0]");
Mind you this is a method I made, but It is how I create specific data typed tags. I have one for each of the data types and I use a dynamic to use them. to do data that has more than one such as you Week[0].Day example I would just do a while and if it fails do a Thread.Sleep(1) and do another try (sometimes there may be a timeout ) then try again. it it fails you will know its at the end.