07-14-2012 08:13 PM
Hello Friends,
I have 5 buttons on front panel (Start, Stop, Home, Back, Forward). I am using an event structure to execute code whenever the value changes on either of these buttons. When Start Button is pressed, the main code starts executing which takes some time to execute. Currently if any of other four buttons are pressed, their code is not executed since Start button event is not complete.
Is there any way to abort the execution of the rest of code for the start event and execute code for the other buttons? Is there any way to prioirtize certain events over another? Any tips, example code would be appreciated.
Thanks
07-14-2012 08:26 PM
You need to ensure that events execute very quickly. Use an appropriate desing pattern to ensure that the UI is decoupled from the processing.
Can you show us some code?
07-14-2012 09:04 PM
I think you are correct about choosing an appropriate design pattern since I can't get the execute the low priority event (Start in my case) very fast. Please see the attached MainVI. I have removed the details in the VI to convey the basic idea. Let me know it you have any suggestions. Also I would like to add, this VI is a part of the project (Evident from Back, Home and Forward Buttons). So this is called as a subVI.
07-14-2012 09:18 PM
You also have an event structure inside of an event structure. That can cause all kinds of problems.
07-14-2012 09:26 PM
I thought that too. But currently that's working perfectly fine. I mean the Start Event
07-15-2012 01:19 PM
Any suggestions where I can start looking to improve my approach?
07-15-2012 02:02 PM - edited 07-15-2012 02:04 PM
Sorry, I am on a laptop, so inspecting that way oversized diagram is not really possible. Keep it compact.
Some things:
Use one event sutrucure in an independent loop for all user interaction.
Make your butons lacth action and place them inside their respective events. No need for local variables.
Using proper dataflow, you can eliminate all your sequence structures.
Use a second independent loop (consumer) that processes queue entries produced by the UI loop above.
Here's just the tip of the iceberg. Let's look at one of your code segments (Sorry, I don't have IMAQ, so certain things look broken):
A 30 second rewrite could look like the code shown below. Much more readable, simpler, clearer, and smaller!
07-15-2012 02:35 PM
Also you only need to check for the existence of the file inside the true case of the outer structure. Move it there.