Vai al contenuto

Comparison a LWORD variable with constants

Home Forum Programmazione IEC 61131 (LogicLab) Comparison a LWORD variable with constants

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Autore
    Post
  • #73730
    Anonimo
    Inattivo

    Trying to use LWORD type  variables in a function,i found out that the  operation comparison with zero literal results error. If I determine it as a typed literal (LWORD#0) the result is correct.

    I don’t know if it is a bug or not.

    #73733
    Sergio Bertana
    Amministratore del forum

    Currently the LogicLab compiles the comparisons considering the constants as a DWORD (32 bits), so without any type declaration only the first 32 bits of the LWORD variable are compared, please refer to the following example.

    VAR
        MyLW : LWORD;
        MyResult : ARRAY[0..3] OF BOOL;
    END_VAR
    
        // TRUE  IF MyLW=16#0000000000000000
        // TRUE  IF MyLW=16#0000000100000000
        // FALSE IF MyLW=16#0000000010000000
    
        MyResult[1]:=TO_BOOL(MyLW = 0);
    
        // FALSE IF MyLW=16#0000000000000000
        // FALSE IF MyLW=16#0000000100000000
        // TRUE  IF MyLW=16#0000000010000000
    
        MyResult[0]:=TO_BOOL(MyLW <> 0); 
    
        // TRUE  IF MyLW=16#0000000000000000
        // TRUE  IF MyLW=16#0000000100000000
        // TRUE  IF MyLW=16#0000000010000000
    
        MyResult[3]:=TO_BOOL(MyLW = LWORD#0);
    
        // FALSE IF MyLW=16#0000000000000000
        // TRUE  IF MyLW=16#0000000100000000
        // TRUE  IF MyLW=16#0000000010000000
    
        MyResult[2]:=TO_BOOL(MyLW <> LWORD#0);
    
    // [End of file]

    As you can see in the example to obtain correct result L’WORD# must precede the constant declaration. I will ask to Axel if in the future some modifications will be done.

Stai visualizzando 2 post - dal 1 a 2 (di 2 totali)
  • Devi essere connesso per rispondere a questo topic.