From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure to switch on and off one LED

Solved!
Go to solution

Good afternoon, 

 

I would like to activate one part of my algorithm depending on the value located in another part. To make easier I symbolize the value by a button and tried to used an user event structure to switch on or switch off a LED located in another while loop.

I can switch on the LED but unfortunately I can not switch off the LED afterward. 

it's possible to edit the event structure and select the option "value change". However I would like the fatest way to switch on and off using the event structure and array. I mean that I would like to activate one part of the algorithm only if the button is switched not to have a continue check of the button value by the event structure.

  

Please, if someone has any idea to switch off the LED (after the switch on), add a comment without any hesitation.

I will be so glad to solve this simple problem.

Thank you in advance for your help.

Ragards

0 Kudos
Message 1 of 9
(4,786 Views)

If you look at what your code is doing in the bottom loop:

 

 

REPEAT

   if BOOLEAN 2 is

   TRUE:  GENERATE USER EVENT

    FALSE:  DO NOTHING.

until STOP 2

 

It should be obvious.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 9
(4,771 Views)

Note that your bottom loop is sending 320,000 events per second (on my machine) to the upper loop.

 

Is that really what you want to do?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 9
(4,765 Views)

i don't think that is what required.

 

The Bottom loop is greedy and it required a wait function. Also the button must to kept to "Latch when released" as a mechanical action so that when the button is pressed an Event is fired. 

-----

The best solution is the one you find it by yourself
Message 4 of 9
(4,760 Views)

You can't switch the LED off because you are not sending an event with a false anywhere.  You are just sending the TRUE.

 

You also really need some kind of wait in your second loop.

 

You mention an array, but I don't see any arrays in your code.  Maybe you over simplified your example.  What exactly are you trying to do?


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 5 of 9
(4,748 Views)

Many thanks for all the comments.

Of course this exemple is drastically simplified.  In the complete version, the while loop at the bottom takes about 50ms for one iteration. At some occasion an event is created, that is why I created a button (yes/no) to illustrate this function.

Before that I have posted the first message I tried to add a "generate user event" in the false condition but the delay time between the switch and effect is very high (about 1or 2 sec). 

I will try to use a wait function in the bottom loop to limit the calculation. 

Thank you again for your help.

 

0 Kudos
Message 6 of 9
(4,715 Views)

I just try to add a condition for the false case and a timer.

Now it work fine but when I stopped the following message appear.

"An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @."

I do not understand why such kind of message appear because i dont use strange letter.

Do you haesome idea to porperly stop the algorithm?

Thank you in advance

 

 

 

 

0 Kudos
Message 7 of 9
(4,708 Views)
Solution
Accepted by topic author matriax

You have a race condition.

 

When you hit stop, it is a race as to whether the event gets unregistered and destroyed by the ending of the upper while loop vs. the sending of the user even in the lower loop.

 

Why it only seems to happen with the false case must be some quirk of the way the code is compiled and the order it is executed.

 

If you put a Not between your Boolean switch and the LED, for me anyway, the error is now generated on the True case of the case structure (still the False value for the switch.).

 

If you put an error constant in the lower while loop and wire that to the Unregister event so that you are now guarantee it doesn't execute until both while loops are stopped, then I don't see an error no matter what the value of the boolean switch is when you hit stop.

Message 8 of 9
(4,696 Views)

Thank very much, the problem is solved

0 Kudos
Message 9 of 9
(4,685 Views)