取消
显示结果 
搜索替代 
您的意思是: 

Button released programatically only in highlight mode

已解决!
转到解答

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 项奖励
1 条消息(共 12 条)
3,448 次查看

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, 2021
2 条消息(共 12 条)
3,423 次查看

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

0 项奖励
3 条消息(共 12 条)
3,417 次查看

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

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 项奖励
4 条消息(共 12 条)
3,410 次查看

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 项奖励
5 条消息(共 12 条)
3,392 次查看
解答
已被主题作者 Vojtěch 接受

teststop.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
6 条消息(共 12 条)
3,386 次查看

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

0 项奖励
7 条消息(共 12 条)
3,383 次查看

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, 2021
0 项奖励
8 条消息(共 12 条)
3,375 次查看

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.

9 条消息(共 12 条)
3,352 次查看

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 项奖励
10 条消息(共 12 条)
3,331 次查看