LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure Question

Hopefully I can explain this okay....
 
I'm using an event structure to control several features in my program and all have worked great.  All of the events in my program are handled via boolean buttons with value changed option.  I have a numeric control in my program that controls integration time.  This changes when the user clicks the up or down arrow or types in a new value.  This control is used and needed to changed the integration time in a couple of different event cases.  However now I'd like to use this numeric control (integration time) to not only change the integration time but also trigger one of the events (in addition to the normal button that I have been using to trigger the event I need to have happen).  (The value of the numeric control when changed also executes a case structure when it is changed in one of the other events.)   
 
However when I tried to do this, I ran into some problems.  If I change the numeric control value during one of the events in which I need to use it, and after stopping the event, then another event seems to execute (based on the changing of the numeric control, this event is the same event I ultimately would like to trigger).  Basically I need to stop the numeric control from executing after stopping another event when its value has been changed and only executing when I need it to.  Everything I seem to be doing hasn't been working and I'm just not seeing any type of walk around.  But I need to be able to use the control in various events to change the integration time and also if needed to change it and thus trigger an event (besides using a boolean button to trigger the same event). 
 
If needed I can post screen captures or sample code, but my main vi is rather large, so I'd have to cook something up as an  example.
 
Any help provided would be much appreciated.   
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 1 of 10
(3,885 Views)

Hi,

You may want to take a look at the Producer-Consumer design pattern for this.  You will find a template for his here: 

templates\Frameworks\DesignPatterns\ProducerConsumerEvents.vit

Basicaly, instead of processing the events in the Events Structure, you pass them down to a different "Consumer" loop using a Queue.  Or better yet, make a "Consumer" State Machine so you can execute different states based on the situation. 
 
Hope this gives you some ideas. 
 
-Khalid
 
0 Kudos
Message 2 of 10
(3,877 Views)

Khalid, thanks for replying.  I looked over your suggestion but I'm not sure if that would work in my case or not.  In the producer/consumer setup, I'm not sure what I would wire into the data input of the vi in that program.  My main vi, isn't really dealing with "data" so much, as my question relates to controlling the code to execute an event which in turns will execute a couple of components of my instrument. 

Basically I have a numeric control that controls integration time and would like for when this control is changed in value to execute an event.  However, I also need to use this control in other event cases to control the integration time, without triggering the event it is connected to.  I was trying to come up with a way to use two different controls, but that just wasn't working.  I'm not sure if what I want to do is even possible or not.  Basically I think I'd like to turn "off" the event form happening in one case or more and then have it "on" only when I need it, so it will run its own event.  I wasn't sure if something like registering for events would work or not, but I'm not familiar with those functions at all.

Thanks again for your ideas, I really appreciate it.  If you or anyone else can provide any further insights, I'd appreciate it.

 

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 3 of 10
(3,825 Views)
I think a State Machine would do what you want. The event structure will always send the Integration Time Value Changed event notification to the State Machine. In State "On" you use the information. In State "Off" you ignore it.

A different approach:
If you just need the value but do not expect the control to be changed in the "Off" states, perhaps just passing the value around with a shift register would do. The shift register gets updated in the Value Changed event case and passed through all other cases.

You could also pass a flag (via a shift register) which tells the Value Changed event case whether you are in the "On" or "Off" mode and execute the event code or not.

Lynn
0 Kudos
Message 4 of 10
(3,819 Views)
Unfortunately I'm not familiar with state machines, but I was trying to look over the example I had found with Labview.  I'm not exactly sure how I would set that up in my case.  The numeric control does not have a set limit of values really.  Although it can be no lower than 0.1 it can go as high as needed, although I doubt it would ever reach any great number.  I only say that as I'm not sure if that state machine would depend on cases of the value of the control. 
 
What do you mean by "flag"?  I'm not familiar with that term either.  Can you post a small example of what you mean? Again I'd like for when no other events are firing to be able to change the control and thus trigger the event it would be linked to.  But when other events are firing where this control is needed the contorl itself would still work and use the value changed, but not fire any events at all. 
 
Would dynamically registering the event or events in question help?  Looking things over yesterday I thought about this, but I'm not sure if that would really work if it is an option.
 
I'm trying to find an easy solution if possible, only to save myself form major rewiring or redesigning of my vi.  This is something a co-worker would like to put into the program and not of my choosing so that's why I'm forced into this issue.
 
Thnaks for you suggestions and ideas.   
 
 
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 5 of 10
(3,808 Views)
A flag is a variable, often a boolean, used to indicate the status of some part of the system. This little example may help with some of these concepts. Boolean 1 sets the flag. Boolean 2 does nothing. The actions taken on Numeric Value Change depends on the state of the flag.

Lynn
0 Kudos
Message 6 of 10
(3,788 Views)
The attached amusing example is an architecture which will work for you.  Read the documentation for details.  It has two components - an event hander and a task handler.  The event handler is the LabVIEW event structure.  The task handler is the queue-based outer loop.  If you need to add data to the tasks defined for the queue, make the queue element a cluster and add a variant to it.

As a general rule, most UI projects involve getting to the same task through different events, making this the standard design pattern for almost any UI driven program.  You can separate the task handler (consumer) and the event handler (producer), but I have found that the synchronization problems are not worth it.

I posted 7.0 and 7.1 versions of the code.
0 Kudos
Message 7 of 10
(3,760 Views)

Although all of the previous suggestions are correct and will solve the problem you have described I will throw out a simple solution.

Upgrade to LV 7.1 where you can use the property node "value(signaling)". This node has the same effect as a user triggering the event.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 10
(3,734 Views)
Hmmm, is NI still selling 7.1? Smiley Wink
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 9 of 10
(3,729 Views)

Finally getting around to replying to this...

Just to let all know who replied here, I was able to solve my problem by using the Dynamic Registering for Events method.  It took a bit of work, but everything works fine, like it should.

 

Thanks agian to all who replied with suggestions, I appreciate.  I was able to learn several things from all of the ideas. 

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 10 of 10
(3,597 Views)