10-24-2012 06:44 AM
Hey guys.
Let me start of by saying that I am self taught in LabVIEW, and just started. So the problems I'm having are properly simple.
Let me describe what I'm doing and then the problem I need help with. I am trying to automate a research setup that uses a series of valves, a massspectrometer and a potentiostat. I want a VI where I can press one button which causes the valves to open and close in a certain order, after which the massspec should perform an experiment, after the experiment the valves need to open close in a certain order again and return to an "idle state". Actually I want several of these buttons for different experiment.
Now for my problem: I've made a VI that does something along the lines of what I want using events and while loops. See attached for a simplified version. It uses an event structure with two buttons which each activate their own case structure. However, if I place the eventstructure outside the while loop, the event is always running. If I place the event inside (as in example) the while loop I have to press a for every step in the case structure. Notice that the "cases" in the case structure is identical in the example, but they won't be in my final version of the program. Finally the LED's indicate if the valve is open or closed. The array of LED, is there in place of a DAQ assistant.
I hope people can help me, please tell me if need to clarify.
Solved! Go to Solution.
10-24-2012 07:13 AM
Sounds like you want a Queued State Machine or the JKI State Machine.
10-24-2012 07:23 AM
Thank you! I will look through the links you've provided.
But the link for the "Queued state machine" does not work. Could you please repost?
10-24-2012 07:30 AM
10-24-2012 08:06 AM
Atamsih,
First of all, your code looks pretty nice as it is. It is clear what youe code does and what you intend to do. I am not sure what your question is exactly however, so I will try to answer what I think your problem may be and I hope this helps.
I think you need a state machine with an event handler (please see the attached code). I have called the main step "DAQ Process" because this is where I believe you want to be performing your main functionality of your program. By using local variables, I can make the booleans light up inside the process, with a bit of wait timing. Another good feature of the state machine, that I didn't put in, is to make all the enums Type Def. That way they all inherit from the same control so if you need to add another case you don't then need to edit every single enum in your code.
I really do hope this helps becasue I learned this stuff recently and have found nuggets like this very useful for LabVIEW programming.
Regards,
10-24-2012 08:14 AM - edited 10-24-2012 08:17 AM
Rob, there are a number of valid reasons to put the event structure inside a state machine, however when adding any hardware or processes which delay the user interface by more than about 200ms, then it should be split into a producer/consumer pattern. If the user wants to close the program or abort the sequence, they will have to wait for the whole thing to finish before anything else can happen.
Also using a producer/consumer would remove most if not all of the 28 local variables which should not really be necessary in a sequencing application
10-24-2012 08:21 AM
Ed,
I read your post after I had done mine . I agree - the QSM is a far better way of solving this.
10-24-2012 09:23 AM
@Rob_Ward wrote:
Ed,
I read your post after I had done mine . I agree - the QSM is a far better way of solving this.
Could you please post your code in an earlier version of LabVIEW?
10-24-2012 09:32 AM
Mark,
I saved it in versions 11 and 10, so I hope this works for you now.
Regards,
10-24-2012 10:05 AM
I agree with the others, take a look at the common state machine design patterns. I did want to say that in order to keep the loop running without someone pressing a button, you need to wire a constant to the timeout terminal. That is the blue connector on the upper left side of the event structure. Wire something like 50 (the value is in milliseconds). If that amount of time goes by without any other events in the structure firing then any code in the timeout case will be executed. Don't forget to wire your state enum through the timeout case.