LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure causing "freezing"

Solved!
Go to solution

ok, I tried digging around on the boards, and I can't quite find what i'm looking for.  hopefully someone can help, or point me in the right direction.  I'd greatly appreciate it.  

I seem to be having some difficulty with an event structure.  The attached .vi is drastically cut back from the full project i am working on, but it does show the issue I'm experiencing.  Basically, in the full project, an operator scans in a product id and hits the GO button.  The tool then displays the sorting destination in the Sort To: field.  the operator (I'd like) would then have the option to print the bar code for that field (I've disabled that for this post, and just added an incrementing test num for simplicity) and once they scan the value into the Bin ID field (and it matches), the next button is available to be pressed.  Once Next is pressed, the iteration is reset so they can scan a new item in.  

I've been playing with this and playing with it, and no matter how I configure the event structure, I cannot get the desired behavior.  in the current configuration, it seems to work OK, until you go to print a second time (in another iteration).

And, when I remove the "next button" value change from the items in the event structure, it will not let you hit next without hitting print, which is not desirable behavior.  

I've disabled the settings for locking the panel and limited the number of operations to queue to 1...which doesn't seem to help either. 

I've also tried adding a timeout, that also doesn't seem to help (and I really don't want it anyway).  My operators may need to go get another box to print their label onto, and there are other scenarios where a timeout in this step is just not desirable either.  

Please help!!!!

0 Kudos
Message 1 of 7
(4,647 Views)

You have a sequence of events that you are trying to perform in a particular order.  The string of while loops waiting for particular conditions seems to be hanging you up.  (Use the debugging tools like highlight execution and probes to determine where you are getting stuck.)

 

The proper thing to do is rework your architecture.  This is begging to be turned into a state machine.

0 Kudos
Message 2 of 7
(4,618 Views)

It may appear that way.  There was a ton of code (company confidential) I stripped out to make this post.  The code posted is bare-minimum I could put up and still repeat the behavior I'm seeing.  I will investigate the feasibility of using a state machine, but I am in the middle of a huge code rewrite for integration into a new system my company wants to use.  I'm not sure I'll have enough time to make that change as well... maybe in phase 3.5, lol.  

I have been using the debugging tools and when I hit one of the "freezing" steps, the debugger isn't showing any activity.  The Event Inspector Window does show the Next button press as a unhandled event sequence, and it just hangs there (when I incldue the Next button press as an event - it does the same thing, but on the print button press, when I remove the next button event)...  In the case of the Next button press, there are no actions within the event case, so I'm not sure what it is hanging on.  

0 Kudos
Message 3 of 7
(4,533 Views)

The debugging tools should show you activity somewhere.  Put indicators on your while loop iteration terminals.

 

It seems to me that you are still spinning a while loop that is in parallel to the event structure.  The event structure won't be able to execute a second time until you get through the entire string of code and while loops allowing the master while loop to go around again.

0 Kudos
Message 4 of 7
(4,529 Views)
Solution
Accepted by topic author dbrown78

I appreciate you effort stripping down the code.  It really helps to explain just why your code will not work. You have greedy loops

 

Lets peek here:

Capture.png

to complete the case shown you need 3 things to happen

  1. an "Event" must happen to complete the Event structure
  2. The greedy (un-throttled) while loop must complete
  3. BIN ID must be equal to "Sort To" 

Wait a moment.... BOTH 1&2 of those depend on  "Next Device" being "TRUE" or having its value changed.   WHAT? the Operation of that "Next Device" Control is "Switch when released!"  So press the button and nothing happens, release the button the value changes once to whatever it wasn't before.  Possibly the new value is "FALSE" and you have now entered another greedy loop where the only way to get out of it is to make it TRUE.

BUT  "Next Device "is disabled until Bin ID equals Sort To so the user can do whatever until that happens without changing Next Device value

 

To get out of that Last greedy while loop you need any of :

  1. an error out of the case
  2. End to have been read as "TRUE"
  3. Next Device" to have been read as "TRUE"

When is the user interface going to respond to button presses?  You are in a greedy loop! hogging all the CPU resources available and the USER is just pounding the mouse on the desk and swearing!

 

Since End has a mechanical action of "Switch While Pressed" that is guaranteed to exit the outer two greedy loops whenever the mouse breaks from abuse or the OS decides it has some time to interrupt the inner greedy loop and just respond to the mouse input anyway. 

 

There is a fairly good template for a Producer-Consumer (Events).vi  You have managed to break just about everything that design pattern needs to be effective

Spoiler
Hey, I wouldn't have learned this much if I hadn't made similar mistakes log agoSmiley Wink

 seen hereCapture.png 


"Should be" isn't "Is" -Jay
Message 5 of 7
(4,519 Views)

"You have managed to break just about everything that design pattern needs to be effective"  Ha, I'm pretty darn good at breaking stuff - only real way to learn anything anyway 😉

 

this project was my first real world programming exercise, and it has turned into a MONSTER since it's inception.  Once the business realized what I could do, they just kept throwing what if's at me, and I kept inserting code.  

 

thank you for your help in explaining, I really appreciate it.  I'm going to play with it some more and see if i can come up with a better way of doing this.   

Message 6 of 7
(4,507 Views)

It took me a few months and a ton of rewriting, but you were completely right.  I turned the entire project into a state drive flow, and it works perfectly.  Thanks for shedding some light on it for me!

Message 7 of 7
(4,239 Views)