Kaczi

How to take single bit form input WORD by Structured Text

5 posts in this topic

How to take single bit form input WORD by Structured Text? Can i write somethink like: inVar[i]   Edited by Kaczi

Share this post


Link to post
Share on other sites
Yes you can. You need to declare the inVar as an Array of BOOL. That way you can access each bit independently using the syntax you write above, but the problem is you cannot access inVar as a Word   You can, however, do a bitwise AND to check the certain bit condition of a Word Variable. Say you declare inVar as a single WORD (not an Array), you can use this kind of script to check :   IF (InVar AND 1) > 0 THEN       (*Check whether Bit 00 of InVar is ON*)        (*Do something*) ELSIF (InVar AND 2) > 0 THEN (*Check whether Bit 01 of InVar is ON*)        (*Do other thing*) ELSE        (*Do other thing*) END_IF

Share this post


Link to post
Share on other sites
Assuming InVar is your word, you should be able to use dot notation to get to any individual bit in the word. The 2nd bit is at InVar.2 10th bit is at  InVar.10 and so on....

Share this post


Link to post
Share on other sites
Hello, unfortunately you cannot do that in CX-Programmer, either in Ladder Editor or Structured Text.

Share this post


Link to post
Share on other sites
in that case use AND operation with suitable bit mask... something like   bitTestValue = (inVar AND Mask)>0   where Mask is same size as inVar but it only has one bit set, for example: bit 0:   Mask= 1 bit 1:   Mask= 2 bit 2:   Mask= 4 bit 3:   Mask= 8 bit 4:   Mask= 16  etc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now