Author Topic: How to handle ReadUDT() with an array of boolean  (Read 1294 times)

sramirez

  • Newbie
  • *
  • Posts: 18
    • View Profile
How to handle ReadUDT() with an array of boolean
« on: December 07, 2022, 03:56:56 PM »
I have a test UDT that I am trying to read a tag with the Data Type of BOOL[3]
I get an error "Index out of range" when I try to use ReadUDT().

I can't figure out what I am doing wrong since I am setting the size of the List(of boolean) in the constructor.

Dim plc As New AdvancedHMIDrivers.EthernetIPforCLXCom
plc.ipaddress = "192.168.1.9"
Dim obj As Test1 = plc.ReadUDT(Of Test)("Test1")

UDT
Test1.TestString STRING
Test1.TestBool BOOL[3]

My vb class is defined as
Public Class Test
  Public Property TestString as string
  Public Property TestBool as new List(of boolean)
  Public Sub New()
     for i = 0 to 2
        TestBool.add(0)
     next
  End Sub
End Class

Thanks for any assistance.
Shawn


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: How to handle ReadUDT() with an array of boolean
« Reply #1 on: December 07, 2022, 04:08:51 PM »
If you are not using version 3.99y Beta, which is downloadable from this forum, try that version.

sramirez

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: How to handle ReadUDT() with an array of boolean
« Reply #2 on: December 08, 2022, 03:04:22 PM »
I gave AdvancedHMIv399yBeta38 a try, and did not have any success.
I included the test program.

If I comment out the BoolTest list and the for loop that initializes the list the ReadUDT returns as expected.
I am grateful for any help.

Module Module1

    Sub Main()
        Dim plc As New AdvancedHMIDrivers.EthernetIPforCLXCom

        With plc
            .IPAddress = "192.168.1.9"
            .PollRateOverride = 1000
            .ProcessorSlot = 0
        End With

        Dim obj As SRTest1 = plc.ReadUDT(Of SRTest1)("SRTest1") <--- Error happens on ReadUDT <Index was out of range. Must be non-negative and less than the size of the collection.>

    End Sub

    Public Class SRTest1
        Public Property TestS1 As String
        Public Property TestS2 As New UDT_Pan_Stile
        Public Property SRTestS3 As Int32
        Public Property BoolTest As New List(Of Boolean)
        Public Sub New()
            For i = 0 To 31
                BoolTest.Add(False)
            Next
        End Sub
    End Class
    Public Class UDT_Pan_Stile
        Public Property Location As Single
        Public Property Type As Int32
        Public Property Gauge As Single
    End Class
End Module

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: How to handle ReadUDT() with an array of boolean
« Reply #3 on: December 09, 2022, 06:07:31 PM »
"Index out of range"
Test1.TestBool BOOL[3]
 for i = 0 to 2


can you figure out now?
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

sramirez

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: How to handle ReadUDT() with an array of boolean
« Reply #4 on: December 12, 2022, 08:18:53 AM »
Thank you for your assistance.

I have tried for i=0 to 31 in my class's NEW() constuctor but I still get the error "ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection."

I have included images my code and the UDT.  I am doing something wrong but I can't figure out what.
If you have time to take another look I would be grateful.

Thanks,
Shawn R

sramirez

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: How to handle ReadUDT() with an array of boolean
« Reply #5 on: December 12, 2022, 10:06:20 AM »
I believe I got it to work.

Public Property BoolTest As New List(Of Boolean) and the Sub New() did not work

Removing the Sub New() and changing BoolTest to

Public BoolTest(31) as boolean solved the issue.

Note, you can't define a Public Property BoolTest(31) as boolean