LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help convert this to a state machine

Solved!
Go to solution

Hi,

 

I feel a bit guilty posting this question because there is so much information on pausing.  I have taken over this vi and I'd like to add the ability to pause it.  I have created a sample vi that is a dumbed down version of the real one.  My vi has two procedures.  So i created a Start Test 1 and a Start Test 2 in this sample vi in order to ask my question.  The question is, how can I pause the vi.  The user may want to pause it, but they may want to pause it at an iteration of the loop.  I have two scenarios, one where the loop is in the event structure, and another where a vi with a loop in it are in the event structure.  I am not very experienced with using the code in the timeout event, but I see how to do that when there is only one test and no loop.  Here I have two and they both have loops,  so I'm not sure how to make this work in a nice state machine.  Any help would be appreciated.  Also, As it is now, I have a sequence in each event.  Frame 1 is used to change the control back to the "off" state.  However, how can you do this without have the sequence.

 

Thanks.

Download All
0 Kudos
Message 1 of 4
(2,651 Views)

You need to change your architecture. You do not want to tie up the event structure with long processes. The purpose of the event structure is to handle an event quickly, and proceed to handling the next event. Sometimes this requires coupling the event structure with another loop that performs the processing. The producer-consumer architecture is one such architecture. You should read over the KB article to see how this architecture works. This will allow you to handle a Pause event. You will need to have some way of monitoring for the pause in your loop. What dictates the presence of the loop and its number of iterations?

0 Kudos
Message 2 of 4
(2,634 Views)

Ok, your response was what I thought would come up.  I will have to look into how long it will take for me to convert this program to a better structure.  The way it is right now, there is basically two whole programs inside two event structures.  The loop in the program is actually controlled by the user.  They can select a number of frequencies to test and those frequencies can range from 1 to however many they want to do. One event is a calibration procedure and the other event is the testing.  So basically, there is an event for timeout, stop, calibration, and testing.  So I simplified the example so as not to expose the real code we are using.  Thanks for the reply.

0 Kudos
Message 3 of 4
(2,628 Views)
Solution
Accepted by hatemachine

Well, you can still do it using just the event structure, but it's not a very good way to do it. For one thing you would need to configure the event case to not lock the front panel so that you can still click on the Pause button while the test is running. As for the looping you would need to use a while loop instead of a for loop and use a shift register to keep track of which iteration you're doing. The iteration counter of the loop is irrelevant in this case. If the test is a subVI then you need to pass references of the front panel controls to the subVI.

 

See attached modification.

 

Again, this is NOT a recommended approach. I am merely showing it to you to see what's involved for your information/education.

Download All
Message 4 of 4
(2,611 Views)