User guide

24
VTB USER GUIDE
6.4 Bit
This type of variable can have only two values: 0 or 1, normally associated to a state OFF/ON or FALSE/TRUE. The variable
BIT must always refer to an original variable which will can contain more bits.
This variables are very useful to manage FLAGS, digital I/O lines and in all cases where we need to read or write a single
bit directly.
The bit variables can be both GLOBAL or PAGE LOCAL and they can be used like normal variables.
For example declaring an INTERNAL variable named STATE of type INT (16 bit) it's possible to associate it up to 16 bit
variables.
VARBIT1STATE.0 (first bit of STATE)
VARBIT2STATE.1 (second bit of STATE)
.
VARBIT16 STATE.15 (16th bit of STATE)
If VARBIT1 = 1 ' test if first bit of STATE is set
VARBIT2=1 ' set second bit of STATE
VARBIT3=0 'reset third bit of STATE
endif
A common use of these variables is the manage of the digital INPUT and OUTPUT lines of the system, as they are
equipped inside system (ex. NGIO) or they are remote channels in a CANOPEN or ETHERCAT net. In the first case the
bits will be associated to internal normal variables, while in the second one they will be contained in variables of type
VCB. That means declaring the bit variables we shell control physically the state of these I/O lines simply reading or
writing the relative bit variable.
DECLARING a BIT VARIABLE
FIELDS OF BIT VARIABLE
Name It identify the UNIVOCAL name of the bit variable
Original Variable Name of the variable associated to the bit one. It must be of type CHAR, UCHAR,
INT, UINT, LONG (also ARRAYS)
Nbit Number of the bit in the associated original variable
WARNING: the first bit is always the number 0 (zero)
The maximum number of bits depends by the type of the original variable:
CHAR/UCHAR 0-7 (8 bits)
INT/UINT 0-15 (16 bits)
LONG 0-31 (32 bits)