AdvancedHMI Software

General Category => Open Discussion => Topic started by: Kramrellim on November 15, 2023, 09:06:08 AM

Title: ReadUDT Size
Post by: Kramrellim on November 15, 2023, 09:06:08 AM
Is there a size limit to a UDT?
I have a UDT that is 14244 bytes
Title: Re: ReadUDT Size
Post by: bachphi on November 15, 2023, 04:16:10 PM
Can you share the UDT to see If I can read it.?
Title: Re: ReadUDT Size
Post by: Kramrellim on November 15, 2023, 04:46:52 PM
Here it is in L5X format.
Title: Re: ReadUDT Size
Post by: bachphi on November 19, 2023, 08:12:39 PM
No good , wont import.

Error: Object does not exist.
Import failed - 1 error(s), 0 warning(s) - No changes were made to the project

STRING_16 is built in. No need to include
Title: Re: ReadUDT Size
Post by: Kramrellim on November 22, 2023, 08:25:32 AM
Thank you for trying. This UDT was supplied to me by Rockwell.
The controller is a Compact GuardLogix 5380  5069-L330ERMS2
Title: Re: ReadUDT Size
Post by: bachphi on November 23, 2023, 10:37:26 AM
That's probably why.  My PLC is a 5370.
Such messy string definition , for ex. STRING_8 can contains up to 24 chars.

I was able to import it into a L330ERMS2, rework the UDT to v2.  then import to my PLC.
It took less than a second to read all tags.
see picture & attached v2.

(https://i.imgur.com/h96fFUO.png6fFUO)
Title: Re: ReadUDT Size
Post by: Kramrellim on November 28, 2023, 07:08:07 PM
Thank you
Title: Re: ReadUDT Size
Post by: Kramrellim on December 01, 2023, 03:04:19 PM
That's probably why.  My PLC is a 5370.
Such messy string definition , for ex. STRING_8 can contains up to 24 chars.

I was able to import it into a L330ERMS2, rework the UDT to v2.  then import to my PLC.
It took less than a second to read all tags.
see picture & attached v2.

(https://i.imgur.com/h96fFUO.png6fFUO)

Yes, I can read the UDT structure with the tag reader. I'm trying now to read the data with ReadUDT.
Here is what I have as the structure.


Module HMI_UDT_Class

    Public completeData As UDT_HMI_StationStatus

    Public Class STR0004
        Public len1 As Int32
        Public STR4(4) As SByte
    End Class

    Public Class STR0016
        Public len2 As Int32
        Public STR16(16) As SByte
    End Class


    Public Class STR0024
        Public len3 As Int32
        Public STR0024(24) As SByte
    End Class

    Public Class String_24
        Public len4 As Int32
        Public Str24(24) As SByte
    End Class

    Public Class String_8
        Public len5 As Int32
        Public Str_8(24) As SByte

    End Class






    Public Class UDT_HMI_ActivePartProgram
        Public Program(19) As String
        Public SubProgram(9) As String
        Public ProgramName As String
        Public SubProgramName As String
        Public ProgramNumber As Int32
        Public SubProgramNumber As Int32
        Public ProgramLineNumber(19) As Int32
        Public SubProgramLineNumber(9) As Int32
        Public SubActive As Boolean
    End Class

    Public Class UDT_HMI_AngleOffset
        Public angleOffsetReq As Boolean
        Public angleOffsetVal As Single
    End Class

    Public Class UDT_HMI_Axis
        Public Enabled As Boolean
        Public InPos As Boolean
        Public Homed As Boolean
        Public Returned As Boolean
        Public Faulted As Boolean
        Public CmdPos As Single
        Public AbsPos As Single
        Public Speed As Single
        Public SpeedUnits As String
        Public Present As Boolean
        Public InhibitStatusButs As Int32
        Public CurrentFaultCode As Int32
        Public jogPos As Boolean
        Public jogNeg As Boolean
        Public jogEnabled As Boolean
        Public Name As STR0004
        Public MtrCurr As Single
        Public MtrCap As Single
        Public InvCap As Single
        Public PosErr As Single
    End Class

    Public Class UDT_HMI_AxisJog
        Public pos As Boolean
        Public neg As Boolean
        Public enabled As Boolean
        Public incChange As Boolean
        Public speed(5) As Single
        Public unit As String_8
        Public incSel As SByte
        Public spdSel As SByte
        Public increment(4) As Single
        Public mode As Boolean
        Public axisSelect As SByte
        Public axisPresent(32) As Boolean
        Public axisType As Int16
        Public axisName(6) As STR0004

    End Class

    Public Class UDT_HMI_Button
        Public Target As Boolean
        Public Active As Boolean
    End Class

    Public Class UDT_HMI_Coordinates
        Public X(500) As Single
        Public Y(500) As Single
        Public Angle(500) As Single
        Public Dist(500) As Single
        Public Active(500) As SByte

    End Class
    Public Class UDT_HMI_FeedrateOverride
        Public spdUnits As String_8
        Public Feedrate As Single
        Public overrideFeedrate As Single
        Public overrideEnabled As Boolean
        Public feedratePct As Single
        Public RapidPct As Int32

    End Class

    Public Class UDT_HMI_MachineStatus
        Public gStop As STR0016
        Public mStop As STR0016
        Public activeMcode(7) As STR0024
        Public activeGcode(7) As STR0024
        Public registers(15) As STR0024
        Public gBlink As Boolean
        Public mBlink As Boolean

    End Class

    Public Class UDT_HMI_Parameters
        Public Number(5) As Int32
        Public Value(5) As Single
        Public Name(5) As String_24

    End Class

    Public Class UDT_HMI_Spindle
        Public AtSpeed As Boolean
        Public Enabled As Boolean
        Public Faulted As Boolean
        Public CmdSpeed As Single
        Public ActSpeed As Single
        Public SpeedUnits As String
        Public Present As Boolean
        Public Direction As Boolean  ' 0=CW 1= CCW
        Public Name As STR0004
        Public MotorCap As Single


    End Class

    Public Class UDT_HMI_StateModle
        Public State As SByte
        Public notComplete As Boolean
        Public notCpEM As SByte

    End Class

    Public Class UDT_HMI_toolPathGraph
        Public inchMode As Boolean
        Public metricMode As Boolean
        Public SampleActive As Boolean
        Public Coordinates As UDT_HMI_Coordinates
        Public GraphClear As UDT_HMI_Button
        Public SampleRate As Single
        Public PosX As Single
        Public PosY As Single
        Public PosZ As Single
        Public UserPosX As Single
        Public UserPosY As Single
        Public UserPosZ As Single
        Public UserMaxX As Single
        Public UserMinX As Single
        Public UserMaxY As Single
        Public UserMinY As Single
        Public UserMaxZ As Single
        Public UserMinZ As Single
        Public DistThreshold As Single
        Public Units As String
        Public zoomPct As Single

    End Class



    Public Class UDT_HMI_StationStatus
        Public btnAuto As UDT_HMI_Button
        Public btnContinous As UDT_HMI_Button
        Public btnSingleStep As UDT_HMI_Button
        Public btnCycleStart As UDT_HMI_Button
        Public btnCycleStop As UDT_HMI_Button
        Public btnCycleAbort As UDT_HMI_Button
        Public btnTestMode As UDT_HMI_Button
        Public btnMode As UDT_HMI_Button
        Public btnManual As UDT_HMI_Button
        Public btnoptionalStop As UDT_HMI_Button
        Public btnBlockDelete As UDT_HMI_Button
        Public btnEmergencyReturn As UDT_HMI_Button
        Public btnControlReset As UDT_HMI_Button
        Public btnFaultReset As UDT_HMI_Button
        Public Axis01 As UDT_HMI_Axis
        Public Axis02 As UDT_HMI_Axis
        Public Axis03 As UDT_HMI_Axis
        Public Axis04 As UDT_HMI_Axis
        Public Axis05 As UDT_HMI_Axis
        Public Axis06 As UDT_HMI_Axis
        Public Axis07 As UDT_HMI_Axis
        Public Spindle01 As UDT_HMI_Spindle
        Public Spindle02 As UDT_HMI_Spindle
        Public Spindle03 As UDT_HMI_Spindle
        Public Spindle04 As UDT_HMI_Spindle
        Public Spindle05 As UDT_HMI_Spindle
        Public ActivePartProgram As UDT_HMI_ActivePartProgram
        Public AxisFault As Boolean
        Public State As Int32
        Public Mode As Int32
        Public ToolPathGraph As UDT_HMI_toolPathGraph
        Public MachineStatus As UDT_HMI_MachineStatus
        Public FeedRateOverride As UDT_HMI_FeedrateOverride
        Public stopIndicate As Boolean
        Public AxisJog As UDT_HMI_AxisJog
        Public Parameters As UDT_HMI_Spindle
        Public StateModel As UDT_HMI_StateModle
        Public AngleOffset As UDT_HMI_AngleOffset

    End Class




End Module

Read

        completeData = EthernetIPforCLXCom1.ReadUDT(Of HMI_UDT_Class.UDT_HMI_StationStatus)("Test_UDT")


I get this fault
IndexOutOfRangeException: Index was outside the bounds of the array.
Title: Re: ReadUDT Size
Post by: bachphi on December 01, 2023, 06:36:26 PM
I normally approach the issue by simplifying,  dividing and conquering.

Can you verify that you can read a simple tag with your custom length of 4?
Title: Re: ReadUDT Size
Post by: Kramrellim on December 02, 2023, 09:19:45 AM
Looks like its the custom length strings.
I get a "Index was outside the bounds of the array."

My example:

    Public Class STR0004
        Public len1 As Int32
        Public STR4(4) As SByte
    End Class

The custom string in the controller

STR004
      Len           DINT
      DATA         SINT[4]   
Title: Re: ReadUDT Size
Post by: bachphi on December 02, 2023, 01:53:32 PM
Aye, your issue was not about the size of the UDT, but rather in the string tag.  Now you can concentrate on finding the fix for it.
Title: Re: ReadUDT Size
Post by: Kramrellim on December 02, 2023, 02:34:26 PM
I've tried everything I can think of.
No luck.
Title: Re: ReadUDT Size
Post by: Godra on December 02, 2023, 03:15:31 PM
If your SINT[4] is 4 elements then your declaration should be Public STR4(3) As SByte.

See this link: https://kcwebprogrammers.blogspot.com/2011/01/vb-arrays-vs-c-arrays-in-aspnet.html
Title: Re: ReadUDT Size
Post by: bachphi on December 02, 2023, 03:40:37 PM
If you look at the tag in the PLC, you will see that that the data array index start at 0. So If a custom string length of 20, then you need to have 20-1=19.

Another thing you need to look at is the data type in the PLC is SINT. What is SINT?  is it really equivalent to SByte?
SINT is short integer(0 to255) not signed integer, a SByte is Signed Byte(-128 to 127)
Title: Re: ReadUDT Size
Post by: Godra on December 02, 2023, 08:07:24 PM
bachphi, your statement seems incorrect to me.

SINT, INT, DINT, LINT should be signed integers and USINT, UINT, UDINT, ULINT should be unsigned.

Check the following link:  https://help.codesys.com/api-content/2/codesys/3.5.12.0/en/_cds_datatype_integer/

Title: Re: ReadUDT Size
Post by: bachphi on December 02, 2023, 08:51:30 PM
LOL, you realized it's for Codesys PLC, not Rockwell source.

I would trust this guy Ron Beaufort: https://www.plctalk.net/qanda/showthread.php?t=59105

Plus, a string contains ASCII code from 0-255., make more sense than -128-127.
Title: Re: ReadUDT Size
Post by: Godra on December 02, 2023, 08:58:28 PM
Here is another link that states the same as what I posted previously:

   https://docs.inmation.com/system/1.94/datasource-interfaces/plc-datasource/ablogix5000.html
Title: Re: ReadUDT Size
Post by: Godra on December 02, 2023, 09:01:41 PM
Maybe Archie could pitch in his knowledge of SINT type.
Title: Re: ReadUDT Size
Post by: Kramrellim on December 03, 2023, 10:05:50 AM
Thanks guys for the help.
It looks like it use the array size as Godra suggested.
today I'll see if I can read the complete UDT.
Title: Re: ReadUDT Size
Post by: Kramrellim on December 04, 2023, 08:15:26 AM
Guys,
Thanks for your help. I got everything working that I need to have working.
I can poll all the data I need from one UDT in 30msec. I poll every 300msec with a Timer.

Thanks again.
Title: Re: ReadUDT Size
Post by: bachphi on December 04, 2023, 10:44:54 AM
Have you checked the actual string?