AdvancedHMI Software

General Category => Support Questions => Topic started by: sds5150 on February 04, 2020, 12:00:15 PM

Title: ReadUDT with array
Post by: sds5150 on February 04, 2020, 12:00:15 PM

We are trying to use the ReadUDT function in AdvancedHMIv399yBeta33.
The image shows our test UDT in the PLC called TIme.

We have a class setup in vb.net as follows
Public Class TimeUDT
        Public Property Yr As Int32
        Public Property Mo As Int32
        Public Property Da As Int32
        Public Property Hr As Int32
        Public Property Min As Int32
        Public Property Sec As Int32
        Public Property uSec As Int32
        Public Property double_str As String
        Public Property single_str As String
    End Class

When we execute the code

Dim objT As TimeUDT
 objT = _EthernetCommsMain.ReadUDT(Of TimeUDT)("time")

We get data filling the properties but run into a problem with double_str.  It is an array in the UDT. 

How do we setup our class so that it can handle the array?

Thanks for the help!

Title: Re: ReadUDT with array
Post by: Archie on February 04, 2020, 05:25:55 PM
Public Class TimeUDT
        Public Yr As Int32
        Public Mo As Int32
        Public Da As Int32
        Public Hr As Int32
        Public Min As Int32
        Public Sec As Int32
        Public uSec As Int32
        Public double_str(2) As String
        Public single_str As String
    End Class
Title: Re: ReadUDT with array
Post by: bachphi on December 03, 2020, 08:16:47 AM
If a StrArray declared as STRING[2] on the PLC side, then its class size should be declared as (1) not 2 :

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 mSec As Integer
    Public StrArr(1) As String
End Class
....
        Dim DTCurrent As DateTimeUDT = PLC.ReadUDT(Of DateTimeUDT)("DTCurrent")


(https://i.postimg.cc/vT4PM2jM/UDT-Date-Time.png)
Title: Re: ReadUDT with array
Post by: Archie on December 03, 2020, 08:49:53 AM
If a StrArray declared as STRING[2] on the PLC side, then its class size should be declared as (1) not 2 :
Good catch. Trying to keep up with which system indicates number of elements versus the maximum element always makes me have to think twice.
Title: Re: ReadUDT with array
Post by: diegokarts@gmail.com on June 11, 2021, 03:54:58 PM
Some example for C#??
Title: Re: ReadUDT with array
Post by: Godra on June 11, 2021, 11:20:08 PM
There is some C# here: https://www.advancedhmi.com/forum/index.php?topic=2545.0

You can also try using online converters to convert from VB to C#.