LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local variable with Flat structure LabVIEW

ขอความช่วยเหลือ.jpgHi! I want to give A and B to be 1 when Boolean3 is true. How I should do it.

0 Kudos
Message 1 of 6
(2,669 Views)

You really need to learn to avoid using Local Variables so much.  They are causing all kinds of race conditions for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(2,644 Views)
Message 3 of 6
(2,637 Views)

While I cannot see your code (the image is too small, and your VI won't open on my machine), your Title says that you have not learned the First Principle of LabVIEW, "Data Flow".  I tell students to never use Frames ("Flat Structure") and to never use Local Variables (when they understand Data Flow a little better, I explain the rare exceptions to these General Principles).

 

Have you looked at the LabVIEW Tutorial material on the first page of this Forum?

 

Bob Schor

0 Kudos
Message 4 of 6
(2,618 Views)

It depends what the values of A and B should be when Boolean 3 is false. Should it be 0, or 0\1 depending on Boolean?

 

You can either use a second selector, or OR Boolean and Boolean 3. If Boolean or Boolean 3 is true, output is 1.

0 Kudos
Message 5 of 6
(2,615 Views)

@H.Nattapat wrote:

Hi! I want to give A and B to be 1 when Boolean3 is true. How I should do it.


Start with a few simple LabVIEW tutorials before continuing any further.

 

Let's look at what you currently have:

  • You have four independent code paths interacting with the same boolean in parallel. Since there is no way to know in what order things execute, A can be either 0 or 1, depending on the state of the boolean when the local variable was read. There are at least three random possibilities
  • The local variable is read first, so A will depend on the state of the boolean right before the run arrow was pressed.
  • Boolean 2 is read and written to the boolean right before reading the local variable. Now A will depend on the state of Boolean 2.
  • If boolean 3 is true and the TRUE constant is written to the boolean right before the local is read, A will be 1.
  • As you can see, there is no way to guarantee the output under all conditions, even if all control values are known from the beginning.
  • Same for B. You get whatever the value of A was when it's local variable was read and the value of B is not likely to resemble A in most cases.
  • You code has no while loop? Are you using "continuous run"? Don't!
  • I would also recommend to give all your controls descriptive labels. Naming everything "Boolean N" does not help documenting.
  • It is not a good idea to use long waits inside inner code (1.5 seconds is a very long wait!). Use a better state machine architecture.

 

0 Kudos
Message 6 of 6
(2,582 Views)