LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop an event from passing from one frame to another with Flat Sequence

Hi! I'm new to LabVIEW and I'm trying to create a simple calculator, I'm using a flat sequence to get the first number with event structure and then get the second number also with event structure also.

 

So far I'm not able to choose the second number, because when i press the button to choose the first number, the event at the first frame gets triggered, and it also gets passed to the second frame, so the same event goes for the first and second number.

 

I'm wondering how is it possible to stop the event from passing between the frames automatically? and if there is a better way to do this?

 

I also tried it with while loop, but the event get passed the same way from one iteration to the another, so the same thing happens.

 

My VI is attached, thank you for your help!

0 Kudos
Message 1 of 10
(2,437 Views)

All you need is one toplevel loop and one event structure with several events.

 

(Your code makes no sense. Start with some simple tutorials. Learn about the basics of dataflow. Search the forum and examples for calculator to get some ideas.)

0 Kudos
Message 2 of 10
(2,423 Views)

When using event structures, I would recommend reading up on the caveats and recommendations.

 

https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/caveatsrecmndtnsevnts/

 

To explain at a high level what is happening in your VI the event isn't being "passed" into the second frame, the click is actually sending that event to both structures at the same time. Each event structure is configured to handle a set of events and when one of those events happens it ends up in that event structures queue. When it comes time for the event structure to execute, it looks at its queue and if there is an event that needs to be handled it goes ahead and executes that case. When you run your VI and click "1" LabVIEW basically sees that there are 2 observers waiting for that event and separately tells both of those observers that "1" has been clicked.

 

As mentioned, you could probably do this whole thing by putting the event structure in a while loop. You'll also want to look up shift registers for storing information between iterations.

Matt J | National Instruments | CLA
Message 3 of 10
(2,364 Views)

Hi altenbach! thank you for your answer.

you are right the code didn't make much sense, i have changed it and it kind of works correctly now with one while loop and one event structure, but i'm still learning how data flow works.

 

I looked up some calculator examples and they were very helpful.

0 Kudos
Message 4 of 10
(2,323 Views)

Thank you Jacomson for your detailed explanation, i wasn't sure how the events were being handled, but now it's much clearer.

 

I will take a look at the events caveats, and understand all the details.

0 Kudos
Message 5 of 10
(2,318 Views)

@salaryunis wrote:

Hi altenbach! thank you for your answer.

you are right the code didn't make much sense, i have changed it and it kind of works correctly now with one while loop and one event structure, but i'm still learning how data flow works.

 

I looked up some calculator examples and they were very helpful.


Good! It seems you are a fast learner. Fell free to ask more question or show us your "kinda works" efforts and we probably can speed up the learning curve even more with specific advice. Good luck!

0 Kudos
Message 6 of 10
(2,281 Views)

I have changed it a bit and now i got this VI. Now it works for individual numbers (1 digit) only, and simple math operations.

 

Any ideas on how to implement it for larger more digit numbers would be appreciated.

0 Kudos
Message 7 of 10
(2,224 Views)

Your VI is broken. Did you attach the right one?

0 Kudos
Message 8 of 10
(2,204 Views)

Hi altenbach, sorry it was the wrong VI.

0 Kudos
Message 9 of 10
(2,186 Views)

Quick glance:

  • All your buttons should be latch action (are you familiar with the mechanical action settings?). No need for any value property nodes.
  • To check even/odd just AND [i] with 1 and do a "=0" or "!=0" (Yes, there is an =0 primitive!)
  • doing that even/odd on [i] is probably wrong because things can get out of sync.
  • Index array is resizeable. You only need one instance to get both elements.
  • Replace array subset takes scalars at the bottom. No need to build array first.
  • Your song and dance with insert into array and selecting later could be done with a single "insert into array" and the select picking between 0 and 1.
  • You need to redesign your logic from scratch so entering digits appends to a string that you can parse for display.
  • All latch action buttons belong inside their event case so they reset when the event fires.
  • You can place all your buttons inside a (transparent) cluster and combine a lot of code.
  • ...

Have you looked at some of the calculator examples and discussions found in this forum?

0 Kudos
Message 10 of 10
(2,131 Views)