In most input cards of Beckhoff, there are two variables, Limit 1 and limit 2. They have a BIT2 datatype, size of 0.2 bytes, which means they have two bits, as shown in the following figure for Limit 1:
Bit0: Value smaller/equal Limit 1
Bit1: Value bigger/equal Limit 1
so there are some questions: what kind of datatype should I define to link this variable to it, and how can I access both of its bits.
Any help would be appreciated.





You can use the
BITdatatype in TwinCAT, but this is only available within a struct or a function block.You can for example define a STRUCT as follows (see also InfoSys):
It should be possible to link an instance of this struct to the variable.
Note that using BIT access can be a bit slower than using bit masks:
Toni Kucic did a speed comparison and found BIT access (13.5 ns) to be around a factor 5 slower than bit masks (2.8 ns). Full results:
BITdatatypes do have the advantage that they are much more memory efficient: