ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
06-17-2010 05:41 PM - edited 06-17-2010 05:44 PM
Gents,
I appreciate the comments so far. ...as of right now my familarity and time constraints are keeping me from fully understanding the producer/consumer methods using queues. I'll get to it eventually I'm sure.
Anyway, for now, can't I just do this with parallel while loops?
My main vi utilizing a state machine with an event structure (as tbob helped me figure out about a week ago!) works great to turn on a LED. The subvi that controls turning the LED on always turns the previous LED off first... My LED communication is accomplished via i2c communication. Additionally, I can easily turn off any/all the LEDs by using a digital I/O port that resets the i2c devices...this way I don't have to worry about keeping track of which LED was on previously, just shut them all off before turning any of them on. Probably not the sexist way to do it, but very functional.
So essentially, all I really need to do is use the same digital I/O port after time elapses...sounds easy enough, but I'm still struggling with this.
-Mike
06-17-2010 06:05 PM - edited 06-17-2010 06:09 PM
Attached is a screen shot of what I'm trying to do...currently I'm scratching my head on how to reset the elapsed time...
06-17-2010 08:01 PM
Your local variable for resetTimer is outside the loop. What happens is that the original value for this variable when the program starts execution gets passed into the loop. The loop always uses this same value because the local is never read again. So the timer never gets an updated local and never gets reset. Put your local variable inside the loop. This way, the local gets read with every loop iteration. Now when the variable gets changed, the local is read and the change gets sent to the timer.
Same problem with your exit local variable. It gets read once, and never again. Put it inside the loop to get read every loop iteration.
06-17-2010 08:29 PM
tbob,
I'm still having trouble with the elapsed time...it starts running as soon as the vi starts. I think this is normal behavior. What I really need to happen is for it to start or reset until an LED is selected. Then, when say 3 seconds has passed, shut off all LEDs...I think I'm just slow or something! LOL
-Mike
06-17-2010 11:51 PM
Man...something so simple is kicking my butt!
OK, lemme put this down in text...
----------------------------------------------------------------------------------
1. User selects LED to turn ON in main vi ---> go to step 2.
2. Turn off any previous LED by just turning all LEDs OFF ---> go to step 3.
(use LED reset vi to turn LEDs OFF by using DIO output to reset I2C LED controller)
3. Turn ON LED selected in step 1. ---> go to step 4.
4. Start/restart timer - if timer count equals LED ON duration constant
(use LED reset vi)
----------------------------------------------------------------------------------
*Note, user can select a different LED or the same LED to turn ON again during step 4, moving back to step 1.
----------------------------------------------------------------------------------
The main vi is one big happy state machine utilzing an event structure...the event structure listens to see if the LED value changes, if so it currently starts step 1, and happily makes it through step 3 as previously described...its dealing with step 4 where I have problems. More directly, dealing with the timer...I realize step 4 must occur in a loop parallel to the main vi loop so the timer doesn't make the main vi wait on it. I just can't seem to implement it! I'm tired, and going to bed now...if this makes no sense, forgive me.
-Mike
06-25-2010 10:36 AM
Your Elapsed Time is in a loop that runs parallel to the main loop. Of course it will start as soon as the vi is run. Set up your state machine exactly as you have described in your text description. State 1, state 2, etc. The timer would go in state 4. Then your vi will be much easier to read and understand.