user1296153
user1296153

Reputation: 585

LabVIEW: how to stop a loop inside event structure

I create an event structure for two buttons, start ROI and stop ROI. When the user presses start ROI it goes to this event and do the following:

  1. check if the camera is open and is in idle
  2. enqueue "none" to the queue to initialize the queue
  3. in the loop dequeue every iteration to find if there's invoked message, which is inserted from the callback
  4. if the element is "invoked" then update the region

The problem I am seeing is that when it is in the loop I cannot press the stop ROI or any other buttons. But the ROI keeps updating. I am puzzled why this is happening.

enter image description here enter image description here

Could you please help me ?

Thanks,

Upvotes: 0

Views: 4824

Answers (2)

nekomatic
nekomatic

Reputation: 6284

As far as I can tell from the code you have shown, your event structure should not be attempting to handle the stop ROI Value Change event. It doesn't need to, because the only place you need to respond to that event is inside your innermost loop and there you are handling the button click by polling the value of its terminal anyway.

However as @Dave_St explains, this will only work if the loop runs regularly, i.e. if the Dequeue Element function either receives data regularly or has a short timeout, because otherwise it will wait for data indefinitely and the loop iteration will not complete until the dequeue has executed. Having an event handler for the button click can't help here because it can't interrupt the program flow - the event structure only waits for an event to happen and then allows the code in the corresponding frame to execute.

More generally though, and looking at your front panel which suggests you are going to want to deal with further controls and events, the problem is that you are trying to do a time-consuming task inside an event structure. That's not how event structures are designed to be used. You should use a design pattern for your app that separates the UI (responding to user input) from the process (acquiring images from a camera) - perhaps a queued message handler would be suitable. This may seem harder to understand at first but it will make your program much easier to develop, extend, and maintain.

You can find more information, examples and templates in your LabVIEW installation and its online help. I do recommend using one of the templates as your starting point if possible because they already implement a lot of common functionality and can save you a lot of redundant effort.

Upvotes: 0

Dave_St
Dave_St

Reputation: 452

Disable front panel locking

Edit events for that case (the one pictured in your screenshot) and make sure the box titled "Lock front panel" is unchecked. This should solve your issue.

Upvotes: 0

Related Questions