11-08-2011 06:27 AM
I am fairly new to LabVIEW and I am writing a basic program with various functions to help me learn. I am sure I may not be doing this the best way but I wanted to use certain functions that I am trying to learn about from another program I have been asked to modify.
What I am trying to do is trigger an event in an event structure with a combo box. However the event sometimes works once but then won't for the majority of time. I am populating the combo bax from a string array and then referencing the string value index to determine values for another part of the program. Anyhelp is much appreciated.
11-08-2011 07:20 AM
You need to place the control with which you are triggering an event within the main loop, preferably within the event cell that triggers off of it.
This is all becase of dataflow. When you execute your application, the control is read once and then will never reset until you run the program again. This will allow you a single trigger of the value change event and then no further events will trigger off of modifying the control.
Just replace the property node with the actual control and you should be good to go.
Regards,
Dan King
11-08-2011 07:56 AM
Dan,
Thanks for the clarification, I understand your point. However, this did not solve my issue. I am thinking the problem has something to do with the values in the combo box. They are not numbered like typical combo box items, they become equivalent to the string defining the item even if I uncheck the box in the properties-edit items for 'values match items'.
11-08-2011 08:27 AM
Hello Chet,
I looked into it in more detail and the behavior you are seeing is partially due to the behavior of the combo box. Instead of returning the text of the box itself, it returns a string containing the index of the box. I modified the VI to take this string, convert it to an integer, and feed the index into your index array for fastener details.
You also weren't passing the information from your shift register through your "Fastener" cell, which would cause you to lose the data from your "Unit" cell after executing the "Fastener" cell once. I also went ahead and deleted the Timeout case since you weren't using it right now; you can always add it back later if you need it.
The last thing I did is clear the Fastener Details indicator when changing the Units, as you would be displaying erroneous data immediately after the switch. I figured no data was better than wrong data.
For further development, I would look at moving to a Producer-Consumer(Events) architecture to gain more control over the data deisplayed and the behavior of your front panel. For example, it would be nice for the "Units Value Change" to execute the code from its cell along with the "Fastener Value Change" code, without duplicating the code itself.
Regards,
Dan King
11-08-2011 09:01 AM
Dan,
Thanks again. Any chance you can send me that code in LabVIEW 2010? I don't have 2011.
11-08-2011 10:58 AM
Chet,
Here you go.
Regards,
Dan King
11-09-2011 07:41 AM
Dan,
Thank you again, each of your responses is helping me more and more. I hope you get something out of this also. So your code changes certaily improve things however I noticed a strange behavior. For combo box indicies 0-7 your code change works. However, for indicies > 7 the combo box outputs a string value but they are all from the usFasteners array?!?!?
What I found was when I was troubleshooting I unticked the 'values match items' box in the combo box properties and I also changed some of the values (0-7). This is why items 0-7 worked, items > 7 had the string value from usFasteners array. Well I changed the properties of the combobox back to values match items and now it consistenly displays the string which I can use as I originally did with the search array function. The main problem I think was what you pointed out with not passing the indexed values thru the unit case as well as not having the combo box in the event case.
I cleaned the code up a bit also to get rid of some of the duplicated code and attached if you would care to see. Instead of taking the fastener details to default values I use a val(sgnl) property node to set the item to index 0 of the array.
Do you still think I would be better off with the producer-consumer (event) structure?
Thanks again for all your help!
11-09-2011 10:59 AM
Chet,
I took a look at the code and it looks great. At this point I wouldn't move to the producer-consumer (events) structure given your solution. It all depends on where you are going from here though. If your application isn't going to get much larger it is probably pretty good as is. If this is only the beginning, and you are planning on adding more functionality, I would look at changing the high-level architecture and start increasing the modularity of your code.
You are on the cusp of where moving some of your code to subVIs may become helpful in the organization of your top-level application. Again, it really matter on how much additional functionality you plan on adding to the application.
Regards,
Dan King