LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping two parallel while loops with a single boolean action

Solved!
Go to solution
Solution
Accepted by topic author fowlerd8

1. You can combine your voltage and temperature channels into a single task.  This will simplify your code.

2. Since you only want 1 sample based on whenever your loop gets around to it, set the timing type to Finite Samples with a size of 1.  This will eliminate the need for the DAQmx Start, DAQmx Stop, and unreserving the task.  You can just do the DAQmx Read when your loop iterates.

3. I am not even seeing a reason to break your loops up.  Combine them into a single loop and, again, things will be simpler.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 11 of 19
(1,672 Views)

Thank you so much, most of what you just said resolved many of my previous issues, and I did not know the most efficient way of solving them at the time.  For example, I was getting an error stating that a resource was already reserved for a certain task or something like that, so implementing the start, stop, and unreserve was my workaround.

 

Thanks!!

 

 

0 Kudos
Message 12 of 19
(1,667 Views)
Solution
Accepted by topic author fowlerd8

The Stop Button is deliberately defaulted to "Latch When Released".  Certain buttons, such as "Play", "Stop", "Start", etc. (the ones with rectangular Button icons, in general) are meant to act almost like Push buttons, i.e. they should always be "Ready to Push".  They are designed to work with the LabVIEW Event Structure and to handle "one-time" tasks. 

 

There are really three "timed actions" with a Latch When Released button.  Let's assume it is off.  Reading it returns, of course, False.  Now you push it (and hold it down) -- still nothing happens, the value is still False.  Now you let go, and the Value becomes True.  It remains True (i.e. "latches") until you read it, when it reverts to its Default Value (which happens to be False).  

 

So here's how you use them in an Event loop.  Create an Event for Stop, Value Changed, and put the Stop button inside the Event.  Now, when you push the Stop button, whenever LabVIEW gets around to handling the Event (probably almost immediately if you've coded the Event loop correctly), LabVIEW will Read the Stop (returning True), will reset the Stop (setting it back to False), and if you were to read it again (which you probably shouldn't do), it would say "False".

 

Write yourself a little VI to test this behavior -- it is quite instructive, and you'll remember how this Boolean Mechanical Action works.

 

Bob Schor

Message 13 of 19
(1,644 Views)

Thanks so much for your detailed response! I will get right to it 🙂

0 Kudos
Message 14 of 19
(1,642 Views)
Solution
Accepted by topic author fowlerd8

Why not use a local variable, very simple. Here are the examples for each method:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019LmXSAU

Message 15 of 19
(1,616 Views)

@LennartM wrote:

Why not use a local variable, very simple. Here are the examples for each method:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019LmXSAU


Local variable has been suggested, but requires switch action and has some side effects as mentioned. Personally, I prefer the solution using an event structure, and that one is not even mentioned in your link. 😄

0 Kudos
Message 16 of 19
(1,597 Views)

How do I combine my voltage and temperature channels into a single task if it's two different units?

0 Kudos
Message 17 of 19
(1,573 Views)

Is it okay to use the tag channel wire to stop the loops if the loops are running at different speeds or is there a better way to approach that?

 

Thanks,

Harsh

0 Kudos
Message 18 of 19
(1,556 Views)

Ah, that's a great idea.  The Tag Channel is perfect for this.  I posted a Snippet a few weeks ago where I stopped 5 loops (I think) with a single Stop button, and to stop 25, I would only have had to branch the Channel (which you can do with a Tag).

 

Bob "Channel Wire" Schor

Message 19 of 19
(1,547 Views)