11-25-2010 08:35 AM
Hey,
The program I'm trying to create is a very linear one and involves performing three different processes after one another, each for a set amount of time.
I originally tried using case statements and timers to do this, but everything got very messy very quickly. I then looked at sequence structures however have read some bad things about them.
Could anyone point me in the best direction to achive this?
Thanks,
Sam.
11-25-2010 09:01 AM - edited 11-25-2010 09:09 AM
For example I would use this to collect a sample every second from a certain place for the first three seconds and then somewhere else after that.
However, before any of this begins I want to check/wait for a certain condition to become true. Once it is true however I dont care about whether or not that condition goes back to false, I just want to perform this section of my program.
11-25-2010 10:06 AM
For the 2nd wait you mention it's easy to place another loop which check for that condition before this one, then wire them together with any sort of wire as to make certain which one is performed first.
If the condition you wait for is some button press it's even better, then you can place an event structure without(!) loop around which waits for the event, in the same manner.
The loop you posted with a case looks quite alright, that's how programs will look. 🙂
/Y
11-25-2010 10:11 AM
"then wire them together with any sort of wire as to make certain which one is performed first."
How do I go about doing this?
Basically before this part of the program executes I want to check that the current temperature is stable, i.e. read it in and use a shift register to check that it is currently staying the same. If it is stable, then go on and do the test.
11-25-2010 04:20 PM
11-26-2010 06:14 AM
@Sam_R wrote:
"then wire them together with any sort of wire as to make certain which one is performed first."
How do I go about doing this?
Basically before this part of the program executes I want to check that the current temperature is stable, i.e. read it in and use a shift register to check that it is currently staying the same. If it is stable, then go on and do the test.
If you use a shift register i'd simply wire the Shift register out to the next loop, thus it'll wait for the first one to finish. Steves suggestion of a state machine is good, but if the application is as simple as you make it sound there's really no big use.
The application sounds very linear, so just wire the 2 loops together, and if you think the diagram get abit big, make a Sub-vi of each loop instead. That's generally a good idea as you then can wire through the Error wires which is good practice.
/Y
12-03-2010 06:05 AM
Hi Sam,
a State machine would be a perfect architecture for you to use.
Go to:
File-->New-->and a dialogue box should appear.
From the tree menu on the left go to -->VI-->From Template-->Frame Works-->Design Patterns--> Standard State Machine.
This example will have comments within it explaining how a state machine works, and how to program it, but if you need any help just post back!
Rich.
12-03-2010 09:13 AM
Sam_R, Yamaeda is right. Sometimes things are so simple that you do not need a state machine. But sometimes you end up adding features to your simple little program and it ends up growing out of control. Trust me
There are a million examples of state machines out there. This makes a million and one. It does not address the part of your question about performing an action for a certain amount of time. I wanted to keep it as simple as possible while also demonstrating programmatically determining the next state and error handling.
I don't mean to sound condescending with this basic example. But I know there was a time when it seemed like advanced stuff to me. Hopefully someone will find this useful.
12-07-2010 03:33 AM
Hey Sam,
I've adjusted the sample code a little for you, it contains a timing VI within it, thus the code in that state will run for Xms.
You should be able to adjust this as needed.
Regards