Funzioni ed FB per conversione dati

VBitTest, Variable bit test

image0

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
image1

Esempio LD

image2

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

image3

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
image4

Esempio LD

image5

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

image6

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
image7

Esempio LD (PTP114A100, LD_BitToByte)

image8

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

image9

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
image10
Esempio LD (PTP114A100, LD_ByteToBit)

image11

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

image12

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
image13

Esempio LD (PTP114A100, LD_ByteToWord)

image14

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

image15

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
image16
Esempio LD (PTP114A100, LD_WordToByte)

image17

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.

image18

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
image19

Esempio LD (PTP114A100, LD_DoubleToWord)

image20

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

image21

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
image22

Esempio LD (PTP114A100, LD_WordToDouble)

image23

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

image24

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
image25

Esempio LD

image26

BEArrayTo Var, Big endian array to variable conversion

image27

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
image28

Esempio LD

image29

VarToLEAr ray, variable to little endian array conversion

image30

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
image31

Esempio FBD

image32

VarToBEAr ray, variable to big endian array conversion

image33

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
image34

Esempio FBD

image35

VarSwap, swap variable value

image36

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
image37

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

image38

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
image39

Esempio LD

image40