248
Manual – IPOSplus®
18
Querying bits and input terminals
Compiler – Examples
18.3 Querying bits and input terminals
To query what level a certain input terminal has, a bit must be tested with a variable. The
variable is either H483 (InputLevel), which contains the levels of the binary inputs, or a
variable h of your choice which contains the levels after the _GetSys() function has been
performed.
18.3.1 Testing single bits
To test a bit in a variable, perform an AND operation using a constant in which the bit to
be tested is set to one.
If the result is zero, then the bit to be tested is also zero and thus the input terminal level
is low. If the result is not zero, then the bit is one.
The following example sets H10 to 1 if binary input DI03 is set to one.
18.3.2 Testing several bits
In order to test several bits of a variable for a certain state, you have use an AND oper-
ation to mask the bits to be tested and compare the result with a constant that corre-
sponds to the bit pattern to be tested.
The following example sets H10 to 1 if there is a 1 at DI01 and a 0 at DI03.
#include <const.h>
#define DI03 0b1000
#define DI01 0b0010
main()
{
if(( InputLevel & (DI03 ¦ DI01)) == 0b0010)
{
H10 = 1;
}
}
Testing individual bit using H483 Testing individual bit using _GetSys()
#include <const.h>
#include <io.h> // MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
main()
{
if(( InputLevel & DI03 ) != 0)
{
H10 = 1;
}
}
#include <const.h>
#define INPUTS H1
#include <io.h> // MOVIDRIVE A
#include <iob.h> // MOVIDRIVE B
main()
{
_GetSys( INPUTS, GS_INPUTS );
if(( INPUTS & DI03 ) != 0)
{
H10 = 1;
}
}