05-09-2017 04:59 PM
Dear All,
I am trying to LabVIEW's tab control to switch between various control elements for a scientific instrument I am constructing. I set it up identically to the tab control in the NI example, which I can get to run fine on my computer. While I seem to have successfully gotten the structure setup and can get it to run one tab at a time (the one selected when I click on it), I cannot switch between tabs while the software is running. I have included a copy of my code in hopes that it will be of help in solving this problem.
I tried an event structure (set to value change, with the "new val" tab connected to the tab selector) and it would run the second tab clicked on but no others, even though the structure was placed in a while loop set to never stop.
Any help you can provide would be greatly appreciated. Thanks!
05-09-2017 10:06 PM - edited 05-09-2017 10:08 PM
I see a couple problems with your code.
First, it is very unusual for the value of the tab control to be something that actually controls the execution of your program. Generally, the tab control is an organization tool to allow the user to see different groups of controls, while hiding others. Using it to control your program, and particularly the way you have it control loops within a case structure. It is just a tangle of execution.
Second, the bigger problem is the way you have multiple event structures in your VI. Unless you really know what you are doing, multiple event structures is wrong. You have them in loops, in parallel, inside of a case structure. (Why would they need to be in separate event structures in separate loops? Jog Fwd and Jog Rev seem to be different events that belong in the same structure!) If you trigger one of those events and that case is not in the path of execution, you will lock up your VI cold because they are set to lock the event structure until the event completes. But that case structure won't complete, event if you change the tab which will cause those other while loops to stop, but those while loops won't complete until you happen to have triggered each of those event structures: a Jog Fwd, Jog Rev, and Re-zero stage. And you'd probably have to trigger each of them twice.
Read Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2016 Help
Then restructure all of your code. The vast majority of programs can use a state machine architecture, or a producer-consumer, or a combination of the two.
05-09-2017 11:00 PM
Thank you very much for your response.
I had actually read that link previously and had placed the two events in their own loops in an effort to avoid a sequential issue (namely, having to jog back and jog forward once each before the loop could move to the next iteration). You are correct that the VI locked up when these events were triggered, I have adjusted all of the event structures to not lock the VI any more. Previously, I had written those as case structures, but they required the user to mash the button down for an extended length of time in order to have a "true" value be read when the case structure was "looking." I will adjust the structure sequence so that there is only one event structure in that loop, and think of any way that I might be able to integrate it with the code on the top of the tab there so that there is only one loop in the tab, similar to the others.
I was basing my use of the tab structure on this link (https://forums.ni.com/t5/Example-Programs/Tab-Control-with-While-Loop-and-Event-Structure-Example/ta...). Previously, the separate functions for this instrument were controlled with individual VI's that the user would open and close. My goal was to get them all under one umbrella so that the user would not have to open so many VI's. We have controlled other instruments in this way in the past using C++, but never labview yet.
My understanding from your comment and my reading of the literature on state machines and producer-consumer architecture is that I should instead use the tab control solely for the front panel, and instead use the state machine architecture (like http://www.ni.com/tutorial/7595/en/), with an statement at the end of the case structure to select the next tab for the iteration, perhaps by polling the tab control (since the go-to-next action is the changing of the tab) and then wiring it over to the shift register. I'll try a code structuring like this and see how it goes.
Again, thanks for your assistance.
05-10-2017 01:15 AM
Hi RavensFan,
First, it is very unusual for the value of the tab control to be something that actually controls the execution of your program.
I use tabs to organize the UI of a VI sometimes.
And in such cases I tend to use the tab control value in the BD to only execute the code parts needed to drive the UI (like filling graphs or updating other stuff) when to indicators are actually visible…
I think this is a very usual use case for tabs!
05-10-2017 08:24 AM
I think that is a legitimate use case. But you still aren't really controlling the overall execution of the VI.
But I don't think it is that usual of a use case. Most people will just allow indicators and graphs to be updated even they don't happen to be visible.
05-10-2017 09:48 AM
I don't understand what possesses people to create block diagrams with huge amounts of white space.
Trying to follow what you're doing isn't easy; one look at that mess was too much for me.
You'll get more help if you clean up your code before you attach it.
05-10-2017 09:47 PM
Thanks all for your help! Based on RavenFan's advice, I set up a state machine architecture for the program as a whole. The conditional statement accepts the tabs as inputs, and the last item for each tab is to poll the tab controller for the next loop iteration. In this way, the tabs still do control which code is executed (otherwise there could be potential conflicts from different tabs trying to tell the same elements to do different things), but the tab controller is polled often enough to actually change the tabs.
Condensing all of the event structures for the "stage" tab into one structure made everything much easier, and they now all work. I also cleaned up the white space a little
I've attached new code that seems to work much better. Thanks again for your assistance!