04-04-2011 11:17 PM
Hello, I'm making a program to run a chamber, and I am running in to some trouble. I have 5 while loops that are supposed to be running in the main VI connected by queues. The first is checking the front panel for events. That drives the next two which are responsible for either issuing commands to run the chamber, or issuing commands to check data gathered. The fourth is running the chamber, and issuing commands to write the data gathered. The writing takes place in the last while loop. After all of the loops fire the first time, it seems like only the first and last still execute. Could someone take a look and tell me where I went wrong? I'm still very new to labview, so I'm sure it's some little error or another.
Thanks,
Simon
Solved! Go to Solution.
04-05-2011 01:32 AM
Loop 2-4 wont execute unless there's a new queue item queued up. There's no timeout on the 'Wait for queue' (timeout in ms).
Else the code looks very nice but i can add a couple of tips: There's no reason to wire an erorr (or other wire) both to the case '?' and as a separate wire for internal use, you can continue the wire from the '?'. On the same not i'd personally split the error wire inside the cases to keep it cleaner outside, but that's personal preferrence.
Since you already have an Exit case i'd wire True out from that to Stop Loop but i agree your version is very clear.
In the Chamber loop the sequence can easily be removed.
Very neat code.
/Y
04-05-2011 06:39 AM
Thanks for the tip about the "?" in the case. I wired the timeout cases of the preview and dequeue elements so that they wouldn't stop loop execution, but I still can't get 2-4 to execute. I need them to loop so they can provide commands to the chamber, even when there isn't an element in the queue. The queues should just control what they do while looping. Am I missing something?
Because I forgot to mention it earlier, we are talking about the "Main.vi"
Thanks,
Simon
04-05-2011 10:34 AM
So I've been looking at timed loops, would I be better off using these?
Thanks,
Simon
04-05-2011 10:49 AM
One possibility. Don't use shift registers for the error wires. I know there are some people who claim that errors should have shift registers, but it is a bad idea and would cause problems unless you have a special method to handle errors. Why? Suppose you have an occasional error. Something as simple as a timeout error during serial communication. The error goes out on the wire and hits the shift register. That puts the error at the beginning of the next loop iteration. That error would prevent any code in the next loop iteration from executing because most functions are designed to not execute if there is an incoming error. So one error winds up killing your LabVIEW execution from now until forever until you either stop your program, or do something special in it to handle and clear the error.
I don't think timed while loops will give you any better advantages than regular while loops for you application.
04-05-2011 10:55 AM
Thanks, I didn't even think about shifting the error values.
Do you have any idea why some of the loops aren't executing?
Regards,
Simon
04-05-2011 11:07 AM
That was my idea. That the loops were actually executing, but you get an error. And in your error case, you have a True wired to the stop terminal.
So:
1. You get an error.
2. It gets placed in the shift register.
3. Loop iterates, there is an error in the shift register.
4. The error case runs.
5. A True value is fed to the stop terminal thus stopping the loop.
04-05-2011 12:52 PM
What I would probably do is to place an indicator on the while loop i terminal or a probe if it is wired to something. I wish that the i terminal could be directly probed even without a wire connected to it. I think I saw something about that on the idea exchange.
04-05-2011 01:51 PM
I think that I found my problem. I needed to add another identical queue element to the loop if I wanted it to stay in that state. I'm still working through it, but I fixed a couple of loops so far. Thanks for the advice everyone.
Regards,
Simon
04-05-2011 02:09 PM
As you noticed yourself, a queue isn't a fixed state but a queue of commands. As you Dequeue an item it'll disappear. 🙂
/Y