LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run case once then hold

Hello,

I have a case structure (cases 0-3) which is controlled via two boolean switches. If the case is "0" I need to execute that case once, then move to case "3" until a change of case occurs, that is, "1" or "2" are chosen. I can't find a logical way to do this. Could you please have a look at my example code?

Thanks,
dewey
0 Kudos
Message 1 of 9
(3,078 Views)
Have a look at the event structure, seems more suitable for this. (see attached, LabVIEW 8.0)
 
Right now, the "do nothing" case executes every second. Possibly, you can omit this case and just wait and really do nothing. 😉
0 Kudos
Message 2 of 9
(3,076 Views)
Thanks for the help altenbach.

I gave the event structure a try with your suggestion, but I can't get it to behave the way I want. I forgot to put some local variables in the original file so I attached an updated file. Mainly the booleans work in an either/or configuration. I like your suggestion about really "doing nothing". It would be great if I could get the logic to work so that I execute the "reset valves" case only once, then sit and "do nothing" until the both booleans are set to FALSE again. Then the case would execute once again and so on.

I would very much appreciate another attempt with this one.

Thank you,
-dewey


0 Kudos
Message 3 of 9
(3,063 Views)
OK, You might as well use a radio-button control for the two booleans, this way you don't need to use that many locals. There is also now nothing going on if idle.
 
See if this suits your purpose. 🙂
 
0 Kudos
Message 4 of 9
(3,057 Views)
Thanks again.

Using this event structure method, I can flip valves on and off just as I want. Then when both booleans are FALSE I want to execute the code in the "Timeout" ONE TIME. As I described earlier, after switching valves on and off for whatever reason and in the case all valves off I need to execute the "Timeout" code once (which will operate a separate main valve), then sit and wait for the booleans to change.I see at startup, the code sits in "Timeout". How can I get it to sit in "Timeout" and execute that code ONCE again until boolean values change?

Thanks,
-dewey
0 Kudos
Message 5 of 9
(3,040 Views)
You could just manipulate the timeout values via the shift register.
  • Set the timeout inside the timeout case to -1, basically disabling the timeout once it has been called.
  • Set the timeout to zero whenever both booleans are false, otherwise set it ot -1.
  • mix and match to suit your needs. 😉
Message 6 of 9
(3,030 Views)
Hi altenbach,

I really wish I could get your nice event structure to work for me. At least I am learning about them and I am trying to implement it into my code. I have posted my working code to help describe my problem. I have one main loop. The two top case structures are the ones I am concerned about. When the booleans are both FALSE,  I only want case "0" to run once. Case "0" won't run again until the booleans change and are again both set to FALSE. If selected, I need cases "1" or "2" to run every 1000ms with the main loop because "1" runs PID controls and "2" needs to update if the flow setting is changed. I couldn't get cases "1" and "2" to run like that with the event structure. In addition, I read about the caveats of event structures and I will need to have more than one structure in the main loop. That is, the structure below the top case structure needs to operate similarly.

I thought I could do it with with a simple shift register comparison, but I like the event structure programming and can see more uses for it in my code.

Thank you very much for your patience and help.

Yours,
-dewey
0 Kudos
Message 7 of 9
(3,022 Views)
Dewey,

You might look into state machine architectures. They would allow the elimnation of local variables and provide a much more versatile and robust method of handling your logic and timing conditions. It wold also make it much easier to change the logic in the future if that should ever become necessary (typically after you get it working and then move on to something else so that you have forgotten exactly hwy you did things the way they were done!).

Several examples and many posts to the Forums describe this architecture in its many variations.

Lynn
Message 8 of 9
(3,019 Views)
Hi Lynn,

Thank you for your suggestion. I have been reading about the state machine designs in Labview. I think I will be able to use your suggestion along with what I learned with altenbach's help to solve my problem. Maybe I will be posting a state machine problem soon:)

Yours,
dewey
0 Kudos
Message 9 of 9
(2,996 Views)