Compare UDTs Value

Good morning all,

I'm in the process of developing my first project with the PLCNext and i run into some problems so far, i will make another post for the other problems but for this one i would like to ask the next:

Is it possible to compare somehow the value of two UDTs variables?

Let's say for example that i have created the next Data Types:

[b]TYPE

DatosAlarma : STRUCT
    
        Equipo : WSTRING := "";
        Texto : WSTRING := "";
        Activa : BOOL;
        Timestamp: LDATE_AND_TIME;
        Categoria : USINT := 0;
    
    END_STRUCT
    
    AlarmArray : ARRAY[0..99] of DatosAlarma;

END_TYPE[/b]

If i create two variables of the new type [b]"AlarmArray"[/b] and try to compare them in ST language to check if there's been any changes in the value of one of them, the software throws my an error:

[b]"The data type of the left operand ('AlarmArray') is not 'ANY_ELEMENTARY'. "[/b]

Is there any way two avoid this error and compare this two variables?

Thank you in advance!

Kind Regards,

Nacho

Unfortunately It’s not possible to do this as simply as you would like.

In languages like C++ you could overload the equality operator in your custom type, but that type of thing is currently not possible in IEC 61131 languages.
One solution would be to create a function that evaluates the equality of two variables of your custom type. You would need a separate function for every operator for every custom type, but if you only need a small number of these it might be a manageable (and neat) solution.

Hi martin,

Thank you for your quick response!

OK, that's a possible solution for me as i will only need (for the moment) to compare just one type of data types.

May i ask another question as we are already here:

Is it possible to create a variable of type ARRAY of "something" or a STRUCT directly in the variables tab of a function block without having to create a datatype for that?

Kind regards,

Nacho

No, unfortunately not. You will need to create a new data type for every array (type/length) and every struct. In PLCnext Engineer it is not possible to create these type definitions in a variable table.