LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Global variables between parallel loops

Hi all,

I am trying to get a process in three parallel loops to only execute if a global variable ("pump in use") is not true (only 1 loop gets to use the resource, the other two have to wait). I start process 1, but I do not want process 2 or 3 to run until I stop process 1 and make the variable false. In my example, I start process 1, then 2.  P2  starts running.  Starting P3 runs P3, even though P1 has never been stopped.  I'm sure its easy but I am not seeing it.

ploop vars.jpg

0 Kudos
Message 1 of 8
(1,574 Views)

Process 2 or 3 reset the global to False, so the next attempt will be free to run ...

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 8
(1,573 Views)

If you want us to look at your attached code, you also need to include the global variable (currently missing!)

 

From the code it looks like you are a beginner and right now is a really good time to forget all bad habits and learn the right way to do things.

 

  • If only one process should run at any given time, why are there three loops??? One would be sufficient!
  • Thinks "state machine"! One state for each process.
  • There is a +1 primitive.
  • There should be no orange if these are integers.
  • Ping-ponging value via value property nodes is extremely ugly and inefficient. These values belong in a shift register.
  • Maybe you could place your three switches into a radio button control?

 

0 Kudos
Message 3 of 8
(1,543 Views)

See if this can give you some ideas....

 

altenbach_0-1681231396134.png

 

0 Kudos
Message 4 of 8
(1,535 Views)

Thank you for your reply.

 

This is sample code to illustrate my issue. I have simplified my issue to show only that  which is causing me a problem.  In reality, these are three large independent loops running multiple processes at once.  Each station happens to share a common pump, which is why I need to let P1 finish with the pump before P2 tries to use it.

 

Thanks for your critique on my programming, do you have a suggestion that would allow me to inhibit P2 & P3 while P1 is running?

0 Kudos
Message 5 of 8
(1,508 Views)

You have attached a global (P1 in use) that has nothing to do with your original post.

 

All you might need is a single global variable (or maybe an action engine) that is an integer (instead of a boolean) and indicates which process uses the pump (and "-1" for nobody). Each process can check if the pump is free, grab it by writing its process to it, and set it to -1 when it is done.

 

We don't really have sufficient details to give more specific advice. What exactly is a process doing if the pump is not available? Wait for the pump? Some other tasks that don't require the pump?

0 Kudos
Message 6 of 8
(1,489 Views)

Thanks for the reply.

I have a tank based chemical dosing system that has three tanks.  I have three pumps and three chemicals (and multiple routing valves).  Each tank has to run its 5 steps in order, moving from one chemical or step to the next. (I am using a state machine for this).  As an example, Tank 1 step 1 is to open some valves which route chemical 1 to tank 1, and start pump 1.  All three systems have to be able to run at the same time but if Tank 1 is using pump 1, Tank 2 cannot start pump 1 until Tank 1 is done with it. So after they start T1, then T2, I need to keep T2 in it's while loop until the pump becomes available, hence the sample code with three while loops,  constantly looking for some permissive to end the loop and start running. 

 

I like the idea of the integer variable.  So I would write a "2" to the variable if #2 grabs the pump, and "0" when it releases it?  And the others would look for "0"  to trigger use?  What if 1 is running, 2 and 3 are triggered, each waiting for their loop to end?  One should grab it before the other?  That's what I was hoping the Global booleans would do, but they don't.

Thanks again for the help.  Yes, I am fairly new.

p3tanks.jpg

0 Kudos
Message 7 of 8
(1,482 Views)

@Gort000 wrote:

One should grab it before the other?  That's what I was hoping the Global booleans would do, but they don't.


That simply needs a conflict resolution, completely independent of the implementation.

 

Assuming more than one process is waiting for a resource, should they get served...

 

  • In numerical order?
  • Whoever wanted it first?

Once you know how it should be resolved, just program it! Right? That's why an action engine would be more functional than a dumb global. It could keep an array of reservations and release them to a certain process only if no lower numbered process is also waiting.

 

 

0 Kudos
Message 8 of 8
(1,478 Views)