Funzioni ed FB per conversione dati¶
VBitTest, Variable bit test¶
Type | Library |
Function | eLLabUtyLib_C030 |
Questa funzione esegue il test di un bit in una variabile.
Parametri funzione:
Variable (UDINT) | Variabile in cui testare il bit. |
Bit (USINT) | Numero del bit da testare (Range da 0 a 31). |
La funzione ritorna:
(BOOL) | Stato bit indicato. |
Esempi¶
Lo stato del bit 4 della variabile VarInp viene trasferito sull’uscita digitale Do00M00.
Definizione variabili |
![]() |
Esempio LD
Esempio IL
LD VarInp (* Variable input *)
VBitTest 4 (* Variable bit test *)
ST Do00M00 (* Transfer bit status to digital output *)
Esempio ST
Do00M00:=VBitTest(VarInp, 4); (\* Variable bit test \*)
VBitSet, Variable bit set¶
Type | Library |
Function | eLLabUtyLib_C030 |
Questa funzione esegue il set di un bit in una variabile.
Parametri funzione:
Value (BOOL) | Valore bit da settare. |
Variable (UDINT) | Variabile in cui settare il bit. |
Bit (USINT) | Numero del bit da settare (Range da 0 a 31). |
La funzione ritorna:
(UDINT) | Valore variabile dopo il set del bit. |
Esempi¶
Lo stato dell’ingresso digitale Di00M00 è trasferito nel bit 8 della variabile VarOut.
Definizione variabili |
![]() |
Esempio LD
Esempio IL
LD Di00M00 (\* Variable input \*)
VBitSet VarOut, 8 (\* Variable bit set \*)
ST VarOut (\* Transfer result to variable \*)
Esempio ST
VarOut:=VBitSet(Di00M00, VarOut, 8); (\* Variable bit set \*)
BitToByte, Bit to byte conversion¶
Type | Library |
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire 8 variabili BOOL in una variabile BYTE.
b0 (BOOL) | Bit 0 del byte di Out. |
… | … |
b7 (BOOL) | Bit 7 del byte di Out. |
Out (BYTE) | Risultato conversione ingressi a bit. |
Esempi¶
Gli 8 ingressi digitali del modulo 0 sono trasferiti nella variabile VarOut. Attivando il solo ingresso digitale Di00M00 la variabile VarOut assumerà valore 1, attivando il solo ingresso digitale Di01M00 la variabile VarOut assumerà valore 2, e così via fino all’ingresso Di07M00 attivando il quale la variabile VarOut assumerà valore 128. Attivando più ingressi contemporaneamente la variabile VarOut assumerà valore pari alla somma degli ingressi attivati.
Per semplicità negli esempi IL e ST non vengono riportati tutti i bit.
Definizione variabili |
![]() |
Esempio LD (PTP114A100, LD_BitToByte)
Esempio IL (PTP114A100, IL_BitToByte)
LD Di00M00
ST FBData.b0 (\* Transfer digital input to input bit \*)
LD Di07M00
ST FBData.b7 (\* Transfer digital input to input bit \*)
CAL FBData (\* Call the BitToByte function block \*)
LD FBData.Out
ST VarOut (\* Transfer the result to variable \*)
Esempio ST (PTP114A100, ST_BitToByte)
FBData.b0:=Di00M00; (\* Transfer digital input to input bit \*)
FBData.b7:=Di07M00; (\* Transfer digital input to input bit \*)
FBData(); (\* Call the BitToByte function block \*)
VarOut:=FBData.Out; (\* Transfer the result to variable \*)
ByteToBit, Byte to bit conversion¶
Type | Library |
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire una variabile BYTE in 8 variabili BOOL.
In (BYTE) | Valore byte da convertire |
b0 (BOOL) | Bit 0 di In. |
… | … |
b7 (BOOL) | Bit 7 di In. |
Esempi¶
Lo stato del bit 0 della variabile VarInp viene trasferito sull’uscita digitale Do00M00 lo stato del bit 1 della variabile VarInp viene trasferito sull’uscita digitale Do01M00 e così via fino allo stato del bit 7 della variabile VarInp viene trasferito sull’uscita digitale Do07M00. Per semplicità negli esempi IL e ST non vengono riportati tutti i bit.
Definizione variabili |
![]() |
Esempio LD (PTP114A100, LD_ByteToBit)
Esempio IL (PTP114A100, IL_ByteToBit)
LD VarInp
ST FBData.In (\* Transfer the variable to input \*)
CAL FBData (\* Call the ByteToBit function block \*)
LD FBData.b0
ST Di00M00 (\* Transfer output bit to digital output \*)
Esempio ST (PTP114A100, ST_ByteToBit)
FBData(In:=VarInp); (\* Call the ByteToBit function block \*)
Do00M00:=FBData.b0; (\* Transfer output bit to digital output \*)
Do01M00:=FBData.b1; (\* Transfer output bit to digital output \*)
ByteToWord, Byte to word conversion¶
Type | Library |
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire due variabili BYTE in una variabile WORD.
MSB (BYTE) | MSB del valore in uscita Out |
LSB (BYTE) | LSB del valore in uscita Out |
Out (WORD) | Valore in uscita |
Esempi¶
Le due variabili MSBByte e LSBByte sono uniti nella variabile VarOut in uscita.
Definizione variabili |
![]() |
Esempio LD (PTP114A100, LD_ByteToWord)
Esempio IL (PTP114A100, IL_ByteToWord)
LD MSBByte
ST FBData.MSB (\* Transfer the MSB variable to input \*)
LD LSBByte
ST FBData.LSB (\* Transfer the LSB variable to input \*)
CAL FBData (\* Call the ByteToWord function block \*)
LD FBData.Out
ST VarOut (\* Transfer output to variable \*)
Esempio ST (PTP114A100, ST_ByteToWord)
FBData.MSB:=MSBByte; (\* Transfer the MSB variable to input \*)
FBData.LSB:=LSBByte; (\* Transfer the LSB variable to input \*)
FBData(); (\* Call the ByteToWord function block \*)
VarOut:=FBData.Out; (\* Transfer output to variable \*)
WordToByte, Word to byte conversion¶
Type | Library |
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire una variabile WORD in due variabili BYTE.
IN (WORD) | Variabile da convertire. |
MSB (BYTE) | MSB del valore in ingresso. |
LSB (BYTE) | LSB del valore in ingresso. |
Esempi¶
Le variabile VarInp è divisa nelle due variabili MSBByte e LSBByte.
Definizione variabili |
![]() |
Esempio IL (PTP114A100, IL_WordToByte)
LD VarInp
ST FBData.In (\* Transfer the variable to input \*)
CAL FBData (\* Call the WordToByte function block \*)
LD FBData.MSB
ST MSBByte (\* Transfer the MSB output to variable \*)
LD FBData.LSB
ST LSBByte (\* Transfer the LSB output to variable \*)
Esempio ST (PTP114A100, ST_WordToByte)
FBData.In:=VarInp; (\* Transfer the variable to input \*)
FBData(); (\* Call the WordToByte function block \*)
MSBByte:=FBData.MSB; (\* Transfer the MSB output to variable \*)
LSBByte:=FBData.LSB; (\* Transfer the LSB output to variable \*)
DoubleToWord, Double to word conversion.¶
Type | Library |
---|---|
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire una variabile DWORD in due variabili WORD.
IN (DWORD) | Variabile da convertire. |
MSW (WORD) | MSW del valore in ingresso. |
LSW (WORD) | LSW del valore in ingresso. |
Esempi¶
Le variabile VarInp è divisa nelle due variabili MSBWord e LSBWord.
Definizione variabili |
![]() |
Esempio LD (PTP114A100, LD_DoubleToWord)
Esempio IL (PTP114A100, IL_DoubleToWord)
LD VarInp
ST FBData.In (\* Transfer the variable to input \*)
CAL FBData (\* Call the DoubleToWord function block \*)
LD FBData.MSW
ST MSBWord (\* Transfer the MSW output to variable \*)
LD FBData.LSW
ST LSBWord (\* Transfer the LSW output to variable \*)
Esempio ST (PTP114A100, ST_DoubleToWord)
FBData.In:=VarInp; (\* Transfer the variable to input \*)
FBData(); (\* Call the DoubleToWord function block \*)
MSBWord:=FBData.MSW; (\* Transfer the MSW output to variable \*)
MSBWord:=FBData.LSW; (\* Transfer the LSW output to variable \*)
WordToDou ble, Word to double conversion¶
Type | Library |
---|---|
FB | eLLabUtyLib_C030 |
Questo blocco funzione permette di convertire due variabili WORD in una variabile DWORD.
MSW (WORD) | MSB del valore in uscita Out |
LSW (WORD) | LSB del valore in uscita Out |
Out (DWORD) | Valore in uscita |
Esempi¶
Le due variabili MSBWord e LSBWord sono uniti nella variabile VarOut in uscita.
Definizione variabili |
![]() |
Esempio LD (PTP114A100, LD_WordToDouble)
Esempio IL (PTP114A100, IL_WordToDouble)
LD MSBWord
ST FBData.MSW (\* Transfer the MSW variable to input \*)
LD LSBWord
ST FBData.LSW (\* Transfer the LSW variable to input \*)
CAL FBData (\* Call the WordToDouble function block \*)
LD FBData.Out
ST VarOut (\* Transfer output to variable \*)
Esempio ST (PTP114A100, ST_WordToDouble)
FBData.MSW:=MSBWord; (\* Transfer the MSW variable to input \*)
FBData.LSW:=LSBWord; (\* Transfer the LSW variable to input \*)
FBData(); (\* Call the WordToDouble function block \*)
VarOut:=FBData.Out; (\* Transfer output to variable \*)
LEArrayTo Var, Little endian array to variable conversion¶
Type | Library |
---|---|
Function | eLLabUtyLib_C030 |
Questa funzione acquisisce il valore da un array little endian (MSB - LSB) Source e lo trasferisce nella variabile di destinazione Destination in base al tipo Type di variabile definito.
Parametri funzione:
Type (USINT) | Tipo di variabile destinazione come definito nella tabella Variable types definition. |
Destination (@USINT) | Indirizzo variabile di destinazione. |
Source (@USINT) | Indirizzo array sorgente. |
La funzione ritorna:
(BOOL) | FALSE: Errore tipo dati, TRUE: Conversione eseguita. |
Esempi¶
Il valore presente nell’array LEArray “1, 2, 3, 4” viene convertito nella variabile Variable, eseguita la conversione la variabile avrà il valore 16#01020304.
Definizione variabili |
![]() |
Esempio LD
BEArrayTo Var, Big endian array to variable conversion¶
Type | Library |
---|---|
Function | eLLabUtyLib_C030 |
Questa funzione acquisisce il valore da un array big endian (LSB - MSB) Source e lo trasferisce nella variabile di destinazione Destination in base al tipo Type di variabile definito.
Parametri funzione:
Type (USINT) | Tipo di variabile destinazione come definito nella tabella Variable types definition. |
Destination (@USINT) | Indirizzo variabile di destinazione. |
Source (@USINT) | Indirizzo array sorgente. |
La funzione ritorna:
(BOOL) | FALSE: Errore tipo dati, TRUE: Conversione eseguita. |
Esempi¶
Il valore presente nell’array BEArray “4, 3, 2, 1” viene convertito nella variabile Variable, eseguita la conversione la variabile avrà il valore 16#01020304.
Definizione variabili |
![]() |
Esempio LD
VarToLEAr ray, variable to little endian array conversion¶
Type | Library |
---|---|
Function | eLLabUtyLib_C030 |
Questa funzione trasferisce il valore di una variabile Source in base al tipo Type definito, in un array Destination utilizzando il formato little endian (MSB - LSB).
Parametri funzione:
Type (USINT) | Tipo di variabile come definito nella tabella Variable types definition. |
Destination (@USINT) | Indirizzo array di destinazione. |
Source (@USINT) | Indirizzo variabile sorgente. |
La funzione ritorna:
(BOOL) | FALSE: Errore tipo dati, TRUE: Conversione eseguita. |
Esempi¶
Il valore presente nella variabile Source viene convertito nell’array Destination di tipo little endian (MSB – LSB). Nell’esempio è riportata anche la finestra di Watch con i valori visualizzati.
Definizione variabili |
![]() |
Esempio FBD
VarToBEAr ray, variable to big endian array conversion¶
Type | Library |
---|---|
Function | eLLabUtyLib_C030 |
Questa funzione trasferisce il valore di una variabile Source in base al tipo Type definito, in un array Destination utilizzando il formato big endian (LSB - MSB).
Parametri funzione:
Type (USINT) | Tipo di variabile come definito nella tabella Variable types definition. |
Destination (@USINT) | Indirizzo array di destinazione. |
Source (@USINT) | Indirizzo variabile sorgente. |
La funzione ritorna:
(BOOL) | FALSE: Errore tipo dati, TRUE: Conversione eseguita. |
Esempi¶
Il valore presente nella variabile Source viene convertito nell’array Destination di tipo big endian (LSB – MSB). Nell’esempio è riportata anche la finestra di Watch con i valori visualizzati.
Definizione variabili |
![]() |
Esempio FBD
VarSwap, swap variable value¶
Type | Library |
---|---|
Function | eLLabUtyLib_C060 |
Questa funzione esegue lo swap del valore di una variabile. La funzione trasferisce eseguendone lo swap il valore della variabile Destination nella variabile Source in base al tipo Type definito.
Gli indirizzi di Source e Destination possono coincidere rendendo possibile lo swap sul valore diretto di una variabile.
Parametri funzione:
Type (USINT) | Tipo di variabile come definito
nella tabella Variable types
definition.
In base al tipo avremo:
BOOL_TYPE
Non viene eseguita alcuna
conversione.
Source=TRUE,
Destination=TRUE
BYTE_TYPE, SINT_TYPE,USINT_TYPE
Viene eseguito lo swap dei
nibbles (4 bit).
Source=16#12, Destination=16#21
WORD_TYPE, INT_TYPE, UINT_TYPE
Viene eseguito lo swap dei
bytes.
Source=16#1234,
Destination=16#3412
DWORD_TYPE, DINT_TYPE,
UDINT_TYPE, REAL_TYPE
Viene eseguito lo swap delle
words.
Source=16#12345678,
Destination=16#56781234
|
Destination (@USINT) | Indirizzo variabile di destinazione. |
Source (@USINT) | Indirizzo variabile sorgente. |
La funzione ritorna:
(BOOL) | FALSE: Errore tipo dati, TRUE: Funzione eseguita. |
Esempi¶
Sono effettuate alcune operazioni di swap di variabili.
Definizione variabili |
![]() |
Esempio ST (PTP114A670, ST_VarSwap)
ByteData[0]:=16#12; (\* Byte data example \*)
i:=VarSwap(BYTE_TYPE, ADR(ByteData[1]), ADR(ByteData[0]));
WordData[0]:=16#1234; (\* Word data example \*)
i:=VarSwap(WORD_TYPE, ADR(WordData[1]), ADR(WordData[0]));
WordData[2]:=WordData[1];
i:=VarSwap(BYTE_TYPE, ADR(WordData[2]), ADR(WordData[1]));
DWordData[0]:=16#12345678; (\* DWord data example \*)
i:=VarSwap(DWORD_TYPE, ADR(DWordData[1]), ADR(DWordData[0]));
DWordData[2]:=DWordData[1];
i:=VarSwap(WORD_TYPE, ADR(DWordData[2])+2, ADR(DWordData[1])+2);
IEE754DoubleToFloat, IEE754 double to float¶
Type | Library |
---|---|
Function | eLLabUtyLib_C040 |
Questa funzione esegue la conversione di un numero REAL nel formato IEE754 double (64 bits) nel formato IEE754 float (32 bits).
Parametri funzione:
Value (@BYTE) | Pointer all’array valore IEE da convertire. |
La funzione ritorna:
(REAL) | Valore variabile convertita. |
Esempi¶
Viene eseguita la conversione del valore double IEE754 “3FFB88CE703AFB7F” e si ottiene come risultato il valore REAL “1.7209”.
Definizione variabili |
![]() |
Esempio LD