How to Traverse BITs within a WORD/DWORD Variable in TwinCAT?

 A very straightforward question. Since each Bit in a Word or Dword variable in TwinCAT cannot be addressed using a variable to specify the index, for instance, wVar.3 is valid, but wVar.i is illegal. To address this, TwinCAT provides several functions for performing bit operations on variables:





For instance, the assignment statements wVar.i := TRUE or wVar.i := FALSE

can be written as: SetBit32(wVar, i) or ClearBit32(wVar, i)

The conditional statement wVar.i = TRUE

can be written as: GetBit32(wVar, i)