LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Button released programatically only in highlight mode

Solved!
Go to solution
Highlighted

Hello, I am trying to control two loops with one button. Given that you cannot use latching action with variable, I used switch with setting value back to false after loop ends. Everything works fine in highligh mode, but not when I try ti use it. I figured to it'll be faster to post it while I try to find the solution. Attaching testing VI.

(the indended fuction of program is to continuously read values from USB module and save them when button pressed, if you have suggestion to improve to code somehow I am open to it)

0 Kudos
Message 1 of 12
(311 Views)
Highlighted

This is a typical race condition: the local is reset to false before the lower loop reads it.

You should reset the local only after both loops are terminated.

A better choice is to use a latching button and manage the Value Change event also in the lower loop.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019
Message 2 of 12
(286 Views)
Highlighted

Well I need to run the other loop continuously, with event structrure it stucks and waits for event. Is there other way?

0 Kudos
Message 3 of 12
(280 Views)
Highlighted

Wire a constant >= 0 to the Timeout input of the event structure.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019
0 Kudos
Message 4 of 12
(273 Views)
Highlighted

Ok, but how then I get the value from stop button? Property node - value provides variant, not boolean, data type. Variable doesn't work with latching action. And this would this trigger event with every iteration wouldn't it?

0 Kudos
Message 5 of 12
(255 Views)
Highlighted
Solution
Accepted by topic author Vojtěch

teststop.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019
Message 6 of 12
(249 Views)
Highlighted

Ahh, ok I haven't realized I can fulfill any conditon from event structure to allow for next iteration. This works, thanks.

0 Kudos
Message 7 of 12
(246 Views)
Highlighted

Let's add a caution remark. You can manage the very same event in multiple event structures, but be careful: all structures must be "ready to react" when the event occurs. A typical mistake is to put one of them into a case (of a case structure) that will not be executed because the external condition does not match. This would hang the program (user interface would become unresponsive).

 

Another remark is the following: now that you learned how to use the Timeout case in an event structure, you may combine both loops into one, provided that your timing requirements are not too tight and the save operation is not too time consuming.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019
0 Kudos
Message 8 of 12
(238 Views)
Highlighted

Another option is to move the Stop button to the bottom loop as shown here. No need for a second event structure. Also, there's no need for that local variable in the bottom loop. Just wire directly to the terminal. I would probably also consider a different approach to saving the data point. You currently have a race condition and may not always be saving the point that you want to save. By the way is there a reason that you're making a waveform and then coercing it to a DBL? You have a lot of Rube-Goldberg in there. I understand that some of that may be the result of making an example that is not your real program, but wasn't sure what may be in your real program.

 

johntrich1971_0-1600343630827.png

Edited to Add: Once the stop button is made latching you can get rid of the write to local variable.

Message 9 of 12
(215 Views)
Highlighted

Connecting the loops via terminals resulted in unwanted dependency, so I solved it by using variables. The value doesn't change much in time (it is resistance dependent on temperature, you would set the temperature and wait for the resistance to become +/- stable). So you would just change temperature and hit save from time to time. That is why i want 1 quite current value to save with current temperature. If there is better way to convert waveform to single value I would like to hear it. I can attach "final" program now for you to explore.

0 Kudos
Message 10 of 12
(194 Views)