LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to detect value change of a control in a event case?

I uses a state machine to control the data acquisition. When the case goes to "reading", the while loop in this case runs the frontend reading, some data processing and displaying. I have several parameters to control the graph scales. What I am doing is to use registers for these parameters and in every loop compare the new values with the old value in the register. If there is different, some adjusting will be applied.
My question is whether there is any other way (property or event) to detect the value change of a control within the while loop like my case. Then I can make the code cleaner.
Thanks!
0 Kudos
Message 1 of 8
(3,205 Views)
You should take a look at the Events Structure, specifically its use as the "producer" in the Producer-Consumer design pattern.  Check it out:
 
LabVIEW 7.1\templates\Frameworks\DesignPatterns\ProducerConsumerEvents.vit
 
-Khalid
0 Kudos
Message 2 of 8
(3,196 Views)
You would need to use a property node and the Value(Signaling) property to have an event function on the control that is changed by the program.
0 Kudos
Message 3 of 8
(3,182 Views)
Thanks for the reply.
My problem is that it is in a while loop inside a event case and everything should be done in the loop including reading the status of those parameters. I guess any event can't take effect only after the loop stops and the current case ends. That's why I used those registers and comparison in my program.
I don't want to change the program pattern. It takes too much time.
I wish I could find some better way. Is there such a property (or anything else) which I can put into that loop, and I can read out whether the value of that parameter control is changed?
Thanks!
0 Kudos
Message 4 of 8
(3,174 Views)
Hi Jiankang:

As LabView doesn't do anything until all inputs are filled, LabView doesn't take the loop again until all blocks in the loop have ended.

So, if you want to catch events inside one event, you won't be able to treat those events until the event you are processing ends.

I guess you have a while loop and inside you have an event structure. In one of those events, you have another while loop and want to catch events on that inner loop.

I gess... but my guess can be wrong.

If my guess is more or less right, you should try to eliminate that inner loop, and on it's place, insert a case on those events you want to catch in the inner (eliminated) loop.
When the conditions for the inner loop are met, set a variable to true, and depending of that variable, take the true or false case of the modified events.

... mmm... I think I haven't been so clear.

Hope it helps,
Aitortxo.
Message 5 of 8
(3,169 Views)
Aitortxo, your guess is exactly right.
It sounds like there is no simple way to solve it. 😞
0 Kudos
Message 6 of 8
(3,159 Views)
Ok, JianKang, let's see if we can make it.

You want to manage events generated in the inner loop, don't you, those events can be managed, there is no problem!, you just need to change orders.

You have, let's say
1.- a while
2.- an Event Case
2a.- event1
2b.- event2
2c.- event3
2d.- event4
3.- another while in which events are generated inside 2c
3a.- event1
3b.- event4
(being event1 and event4 the same for both loops)


try to change to
1.- the same while with a boolean in Shift Register initialized to false
2.- an Event Case
2a.- event1
2a1.- case ShiftRegister=True
2a2.- case ShiftRegister=False
2b.- event2
2c.- event3
--- here you see the value of boolean. If it's false, this is the first time you enter here, so you set it to true.(simulating you are inside the inner loop) ---
2d.- event4
2d1.- case ShiftRegister=True
2d2.- case ShiftRegister=False

---------------

When the Event in which you had the inner loop occurs, change to true the value in Shift Register and continue treating events.

When you catch an event for the old inner loop, compare if the shift register value is true. If it is false, you haven't get into the inner loop. If it is true, you are in the inner loop.

reset the shift register when the inner loop condition is met

I hope this time is more clear. Does this modification modify considerably you code? I think this can be a good solution to catch all events.
Aitortxo.
0 Kudos
Message 7 of 8
(3,156 Views)
Yes, this is a good solution. Thanks!
 
Actually my current code is more like this,
1.- a while
2.- an Event Case
2a.- event1
2b.- event2
2c.- event3 (inner loop inside, need response to event 1, and 4 in the loop)
2d.- event4

So I am thinking that your first structure may also work if I can divide the current events to two groups. For example,
1.- a while
2.- an Event Case
2a.- event2
2b.- event3 (inner loop inside, need NOT response to event 1, and 4 in the loop. It's done in event case 4)
and
3.- a while
4.- an Event Case
4a.- event1
4b.- event4
 
Is this similar like the producer-customer pattern that Khalid mentioned earlier yesterday? Any, I will have to make some change to the program structure.
0 Kudos
Message 8 of 8
(3,135 Views)