Hi
I am looking into code to set a block of 8 booleans within a datablock, depending on the condition of 8 'flags'. The start bit of the 8 bools can vary, and the flags will be determined earlier within this block so will be temp variables.
The DB is basically a long list of bools
So, if flag1 is on, set the first bit of the db which should be the same bit as in iStartbit (example, bit12 of the db)
Does this look suitable? I am unable to test for several weeks
Cheers
I am looking into code to set a block of 8 booleans within a datablock, depending on the condition of 8 'flags'. The start bit of the 8 bools can vary, and the flags will be determined earlier within this block so will be temp variables.
The DB is basically a long list of bools
So, if flag1 is on, set the first bit of the db which should be the same bit as in iStartbit (example, bit12 of the db)
Does this look suitable? I am unable to test for several weeks
Cheers
Code:
FUNCTION FC 111 : VOID
TITLE =
VERSION : 0.1
VAR_INPUT
DataBlockA : BLOCK_DB ;
iStartBit : INT ; //0=bit0 ,1=bit, 8=bit 8 etc.
END_VAR
VAR_OUTPUT
END_VAR
VAR_TEMP
flag1 :BOOL ; //flag1-8 needed
iLoopCount : INT ;
END_VAR
BEGIN
NETWORK
TITLE
//// decide status of flags 1..8
NETWORK
TITLE =Open DB and setup bit 1 position to the pointer
OPN #DataBlockA;
L #iStartBit;
LAR1 ;
TITLE =
L #flag1
= DBX [AR1,P#0.0]
L #flag2
= DBX [AR1,P#0.1]
L #flag3
= DBX [AR1,P#0.2]
L #flag4
= DBX [AR1,P#0.3]
L #flag5
= DBX [AR1,P#0.4]
L #flag6
= DBX [AR1,P#0.5]
L #flag7
= DBX [AR1,P#0.6]
L #flag8
= DBX [AR1,P#0.7]
END_FUNCTION