Obsidean_VM/04-InLavoro/9..... MASTER Transport/Standard Transport/FC 5500 - FC Var To Dint.md

1.4 KiB

#t_Address := #InVar; // Open the ANY pointer so we can work
IF #t_Any_UDT.Source_DataType = 16#01 THEN // Work only with bools
    #t_Byte := DWORD_TO_INT(SHR(IN := #t_Any_UDT.Source_Byte_Pointer, N := 3)); // Get the byte
    #t_Bit := DWORD_TO_BYTE(#t_Any_UDT.Source_Byte_Pointer) AND 15;     // Get the bit
    #Alarm := PEEK_BOOL(area := #cDB, dbNumber := #t_Any_UDT.Source_DB_Number, byteOffset := #t_Byte, bitOffset := #t_Bit);  // Ask the state of the bit
    
    IF #Alarm THEN
        // First we calculate the max magnitude we need, the number of 0 to use to pack all numbers so DB[XXX] + Byte[BBB] + Bits[b] => XXXBBb 
        IF #t_Byte = 0 THEN
            #t_Magnitude_Byte := 1; // In case Byte is 0 LN(0) is undefined so we use 1 to get the space for the byte
        ELSE
            #t_Magnitude_Byte := #t_Byte;
        END_IF;
        #t_Magnitude := REAL_TO_DINT(EXP(LN(10) * TRUNC(LN(WORD_TO_INT(#t_Any_UDT.Source_DB_Number)) / LN(10)) + TRUNC(LN(WORD_TO_INT(#t_Magnitude_Byte)) / LN(10))));
        #Value := WORD_TO_DINT(#t_Any_UDT.Source_DB_Number) * #t_Magnitude + #t_Byte * 10 + #t_Bit;
    END_IF;
END_IF;

Esempio di chiamata:

      CALL  "FC Any To Dint on Alarm"
         Address   :="DB Pack Alarm".A471_39_4
         Num_Alarm :=#T_Warning_Zone

Se questo bit "DB Pack Alarm".A471_39_4 e true ritorna 471394 su #T_Warning_Zone