LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Stalin@NSTL

Is it possile to Incorporate Boolean Toggle Function

Status: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.

Dear All,

 

The toggle bit function is very essential to toggle the flags set in the progam.

Right now we have to doit in inderect manner shown in attachement.

 

It will be very useful when we have a bit toggle boolean function. Not just inverting bit it has to toggle specified flag.

 

If it is already availble in any other form please let me know.

 

 

Regards,

Y.Stalin

14 Comments
altenbach
Knight of NI

>> shown in attachement.

 

You did not attach anything. Do you mean something like this?

Stalin@NSTL
Member

No did not mean that. I am talking about toggling a bit.

 

Like "if the bit is zero make it one else make it zero"

 

The above statement must be executed with signle function. See the below figure. It is actually inverting the present state of CaseFlag.

So that means i need to read the variable modify and store back. instead if canjust toogle caseflag i will be useful.

 

Hope you understand what i mean.

 

toggle.png

 

 

 

altenbach
Knight of NI

Why would you even need a control or indicator for any of this. Just keep the boolean in a shift register and invert if desired.

Stalin@NSTL
Member

It is not control or indicator, it is a local variable "CaseFlag" which is being used in another case structure.

 

It is update in one case structure and used in another case structure. Shift register is iteration dependent. But i am looking for

 

loop independent toggling of bit.

 

 

tst
Knight of NI Knight of NI
Knight of NI

The problem here is that LV is inherently parallel, so code which would be natural in other languages needs to be handled differently if you want to avoid race conditions (which I'm assuming is your problem).

 

In this case, you'll probably want to use a functional global, as that is exactly what they're good for - performing atomic operations on data. Your FG can have two simple actions - read bit X and toggle bit X.

 

See here for a long discussion on the topic - http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801#M240328

 

 

Another option (if you want to keep this local to the VI) is to use a data value reference, which would guarantee locking the data each time.


___________________
Try to take over the world!
AristosQueue (NI)
NI Employee (retired)

Tst has the correct solution. Here's a snippet of code that solves your problem. Just create a non-reentrant subVI that has this as its diagram:

ToggleBit.png

altenbach
Knight of NI

I guess with a globally initialized feedback node (instead of the shift register), we could eliminate (1) the "first call" primitive, (2) the first case statement, as well as (3) the for loop. Do you see any functional difference?

 

RavensFan
Knight of NI

Feeding the toggle control into an XOR function also toggles the boolean value thus eliminating the case structure.

 

(Christian, for some reason your image doesn't show.)

altenbach
Knight of NI

Ravens, while you were typing, I was composing this post... Great minds think alike! 😄

 

 

Stalin@NSTL
Member

None of your codes are simlifieng the function than what i have posted in my query.

 

Instead i can proceed with inverting data in local variable and store back in the same variable. That any way solved my

 

purpose. Which i can use in  any other case structure.

 

Ok any way thanks for your respomse.

 

 

Regards,

Stalin Yennaboina