Author Topic: ControlLogix ReadUDT and WriteUDT  (Read 10239 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
ControlLogix ReadUDT and WriteUDT
« on: May 28, 2018, 02:40:56 PM »
As of version 3.99y Beta 11, it is now possible to read and write complete UDTs into an equivalent class. To use this, you must create classes and map the data types from CLX to .NET equivalents. The following link has a chart that shows the data type equivalents:

https://advancedhmi.com/documentation/index.php?title=WriteUDT

An example would be the UDT shown in the attached picture. An equivalent class for this UDT would be:
Code: [Select]
Public Class DateTimeUDT
   Public Year As Integer
   Public Month As Integer
   Public Day As Integer
   Public Hour As Integer
   Public Minute As Integer
   Public Second As Integer
   Public Microseconds As Integer
End Class

Then to read the value of the UDT:

Code: [Select]
Dim MyUDT as DateTimeUDT = EthernetIpForCLXCom1.ReadUDT("MyUDT",GetType(DateTimeUDT))


NOTE : Creating a class with public fields is considered bad OOP practice. But in order to map arrays, it was necessary to bend that rule a little to make the ReadUDT possible.
« Last Edit: May 28, 2018, 02:45:17 PM by Archie »

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #1 on: May 28, 2018, 08:16:04 PM »
Definitely good news, thank you Archie.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ControlLogix ReadUDT and WriteUDT
« Reply #2 on: April 24, 2019, 10:16:00 AM »
As of 3.99y Beta 30, there has been a change in ReadUDT to use generics. The new format is like this:
Code: [Select]
        Dim MyUDT As DateTimeUDT = EthernetIPforCLXCom1.ReadUDT(Of DateTimeUDT)("MyUDT")

marcowy

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #3 on: January 06, 2021, 05:07:08 PM »
As of version 3.99y Beta 11, it is now possible to read and write complete UDTs into an equivalent class. To use this, you must create classes and map the data types from CLX to .NET equivalents. The following link has a chart that shows the data type equivalents:

https://advancedhmi.com/documentation/index.php?title=WriteUDT
According to this SINT = SByte. But what about USINT? Can I delcare it as Byte and read/write it with ReadUDT/WriteUDT?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ControlLogix ReadUDT and WriteUDT
« Reply #4 on: January 07, 2021, 09:39:40 PM »
According to this SINT = SByte. But what about USINT? Can I delcare it as Byte and read/write it with ReadUDT/WriteUDT?
Unsigned tag types are not yet supported, but I will look into getting this implemented in the next beta version.

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #5 on: January 07, 2021, 11:51:16 PM »
According to this SINT = SByte. But what about USINT? Can I delcare it as Byte and read/write it with ReadUDT/WriteUDT?
Unsigned tag types are not yet supported, but I will look into getting this implemented in the next beta version.

Unsigned types were added to the 5580/5380 platform only, v32 and above.  Also, Micro800 series.  I'm sure you already know but data types for reference (forgive the extra nonsense):

Code: [Select]
0xc6: (1, "USINT", '<B'),
0xc7: (2, "UINT", '<H'),
0xc8: (4, "UDINT", '<I'),
0xc9: (8, "LWORD", '<Q'),
0xcb: (8, "LREAL", '<d'),

Edit: Maybe you are already supporting those types and you were referring to adding support for read/write UDT specifically.  My bad if that statement is true...

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ControlLogix ReadUDT and WriteUDT
« Reply #6 on: January 08, 2021, 02:32:59 AM »
According to this SINT = SByte. But what about USINT? Can I delcare it as Byte and read/write it with ReadUDT/WriteUDT?
Unsigned tag types are not yet supported, but I will look into getting this implemented in the next beta version.

Unsigned types were added to the 5580/5380 platform only, v32 and above.  Also, Micro800 series.  I'm sure you already know but data types for reference (forgive the extra nonsense):

Code: [Select]
0xc6: (1, "USINT", '<B'),
0xc7: (2, "UINT", '<H'),
0xc8: (4, "UDINT", '<I'),
0xc9: (8, "LWORD", '<Q'),
0xcb: (8, "LREAL", '<d'),

Edit: Maybe you are already supporting those types and you were referring to adding support for read/write UDT specifically.  My bad if that statement is true...
I thought it needed to be implemented for both reading individual tags and parsing when Reading/writing UDTs, but after looking I see support for those new tag types were already implemented when reading them individually. So only parsing the UDT byte steam into equivalent classes needs to be implemented.

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #7 on: January 08, 2021, 01:26:06 PM »
According to this SINT = SByte. But what about USINT? Can I delcare it as Byte and read/write it with ReadUDT/WriteUDT?
Unsigned tag types are not yet supported, but I will look into getting this implemented in the next beta version.

Unsigned types were added to the 5580/5380 platform only, v32 and above.  Also, Micro800 series.  I'm sure you already know but data types for reference (forgive the extra nonsense):

Code: [Select]
0xc6: (1, "USINT", '<B'),
0xc7: (2, "UINT", '<H'),
0xc8: (4, "UDINT", '<I'),
0xc9: (8, "LWORD", '<Q'),
0xcb: (8, "LREAL", '<d'),

Edit: Maybe you are already supporting those types and you were referring to adding support for read/write UDT specifically.  My bad if that statement is true...
I thought it needed to be implemented for both reading individual tags and parsing when Reading/writing UDTs, but after looking I see support for those new tag types were already implemented when reading them individually. So only parsing the UDT byte steam into equivalent classes needs to be implemented.

After I had posted, I thought I remembered us discussing this when v32 first came out.  I remember borrowing hardware to test this in python.

diegokarts@gmail.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #8 on: June 11, 2021, 02:29:56 PM »
I need read a Array of UDT with size 10, in C#.
I have a error in command .ReadUDT. See attachments.

 public struct UDT
        {
           
            public Int32 Yr;
            public Int32 Mo;
            public Int32 Da;
            public Int32 Hr;
            public Int32 Min;
            public Int32 Sec;
            public Int32 uSec;
        }

        UDT[] Dates = new UDT[10];
           
           Dates = CLXCom.ReadUDT("Dates",10);

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: ControlLogix ReadUDT and WriteUDT
« Reply #9 on: June 11, 2021, 11:45:28 PM »
Your code should probably be more similar to this:

Code: [Select]
        public struct TimeUDT
        {
            public int Yr;
            public int Mo;
            public int Da;
            public int Hr;
            public int Min;
            public int Sec;
            public int uSec;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            var Dates = CLXCom.ReadUDT<TimeUDT>("Dates[0]", 10);
        }