LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build Array and Avoiding Buffered Allocations ... a little help here??

I tried using this technique with two queues but the "user event handler state machine" just locks up.

 

I've attached a rough VI that actually works to an extent...the attached VI represents the framework of what I am working out of.

 

Any suggestiosn?

0 Kudos
Message 11 of 28
(1,314 Views)

Hello,

 

Where does your VI lock up in the State Machine? Is it locking up in one of the states or is it simply waiting for the queue?

 

-Zach

0 Kudos
Message 12 of 28
(1,296 Views)
I was hoping I could get that answer.  The user event queue won't respond.
0 Kudos
Message 13 of 28
(1,283 Views)

Hello, me again!  (your worst nightmare...)

 

In the code you posted, you initialize your user events queue reference to just a variant (in your sequence structure, which can and should be murdered).  Where did your enumerated constant go?  The one that specifies the next state?  Without that, how are you supposed to know where to go next?

 

And what is that notifier for?  You can use it to stop ALL the loops, you know... not just the "read/write DAQ" case.  In other words, you can get rid of that global and use the notifier instead.  Right now it sends a notification to your event handler loop, which then does...nothing.

 

You are on the right track as far as the two separate queues.  And I'm proud of you for writing yourself a little example VI to figure this out.  I think you can simplify your example VI even further, but that is up to you.

 

Try initializing your user events queue reference to a cluster with your enumerated constant and a variant, I'm guessing it will stop locking up.  🙂

 

I presume I'm looking at the right code?  The one called "example VI"?

0 Kudos
Message 14 of 28
(1,276 Views)
worst nightmare...but source for infoSmiley Happy
0 Kudos
Message 15 of 28
(1,264 Views)

I took a look at the code posted and it got a bit screwed up as some changes didn't get saved.

 

Here's the new attachment.  Apologies.

0 Kudos
Message 16 of 28
(1,254 Views)

Ok, my friend, I've had a look at your code.  There are a few problems I see, but to start with, I will go ahead and reveal the Great Secret as to why your User Events queue appears to lock up...

 

It's not locking up.  It's working just fine.

 

In your code, for some reason that I don't understand, you have a "generate occurrence" function, wired to a "Wait on occurrence" function.  Your "wait on occurrence" function does not have a timeout specified, so it'll just sit there and wait and wait and wait until the cows come home (and they're out partying).  And that's exactly what it's doing.  Just sitting there, waiting (you never actually set an occurrence...you just wait for one).  Since three out of your four loops require the output of that "wait on occurrence" function in order to get started (a loop can't start until it has all its inputs), they can't start executing.

 

Therefore, your event structure loop never even starts.  Same with your mysterious timing (?) loop and your DAQ loop.  The only one of your loops that's running is the one containing your state machine, and of course it has a "dequeue" function that is set to never time out.  So, that dequeue function sits there, waiting and waiting and waiting...just like you told it to.  Thus, the program appears to hang.  It is not hanging.  It is doing precisely what you told it to do.

 

You might note, in the "wait on occurrence" help, that it specifically says that NI recommends you use notifiers and not occurrences.  I second this.  Whatever you have that in there for, either give it a timeout so it can execute and be done, allowing your other loops to start, or get rid of it entirely and replace it with another notifier (you can use as many notifiers as you want, just like queues).

 

Ok.  On to your next problem.  You have one end of your DAQ queue (the "enqueue" function) placed, appropriately enough, in your DAQ loop.  You have the other end of your DAQ queue (the "dequeue" function) placed in the "Data" state of your state machine.  However, you never queue in the "Data" state from your UE queue...so when is all that data coming in from the DAQ loop supposed to be dequeued and displayed?  Also, if you want continuous dequeueing, you will either need to repetitively enter your "data" state, or you will need to put the "dequeue" function into a loop.  Otherwise, you'll keep sending data via that queue and never dequeue it...as happens currently.

 

Next issue!  You do not have a single function which stops all of your loops.  In your event structure loop, you can either stop that loop with your eeeeeeevil global, or the "stop" button.

 

In your state machine loop, you have to queue up the "done" state in order to stop the loop.  That's done in a rather roundabout way, but I will assume there's a good reason for that.

 

In your weird timing loop, you use the eeeeeevil global.

 

In your DAQ loop, you use a button labeled "stop5".  When I click on that terminal to find the control, it's hidden waaaay far away from your other controls, obviously not supposed to be accessible to the user.  Unless that button is pressed, that loop is never going to stop.  Sure enough, that's exactly what happens, and your program appears to hang.  It doesn't really hang, of course...that loop keeps happily executing along, never having been told, "hey, the rest of us are done..."

 

So, those are the main things you'll need to fix, to start with.

 

Told you I'm a nightmare...  Smiley Very Happy

 

d

0 Kudos
Message 17 of 28
(1,243 Views)

thanks again D...  I'll take a look at fixing these...

0 Kudos
Message 18 of 28
(1,238 Views)

Allright....

 

Wading through the concepts of queues is just so much fun...so here goes what I've come up with...

 

1.........The "wait on occurence" function operates to enable all .ini settings to occur within the "initialize" case (of course you don't see these in this mock-code)....  Is this still overhead?  The way you mentioned this function makes me think "why did LV ever come out with the blasted thing in the 1st place?"...though it seems to serve a simple purpose if not abused.  Wish I could say that about a few other things in my life.  Notifier really necessary here?

 

2........You're right about that blasted "stop" global...driving me nuts.  What are the other options?  I know you're going to say somethin' in regards to using a queue function to stop the parallel loops, but I've got the slightest clue without doing a few hours of diggin'...point me in the right direction of an example vi if you could....

 

3......the DAQ queue output........I figure I could do 2 options, a) put it within the main state machine "data" case, b)....still working on this one.... I guess I could run another parallel loop to display the data to the user interface other than using the main state machine event handler (but would this really help all that much, seems like it would just create overhead...pretty much would be....)

 

4.... where to save the data?  what parallel loop?  The main state machine event handler is doing this presently, the "weird timing loop" controls how often the DAQ data is inputed into the database.... is there any other way to control how often DAQ data gets inputed into the database?  Just ramp up/down the "wait" function via the event structure?  As you can see with the updated VI I attached I was just messing around and having the "event handler" loop timeout case call the "Data" case (not a good idea?)

 

This inherited VI is starting to give me a similar feel as some of our older turret lathes...  you wouldn't believe how many globals I've already eliminated...yeah you probably would.

 

5....timing for the wait functions of all of the parallel loops... I have an idea on which loops need to wait less than others, just want to double check....for example, DAQ loop with a 10-wait / State Machine with a 10-wait / Event handler with a max wait of 200? or can you dip below this into the 10 or 100-wait?  

 

Any similar examples you could point me to would be of immense help.

 

Also, quick question in regards to the individuals who reply to all these threads on this forum...NI employees? or just altruistic individuals?

 

Definitely very helpful & unique.

0 Kudos
Message 19 of 28
(1,207 Views)

jonathanupr wrote:

...

 

Also, quick question in regards to the individuals who reply to all these threads on this forum...NI employees? or just altruistic individuals?

 

Definitely very helpful & unique.


All but zach (the "blue bars" are NI employees) are altruist.

 

Aren't they something? Smiley Wink

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 20 of 28
(1,201 Views)