From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wrap my code up

Dear
 
I posted my problem in former thread.
But I didn't get a proper reply.
 
The attachment shows my whole code for manipulating array according to the index.
 
My first problem is to give a STOP routine inside GO event.
As you can see, the GO include one While loop to check if valid elapsed time.
I know one event had better not include more event structure.
But how can I do to stop the while loop(time checking) inside one event?
 
The second is about sub-vi.
I have to include more routine for data acquisition, data saving, etc.
Currently the code is seemed to be too complex to include more routine.
Therefore I want to wrap the one condition plus the shift register (box in attachment).
Should I use some global variable for this solution?
 
Thank you in advance.
 
Lee
 
 
 
0 Kudos
Message 1 of 2
(2,148 Views)

Hello,

Let me get to your questions:

My first problem is to give a STOP routine inside GO event.
As you can see, the GO include one While loop to check if valid elapsed time.
I know one event had better not include more event structure.
But how can I do to stop the while loop(time checking) inside one event?

 
For this you will need a change of architecture.  Once you're in an event case, other event cases handled by that event structure can execute only after the current event case completes.  However, an architecture such as a producer-consumer which has an event handling loop and an event processing loop can solve your problem.  Basically, you start with a queue: in the producer loop you enqueue elements in your event cases which define what to process in the consumer loop - the consumer of course dequeues those elements and processes the data.  There are VI templates to help you get started with this structure - select File -> New -> VI -> From Template -> Frameworks -> Design Pattern -> Producer/Consumer Design Pattern (Events).
 
 
 

The second is about sub-vi.
I have to include more routine for data acquisition, data saving, etc.
Currently the code is seemed to be too complex to include more routine.
Therefore I want to wrap the one condition plus the shift register (box in attachment).
Should I use some global variable for this solution?

 
I don't fully understand what you're going for here, but let me say a few words about global storage.  There is a global variable structure which you can use to pass data across VIs (and within a VI, but the local variable is better for this case... and you should only use variables if necessary - when dataflow can't be used).  Another option is to use what is often called a "functional global variable."  It is fundamentally just a VI with a while loop, uninitialized shift register, and a case structure.  Typically the while loop is set to run only once at a time - it's purpose is really to hold the shift register, which is left uninitialized (on the left, outside the while loop) because that causes it to retain its value across calls to that VI (as a subVI).  The case structure will then usually have cases such as: initialize (to write a "default" value to the shift register), write (to write a specific value to the shift register), read (to return the value of the shift register), and whatever other processing you may want to do on that value.  The basic idea is that it gives you global storage in a subVI which can be called anywhere you'd like, just like a global variable.  The advantage is that you can also do some processing there, all modularized in your subVI.
 
 
I hope this helps!
 
Best Regards,
 
JLS
 

Message Edited by JLS on 04-03-2007 10:44 AM

Best,
JLS
Sixclear
0 Kudos
Message 2 of 2
(2,104 Views)