Author Topic: ReadUDT with array  (Read 1481 times)

sds5150

  • Newbie
  • *
  • Posts: 14
    • View Profile
ReadUDT with array
« 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!


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: ReadUDT with array
« Reply #1 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

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: ReadUDT with array
« Reply #2 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")


« Last Edit: December 03, 2020, 08:19:18 AM by bachphi »
===================================================
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: 5262
    • View Profile
    • AdvancedHMI
Re: ReadUDT with array
« Reply #3 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.

diegokarts@gmail.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: ReadUDT with array
« Reply #4 on: June 11, 2021, 03:54:58 PM »
Some example for C#??

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: ReadUDT with array
« Reply #5 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#.