EireannFian
On my project there is an enum data type with several values. What am i doing wrong here when using the EQ block with the enumerated type?
 
I first tried to put "PARADO_EMERG" with and without double quotes as a raw expression in an entry variable. Then the current approach on the screenshot which is creating a local variable to handle the enum element.
 
Captura de pantalla_20250421_022550.pngCaptura de pantalla_20250421_022523.png
 
However this error shows.
 
Terminado con estatus 1 (pid 32140)
/home/isi/Documentos/Programas/openplc-tfg-backup-openplc3/build/plc.st:42-23..42-28: error: Data type incompatibility for value passed in position 1 when invoking function 'EQ'
In section: PROGRAM program0
0042: _TMP_EQ9_OUT := EQ(estado, elemento_ejemplo_del_enum);
/home/isi/Documentos/Programas/openplc-tfg-backup-openplc3/build/plc.st:42-31..42-55: error: Data type incompatibility for value passed in position 2 when invoking function 'EQ'
In section: PROGRAM program0
0042: _TMP_EQ9_OUT := EQ(estado, elemento_ejemplo_del_enum);
/home/isi/Documentos/Programas/openplc-tfg-backup-openplc3/build/plc.st:42-20..42-56: error: Unable to resolve which overloaded function 'EQ' is being invoked.
In section: PROGRAM program0
0042: _TMP_EQ9_OUT := EQ(estado, elemento_ejemplo_del_enum);
3 error(s) found. Bailing out!
 
Captura de pantalla_20250421_022740.png
Reply 0 0
thiagoralves
You’ll have to build your own EQ block for custom data types because the default EQ doesn’t know what is “equal” on a data type it doesn’t understand. Building such block is quite simple. Just click on the grey plus sign on the left panel to create a Function (not Function Block) and select ST as the language. Suppose you name your block MY_EQ. Then on the top add two variables (state1 and state2) that are the states you want to compare and on the code you write something like this:
if state1 = state2 then
    MY_EQ := true;
else
    MY_EQ := false;
end_if;
 
Now you can use this block to compare your custom states.
Reply 1 0
Reply