LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two Producers and One consumer

I am using two producer loops, one consumer loop, and one queue, identifying the two different streams of data using the ID in the cluster (array paired with an enum variable).

 

The first producer loop (a lock-in amplifier) collects the voltage data based on a train of TTL triggers sent out from my DAQ (USB-6229). The data is transferred via USB.

 

The second producer loop generates the TTL signals that are being sent out while also collecting from two analog inputs (two from a photo-diode).

 

The consumer takes the lock-in and photo-diode data and plots them on their separate plots.

 

My problem is that when I press stop the second loop does not run, leaving the first loop hanging at the lock-in amplifier subVI (LIA MFLI DAQ RUN). Is it as simple as just changing where my stop button is? Or is there another way to ensure that, when I press stop, the second loop runs to ensure the triggers cause the lock-in amplifier subVI to finish data collection (before everything stops)?

 

Alisterio_1-1616054732663.png

 

Please ignore the event structure - I have been trying with no luck trying to get a condition for the second loop to trigger once the first loop begins. And I highly apologize for my spaghetti code .... if it is more confusing to look at it hopefully what I have said is enough.

Alisterio_0-1616054444390.png

 

0 Kudos
Message 1 of 10
(1,668 Views)

Hi Alisterio,

 


@Alisterio wrote:

My problem is that


My problem is I don't understand your code from just looking at your images…

 

Don't you think it would be a good idea to cleanup your code before posting such images?

Don't you think it would be a good idea to cleanup your code to enable you und us to understand that code and to search for problems?

Don't you think it would be a good idea to attach real code instead of images (after cleaning up!) to allow us to analyze/edit/debug your code?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(1,659 Views)

Hi Alisterio,

 

I'd suggest that a more common choice here is to have a "User Interface" loop (with the Event Structure, and all of the controls) and then have that drive the rest of your application.

Send messages to the other loops, which can then be variations on the theme of State Machines or "Queued Message Handlers", etc.

 

It's not obvious from the screenshot shown why your second loop doesn't run, but since it contains an Event Structure, each iteration requires the triggering of a single event. Perhaps you aren't triggering any Events that are registered to the Event Structure, so it hangs?

 

Where is the "Send out triggers" button being clicked/actuated? I have a moderate fear that the answer is via Value Signalling property node in the first loop?


GCentral
0 Kudos
Message 3 of 10
(1,621 Views)

@Alisterio wrote:

And I highly apologize for my spaghetti code .... if it is more confusing to look at it hopefully what I have said is enough.


If you keep spaghetti for a while, bugs will appear...

 

As the spaghetti hides the problem, the spaghetti is the problem.

 

Fix that, and finding the problem will become a lot easier.

Message 4 of 10
(1,613 Views)

@Alisterio wrote:

My problem is that when I press stop the second loop does not run, leaving the first loop hanging at the lock-in amplifier subVI (LIA MFLI DAQ RUN). Is it as simple as just changing where my stop button is? Or is there another way to ensure that, when I press stop, the second loop runs to ensure the triggers cause the lock-in amplifier subVI to finish data collection (before everything stops)?


If they are that dependent on each other, maybe they should be in the same loop.  Furthermore, your error condition doesn't make sense to me.  The top loop has to stop before the other two can stop from the queue error.


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
0 Kudos
Message 5 of 10
(1,602 Views)

Hi Alisterio,

 

I would suggest you make use of some really good architectures. for example Delacor DQMH. It's free and available on VIPM. It uses NI QMH basically and on top of that, they have made really good use additional functionalited to address common scenarios to handle multiple loops/device handling etc etc

 

Also, it will help you to keep the application design consistent and maintainable. Delacor Forum 

I hope it helps.

0 Kudos
Message 6 of 10
(1,598 Views)

wiebe@CARYA wrote:

@Alisterio wrote:

And I highly apologize for my spaghetti code .... if it is more confusing to look at it hopefully what I have said is enough.


If you keep spaghetti for a while, bugs will appear...

 

As the spaghetti hides the problem, the spaghetti is the problem.

 

Fix that, and finding the problem will become a lot easier.


It's a lot like cleaning your room.  If you keep on top of it, it's not a problem.  Let it get out of hand, and it becomes a major chore.  Straighten up your code as you go, and you'd be surprised at how easy it is to do.  Don't be an Oscar Madison.  Be a Felix Unger.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 10
(1,585 Views)

@billko wrote:

wiebe@CARYA wrote:

@Alisterio wrote:

And I highly apologize for my spaghetti code .... if it is more confusing to look at it hopefully what I have said is enough.


If you keep spaghetti for a while, bugs will appear...

 

As the spaghetti hides the problem, the spaghetti is the problem.

 

Fix that, and finding the problem will become a lot easier.


It's a lot like cleaning your room.  If you keep on top of it, it's not a problem.  Let it get out of hand, and it becomes a major chore.  Straighten up your code as you go, and you'd be surprised at how easy it is to do.  Don't be an Oscar Madison.  Be a Felix Unger.


I resent that 😁.

 

I don't like to clean my room.

 

But the point is valid. Procrastinating doesn't make it easier.

0 Kudos
Message 8 of 10
(1,548 Views)

Thanks to all for their hearty recommendations about cleaning up my code. I wholeheartedly agree - I just needed to get it to run in the first place - and it runs absolutely fine except that I need to ensure that one subVI is triggered first before the second subVI (in the other loop) runs. The reason that the first subVI is hanging is because of the absence of the TTL pulses being received at the lock-in amplifier. So the subVIs are NOT sequential, because the lock-in amplifier essentially waits for the NI-DAQ to spit out TTL pulses before it can collect data. 

 

The reason why I haven't attached the code is because of the sheer amount of dependencies that I have - connections to a laser, a signal generator, a lock-in amplifier - and etc.

 

But i take the point very seriously that has been made about the state of my code and will never post again without clean code ready for the helpful folks on thisforum. Sorry for wasting your time looking through that mess .... 

0 Kudos
Message 9 of 10
(1,499 Views)

@Alisterio wrote:

 it runs absolutely fine except ...


LOL.

 

That's typical 😂.

 

Don't worry about this too much. I know plenty of people that make a mess that works so they can 'clean it up later'. I personally experienced that taking the time to clean thins up gives me the air to actually think about what I'm making. But YMMV...

 

Do note that cleaning up afterwards often doesn't happen, judging on what I get to see.

 

In general, every non-trivial bug is caused by too much complexity. That can have many sources. Untidy code is one of them, but there are plenty of other sources.

 


@Alisterio wrote:

But i take the point very seriously that has been made about the state of my code and will never post again without clean code ready for the helpful folks on thisforum. Sorry for wasting your time looking through that mess .... 


It's not a waste of time if you got that message 👍.

 

We wouldn't have bothered if we felt it was a waste of time.

 

Do note that there other advice has been given.

 

You're seem to be in a state of learning where have to step from 'a VI' to 'a program'. That is a steep learning curve. 'Architecture' is the term to search for. You'd typically find many, like producer\consumer, QMH, DQMH, Actor Framework, etc. Using OO provides enough 'architecture' for me. It's a lot to digest.

0 Kudos
Message 10 of 10
(1,459 Views)