LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

program structure suggestions

I'm looking for suggestions on the direction to take with my program structure. The following is a description of the program operation:

 

  1. the default mode is an online/offline sequence. Online dithers around a set position of peak laser power for ~20 seconds. Offline moves off the peak laser power position for ~10 seconds. This sequence repeats continuously.
  2. the user can interupt the default online/offline sequence with one of the following:
    1. a linescan procedure that searches the entire range of positions for the peak laser power. This position is saved for the above online procedure. This procedure may take a minute or so.
    2. a calibration procedure that executes a series of individual actions. This entire procedure may take several minutes.

Where I get stuck is what happens if the users initiates one of the two procedures while in the middle of an online/offline sequence? I don't mind waiting for the online/offline sequence to finish before initiating one of the two procedures but how do I 'queue' the selection?

 

One idea I have is to use an event structure in a separate loop to update a flag variable. This flag variable is used to set the state of a case structure in a different loop. If one of the user selections is set it will switch the case. When the user procedure is finished it will reset the flag variable. The only problem with this is if the user initiates one user procedure and then the other one. The second procedure will be lost.

 

Any suggestions are appreciated.

 

Thanks

0 Kudos
Message 1 of 4
(2,465 Views)

Hi David,

 

I think I understand the question.  Have you used queues before?

 

I would suggest setting up a Queue similar to this: https://decibel.ni.com/content/docs/DOC-19186

 

One while loop will have an Event Structure with your two "procedures", wherein you can Enqueue any number of these procedures in any order, First In First Out (FIFO, how the Queues in LabVIEW automatically do things).

 

A second while loop will have sort of a state machine in it (see a simple example here: https://decibel.ni.com/content/groups/northeast-oh-labview-users/blog/2009/09/08/state-machines).  This will constantlytoggle between your Online and Offline states.  However, you can do a check at the beginning of each iteration to see if the previous while loop (above paragraph) had Enqueued any elements.  To do this, use the Get Queue Status VI and check to see if the "# elements in queue" output is greater than zero.  If so, Dequeue the next element (one of the two procedure types) and use a case structure to determine behavior of the system.

 

I hope this helps!  It may be confusing if you had not done Queues previosuly, but I think that the linked example is very good to learn by.

 

Best of luck and keep me posted on your progress.

Ryan C.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(2,430 Views)

Hi Ryan,

 

Thanks for the suggestion. I have not used queues before but have looked at them for my program. The task that I described in my original post is part of a larger program. Currently, I have a timed loop (producer) interacting with my DAQ cards and another timed loop (consumer) that will do unit conversion and display the data. I am using a functional global to pass data between the loops. This is why I looked at queues. I plan to add a while loop that will handle the tasks I described. 

 

Could I use the functional global in a similar fashion to queues? Perhaps set a flag? The FIFO ability of the queue is interesting.

 

Thanks,

Dave

 

0 Kudos
Message 3 of 4
(2,420 Views)

Hi Dave,

 

You can indeed use functional global variables (FGVs) to pass data between loops. However since they are non-rentrant, when an FGV is called in once location of the code, it is locked from being called anywhere else. This is why queues are used particularly with a state machine architecture, because they allow simultaneous read/write access from any location in the code. However, if I understand correctly, you simply need to set a flag, so FGVs are a good way to do this. For more information on FGVs, I recommend this article: http://labviewwiki.org/Functional_global_variable#Race_Conditions_and_Locking

0 Kudos
Message 4 of 4
(2,392 Views)