07-30-2009 10:03 AM
Hi everyone, and sorry for what I think may be a very newbie question, but I just cannot figure out how to use the event structure in my program.
The layout is this:
I'm using labview to control some devices in my lab. I have to turn something on for thirty minutes, then heat it up for another thirty miunutes (the first device is DAQ controlled and the second is GPIB controlled). While these two processes occur, I have to monitor a temperature using the DAQ card. After the two step process is done, I have to wait for the temperature to be below a certain point, and then start the whole thing over again. Then I have to repeat this process for a set number of times defined by the user.
My question is this, I'm using an event structure to handle all this (this may not be the best way to do this, If any of you know of a better way, feel free to share!). When the program starts the whole process, I want to be able to stop it at any point in case something goes wrong, and I would like to do that using a boolean on the front panel because I will eventually be controlling the process remotely. Is there any way to override an event case once its started? Presumably I will have a "Wait(ms)" VI in there somewhere to facilitate the timing of the processes, but once the VI starts the program waits until it is done before registering any other button-presses.
Thanks in advance for any replies,
-daman
Solved! Go to Solution.
07-30-2009 10:22 AM
The event structure should remain free to respond to events. Code in the event cases should execute quickly to allow another event to be handled. For timing control, consider using the Timeout event case. You can store the start time of a process using a shift register and then subtract it from the current time to get the elapsed time. You can then compare the elapsed time with the specified time for that step in the process and make a decision on what to do next.
While it is possible to architect a complete application with an event structure inside a while loop, it is easier and much more flexible to use a state machine approach.
See the reference design documented here for more information.
Dan Press
Certified LabVIEW Architect
07-30-2009 10:30 AM
Hi, thanks very much for the reply, but might you elaborate on the state machine approach?
I have heard of it, but the explanation in my LabView book is not good (its only mentioned very briefly as an aside) and I've never actually used one in a program before.
Thanks,
-daman
07-30-2009 10:43 AM
You should definately read up on State Machines!
Perhaps that link in my previous post is not working. Try these.
Reference Design - http://zone.ni.com/devzone/cda/epd/p/id/6091
State Machines - http://zone.ni.com/devzone/cda/tut/p/id/3024
ExpressionFlow Blog about QSMs - http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/
JKI State Machine - http://jkisoft.com/state-machine/
07-30-2009 12:10 PM
Thanks! This looks like what I need,
-daman
07-30-2009 04:14 PM
So I've been working for a while trying to figure this out and this is what I have so far.
What I want the program to do is:
1. Initialize
2. Wait for something to happen
3. When someone presses go, the machine I'm using should turn on (this hasn't been implimented yet, but its fairly easy to do)
4. After a predetermined time, turn off the machine, and turn on another (the second process is called annealing)
5. After another set amount of time, turn it off, and wait until a third device reads a certain value (this will be the temperature and we're just wiating for the whole machine to cool down)
6. Repeat again, until you have done it the requested number of times
7. Turn everything off
Also of note: the user should be able to abort the entire program by pressing a button on the front panel at any time during operation
If anyone could make any sense of my program, it would be greatly appreciated, it keeps getting more and more confusing, and I'm out of ideas!
Thanks very much,
-daman
07-30-2009 09:46 PM
I glanced over it quickly and saw a couple early problems.
Your enum constants are not consistent. Some instances have the value Quit. Other instances have the value Exit. The values and names are not always consistent. Thus you wind up with lots of coercion dots on that wire and your case structure winds up using numbers rather than the meaningful names.
IMPORTANT RECOMMENDATION: When using enums, create it as a TYPEDEF enum and always use that saved control.
Take one instance of your enum constant. Add all the case you can think of right now. Turn it into a control. Customize the control and make it a typedef. Save the control. Now go and find all your other enum constants and replace it with a copy of the typedef'd constant. Once you do that for all of them, the coercion dots will go away and your case structure labels will be meaningful. Now if you later need to add another state to your enum, you edit the saved typedef control and all instances of your constants will be updated accordingly. This will also prevent serious bugs if you are trying to execute a state as #3, but other constants have it has something else because you missed adding a state to all of the enum constants.
Don't compare your wire with Quit (or Exit). Use the case structure. Let the Quit/Exit case write a True out the tunnel to the stop terminal. All other cases can use a False or the default value of the tunnel.
You don't need to cascade multiple And functions. On the numeric pallette is a compound arithmetic function. You can change the mode of it to And. You can stretch it downwards and upwards to create 3 or even more input terminals. So 3 inputs can be And'ed with a single function rather needing 2 input And functions. Also, cool is that if you need to do a Not on one particular input, or on the output, you can right click the input or output terminal and select Invert. This will allow you to do some more complicated boolean arthimetic all in one function.
07-31-2009 11:02 AM
Thank you VERY much for the help, I think I've done it now. All the logic is there and appears to be working, I just need to add the guts now.
Again, thanks to both of you, great responses on this forum!
-daman