Vai all indice del manuale di programmazione
Tipo:
Blocco funzione
Libreria LogicLab:
eLLabUtyLib
Libreria Codesys:
Non disponibile
Questo blocco funzione permette di convertire una variabile DWORD in due variabili WORD. I 16 bits alti di In verranno trasferiti nell’operando MSW, i 16 bits bassi verranno trasferiti nell’operando LSW.
Descrizione
In (DWORD) Variabile da convertire.
MSW (WORD) MSW del valore in ingresso.
LSW (WORD) LSW del valore in ingresso.

Esempi
Come utilizzare gli esempi.
Nell’esempio una variabile DWORD con valore 16#12345678 è trasferita in due variabili WORD che avranno valore 16#1234 e 16#5678.
LogicLab (Ptp114, IL_DoubleToWord)
PROGRAM IL_DoubleToWord
VAR
High : WORD; (* MSW word *)
Low : WORD; (* LSW word *)
DData : DWORD := 16#12345678; (* Double word data *)
DDec : DoubleToWord; (* Double decompress *)
END_VAR
(* ************************************************************************** *)
(* PROGRAM "IL_DoubleToWord" *)
(* ************************************************************************** *)
(* This program shows the use of DoubleToWord function block. *)
(* ------------------------------------------------------------------------- *)
LD DData
ST DDec.In (* Transfer the variable to input *)
CAL DDec (* Call the function block *)
LD DDec.MSW
ST High (* Transfer the MSW output to variable *)
LD DDec.LSW
ST Low (* Transfer the LSW output to variable *)
(* [End of file] *)
LogicLab (Ptp114, ST_DoubleToWord)
PROGRAM ST_DoubleToWord
VAR
DData : DWORD := 16#12345678; (* Double word data *)
High : ARRAY[ 0..1 ] OF WORD; (* MSW word *)
Low : ARRAY[ 0..1 ] OF WORD; (* LSW word *)
DDec : DoubleToWord; (* Double decompress *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_DoubleToWord"
// *****************************************************************************
// This program shows the use of DoubleToWord function block.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// DECOMPRESS DWORD
// -------------------------------------------------------------------------
// Decompress word using the FB.
DDec(In:=DData);
High[0]:=DDec.MSW; //MSW word
Low[0]:=DDec.LSW; //LSW word
// -------------------------------------------------------------------------
// DECOMPRESS DWORD
// -------------------------------------------------------------------------
// The same operation as above executed directly using ST statements.
High[1]:=TO_WORD(DData/16#10000); //MSW word
Low[1]:=TO_WORD(DData); //LSW word
// [End of file]