06-04-2014 10:50 AM
I have a subvi that runs a loop taking a series of images from a camera, but if I want to end the loop my main vi is running in, I have to wait till the subvi loop ends therefore moving back into my main vi. Any suggestions?
06-04-2014 11:10 AM
06-04-2014 12:01 PM - edited 06-04-2014 12:04 PM
Well you probably shouldn't have a long loop inside a subVI. Perhaps you should redesign your approach.
However if you insist on having the loop within the subVI, I would recommend using either a functional global, a shared variable, or a notifier. All of these should allow you to flag the subVI to stop the loop whenever the Main VI wishes.
Could you explain more precisely when you want to stop? I.E. Only for emergency exit, take pictures until you tell it to stop then resume Main VI, etc.
06-04-2014 12:29 PM
use an'eventstructure' to respond instanly to the user interface and a notifier with "0" wait connected to the stop control of that sub.vi loop
06-04-2014 02:54 PM
Are you sending any data to this subVI already? Almost always when I have a long subVI, it is actually running off on its own in parallel with my main VI's loop. I then use a queue to send commands to it. Commands may include Start, Stop, Log File, etc. So the Stop command coming from the queue will stop the subVI.
06-04-2014 04:52 PM
@crossrulz wrote:
Are you sending any data to this subVI already? Almost always when I have a long subVI, it is actually running off on its own in parallel with my main VI's loop. I then use a queue to send commands to it. Commands may include Start, Stop, Log File, etc. So the Stop command coming from the queue will stop the subVI.
I guess this is really just a variation of a QSM except that the state machine loop is just made into a subVI? (This is just for my personal understanding.)
06-04-2014 06:17 PM
@billko wrote:
@crossrulz wrote:
Are you sending any data to this subVI already? Almost always when I have a long subVI, it is actually running off on its own in parallel with my main VI's loop. I then use a queue to send commands to it. Commands may include Start, Stop, Log File, etc. So the Stop command coming from the queue will stop the subVI.
I guess this is really just a variation of a QSM except that the state machine loop is just made into a subVI? (This is just for my personal understanding.)
Not reallly. More of a QMH (Queued Message Handler). I like to have loops that do one specific thing (like reading from a DAQ, writing to a file, etc). So some (like the file writer) will only react to commands. Others (like the reading from a DAQ) will have a 0ms timeout while commanded to be active, basically looking for the stop command. So in this way, I can control any of my parallel processes just by sending a message down their queue.
Though, now that I'm thinking of it, this is sounding a lot like the Actor Framework. I really need to start studying up on that.