02-07-2010 01:23 PM
hi everyone,
I have Vi composed of a while loop with different task to do inside.
I tried to put one of the task (a piece of code) Into a event structure "Button1 value change" to execute this part only when the user click on a button,
but as soon as I put a event structure inside the while loop, it stops everything, the other tar task does not work anymore !
It should be very simple but I'm getting crazy about why it does not work, and why everytime I drag even an empty event structure, It stop everyting. (the while loop iterate one time and stop)
I can post a piece of code to explain my problem more in details if needed.
Thank you very much,
Guillaume.
02-07-2010 01:41 PM
02-07-2010 02:03 PM - edited 02-07-2010 02:07 PM
Ok I will try, indeed, it doesn't stop the while loop anymore (thanks).
But the piece of code in the event structure will have to access data inside the while loop, data updated every iteration of the while loop.
In an other way, the code inside the event structure take in argument the data inside the while loop.
For example, the code inside the event structure start on click and wait until a float in the while loop reach 3 for instance, send a signal, wait for this same float to go down to 1 and stop until the user click again. (I hope I am clear)
Will it be possible ? (I need to use local or global variable to pass data dynamicly from one structure to anoher ?)
thanks,
Guillaume.
02-07-2010 02:27 PM
gdlbb wrote:But the piece of code in the event structure will have to access data inside the while loop, data updated every iteration of the while loop.
In an other way, the code inside the event structure take in argument the data inside the while loop.
It would be much easier of you could show us a simplified version of your code.
There are many possible solutions to do all this.
gdlbb wrote:For example, the code inside the event structure start on click and wait until a float in the while loop reach 3 for instance, send a signal, wait for this same float to go down to 1 and stop until the user click again. (I hope I am clear)
I think you are approaching this way too complicated. All you probably need is a simple state machine.
02-07-2010 02:41 PM
gdlbb wrote:Will it be possible ? (I need to use local or global variable to pass data dynamicly from one structure to anoher ?)
thanks,
Guillaume.
You can use a local variable. But put a while loop in the event structure to check whether the local variable has reached the desired value (it is 3 in this case) or not continuously. If you will not put this into a while loop, your event structure will check it only once.
It could look something like this (this example is not written for your case, it is a very abstract example):
02-07-2010 04:50 PM
Giedrius.S wrote:
It could look something like this (this example is not written for your case, it is a very abstract example):
NOOOO!!!!!!
Sorry, but this is horrible code that breaks quite a few rules. 😞
02-08-2010 03:02 AM
altenbach wrote:NOOOO!!!!!!
Sorry, but this is horrible code that breaks quite a few rules. 😞
- An event structure belongs in a while loop (with rare exceptions, such as in dialogs).
- Event structures should not contain while loops that could take a while or might never complete.
- Unless the event has "lock FP until complete" disabled (enabled by default), the stop button would not work while the event is still running.
- The FOR loop inside the event structure uses 100% of the CPU doing basically nothing (Unless there is a small wait in the FALSE case that we cannot see ;)).
- The value property node should be replaced by a local variable. Less overhead.
- Why are your controls disconnected? The "Start to decrement" terminal belongs in the lower loop, replacing the local.
- The "activate event tracker" terminal belongs inside the event frame if it is set to latch action. Is it?
- It seems silly to increment a value just to compare it with a constant. Why not compare with "2" instead?
- You could simplify the code by wiring the value directly to the case and make one case "2" and the other the default.
When making such an example, it would be much more helpful to attach an actual VI (or code snippet) instead of a picture. Many details are not visible in a picture (e.g. mechanical action settings, event settings, etc.)
Thank you for your comment, altenbach. As I have mentioned a few times (probably I should make this my signature), I am far from advanced LV programmer. I have still a lot to learn. So such situations when I brake some coding rules might occur from time to time. It is worth participating in the forum, because sometimes I help and sometimes I learn.
I have tested this example and it worked to me, so I have put that on a forum adding a note, that this is a very abstract code and should not be copied directly.
Will have your notes in mind next time 🙂
02-08-2010 03:22 AM
Giedrius.S wrote:
...It is worth participating in the forum, because sometimes I help and sometimes I learn.
Kudos for your learning attitude 😉
PS: I do not know how to precisely translate this "不耻下问".... but that's the attitude!
02-08-2010 07:32 AM - edited 02-08-2010 07:37 AM
You should also look at using queues to pass data from an event structure loop to a consumer loop. I prefer using queues over Property Nodes and especially Local Variables.
An advantage of using queues is that they can deal with multiple events, even when the first one is still being processed.
02-08-2010 12:01 PM - edited 02-08-2010 12:03 PM
Hi guys,
Thank you very much for your replies, I have learned quite a lot of stuff (about the rules for instance).
I still don't know very much how to handle event structure, but I did want I want with shift register and case structure.
The goal my Vi was :
You push inject button (in the "ignite - inject" tab). So, the injection of fuel in my combustion chamber is armed, ready to go, and then, when the gauge (the camshaft angle) is between 180 and 190 ° it launch injection for real (through the sub-vi number 4)
I know I did not gave enough details, My vi's might be useless for you guys but I post it here anyway because if somebody as the same problem in the future, maybe he will find this post.
Thank you very much,
It's been some month I started to learn labVIEW, and I learn a lot, maybe In 5 years I will able to help :).
Guillaume.
P.S I will give more details of my application in my next post if somebody ask for it.