06-23-2017 08:52 AM
Dear Friends,
I have flat sequence with more than 10 frames, in frame 4 I have a camera and should wait there until user change the focus and then capture picture and continues.
I am thinking how can I make pause in one frame?
I made very simple VI which explain what exactly I mean and my first solution, as you can see in my VI I used while loop which continues running until user press stop button. I believe this is not the best idea while I don't like to put whole my sub vi which is also too big and complicated in while loop.
Please let me know if you have any other suggestion?
Best regards
Arvin
Solved! Go to Solution.
06-23-2017 08:59 AM
Hi Arvin,
Either a while loop or an event structure with a large timeout would be able to accomplish your goal here. You can also use the Wait VI within your while loop to control the speed at which you poll the stop button and avoid hogging the processor.
Check out these options for timing your VI's.
Duncan W.
06-23-2017 09:23 AM
There is rarely a need for a Flat Sequence in LabVIEW. Many times, using the Error Line to "sequence" functions is all you need. This doesn't apply in your case, as you are only using numeric functions. But notice what you are doing -- five "things" in sequence. One way to do this is to say "I want to do 5 things in sequence, so I'll use a For loop with a count of 5, inside it I will put a Case Statement that looks at the For's Index (i) that goes from 0 to 4, and in each Case, I'll do what I need". If you do this, and if you recognize that the variables Numeric, Numeric2, and Numeric3 can be better reproduced as wires connected to a Shift Register (eliminating the troubling Local Variables, eliminating the unneeded Numeric and Numeric2 Controls that are never used as Front Panel objects, and relegating Numeric3 to simply "indicate" the changing value of the Numeric3 "wire-variable"), you'll have a much simpler, easier-to-expand, framework.
Case 3, the Wait, can now be a little While loop (I'd put a Wait-for-100 msec function inside so your CPU isn't "counting nothing as fast as it can"). I'd name the "Stop" control "Continue", and change the name on the button, as well.
I've attached my suggested revision. I would save it as a Snippet, but it would be in LabVIEW 2016, and you're running 2015. This should be 2015 (unless I made a mistake in saving it) ... (note I kept the name, but it should not be a Flat Sequence now, but a Case-within-a-For Loop).
Bob Schor
06-23-2017 09:44 AM
I understand Sequence structures need to be kept around for backwards compatibility but I would like to see NI deprecate the flat (and stacked) sequence and bury it deep in the menu structure so new programmers do not see it or use it.
06-23-2017 10:06 AM
Thanks for your reply, I have also these problem which my processor is hopping. what do you mean avoiding that by larger time out?
06-23-2017 10:12 AM - edited 06-23-2017 10:12 AM
@RTSLVU wrote:
I understand Sequence structures need to be kept around for backwards compatibility but I would like to see NI deprecate the flat (and stacked) sequence and bury it deep in the menu structure so new programmers do not see it or use it.
But I hear they're great for documentation 😉
06-23-2017 10:29 AM
@cbutcher wrote:
@RTSLVU wrote:
I understand Sequence structures need to be kept around for backwards compatibility but I would like to see NI deprecate the flat (and stacked) sequence and bury it deep in the menu structure so new programmers do not see it or use it.
But I hear they're great for documentation 😉
And new icons.
06-23-2017 11:17 AM
My first though when I read "flat sequence with more than 10 frames" was "you need to change to a State Machine. The beauty of a state machine is you can reuse your steps and you can abort the sequence.
As far as your waiting for the user, just use a 1 Button Dialog instructing the user what to do. When they hit the OK button, you just move on. No extra loops or even structures. Just a single function call.
06-23-2017 11:24 AM
I would highly recommend you implement a state machine. It may work for now to just cycle through a for loop, but I think later when you try to add features to your program, you could have problems. For example, what if the user wants to stop the program completely instead of continuing? It will be difficult to add if you just have a while loop spinning and waiting only for the continue button.
Here is how I would modify your code to work as a state machine. Notice, how I've added the ability for it to stop at any time if the user closes the VI.
This uses an event structure, which I highly recommend. I think it makes it very flexible in that you can respond to any event easily by changing your state.
If for some reason you don't want to use an event structure, you could do it with polling as well, like this, but I don't think it's as flexible. It does at least give you the ability to stop midway through though.
--Hope