LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch until Released Buttons are not reset to 0 after release

Solved!
Go to solution

I am quite new to LabView and I have the following problem. I am using User Buttons Cluster which contains 3 Buttons: Accept, Jump, Repeat in "switch until released" action. Inside a case structure(True/False) I treat event Value Change for each button(treatment is different for True and False Cases). I have put the control User Buttons just outside of the case structure. Now when I click on the button the value changes from 0 to 1, the event executes but then the button is not reset to 0 value when released and it is not responding anymore on the next cycle of the state machine while loop. Here is the picture of the code under question as well as the code itself. What can I do to fix it?


I thought about changing buttons to latch when pressed and putting something inside the event cases to force LV to read the button value but I could not find anything that would allow me to force LV to read the value of the button(i can't use the button itself as it is a cluster+i need it in both True/False Cases). Maybe somebody has an ides how to do it?...
image.png

0 Kudos
Message 1 of 7
(5,206 Views)
  1. Never ever have more than 1 Event Structure in a VI!
  2. You have one Even Structure nested inside two Case structures (Inside "User approval" case ther eis a True/False Case, and there is the 2nd Event Structure)
  3. I strongly advice to rebuild your State Machine, this is not a proper way. Lots of possibilities to lock up the code plus race conditions...
  4. Have a look some examples how to make such State Machine. You should have a SINGLE Event structure inside the "Idle" case!
0 Kudos
Message 2 of 7
(5,204 Views)

Ok, thanks for advise. Suppose I do it: instead of user approval case I come back to 'Idle' and there wait for the event for user buttons. The question is still there: user buttons cluster will be outside the event structure and the same thing will happen: the value won't be read by LV after the event occurs as I can't put each button inside the corresponding event. Should I better not use the cluster?

0 Kudos
Message 3 of 7
(5,179 Views)
Solution
Accepted by topic author catherine_91

Your code is "inside-out" and completely constipated. Have exactly one event structure right inside the outer FOR loop and do a proper state machine.

You would also create a single event for the cluster and then see which one has changed to decide the further action.

The correct mechanical action is typically "latch when released". This guarantees that the state remains true until the code has a chance to read the new state and you only fire an event per user action. With "switch until released" (the typical car horn mode!), you can get several reads or no reads at all. You also get two events, one for the down and one for the up. Are you correctly handling the up events?

0 Kudos
Message 4 of 7
(5,173 Views)

"The question is still there: user buttons cluster will be outside the event structure and the same thing will happen:"

 

Always keep the controls (also your buttons cluster) in their corresponding Event Case! This will ensure that the button latches back.

0 Kudos
Message 5 of 7
(5,164 Views)

1)I won't agree with you abour FOR loop as my state machine should turn infinitely till the user preses QUIT.
2)The change I have described above will make this machine having only one event structure.
3) But thanks very much for answer about event on cluster: that is exactly what I was looking for! So I handle event: User Buttons(cluster) Value Change and inside I make a case structure with cases: Jump Button "OldVal!=New Val", Accept Button "OldVal!=New Val", Repeat Button "OldVal!=New Val" and inside I treat thoses cases? This is the right way to do it? Or I can directly connect "Source" of event to a case structure and treat all?

0 Kudos
Message 6 of 7
(5,163 Views)

I have found you old message which completely answer my question=)

Thanks very much!!

What I sometimes do is compare old and new from the event data node using "not equal", convert the resulting boolean cluster to a boolean array (cluster to array) and search for the single true element (search array). The resulting index (typically wired to a case structure) will give you the element position in cluster order.

0 Kudos
Message 7 of 7
(5,150 Views)