From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

START-STOP 2D scanning (with event and case structures)

Hello,

I would develop a VI for 2D scanning with two axes motor controllers (Thorlabs), in order to realize a numerical matrix. The scanning code is included in an event structure and it is selected by the choice of a string condition (case structure). Two bottons handle the start and stop of the scanning. 

Actually, the start and scanning code work correctly, but the stop botton doesn't work: pushing the stop botton the scanning code doesn't stop, but i must wait until completed scanning running.

I'm a basic user of LabVIEW, and I'm sure that I didn't initialize correctly the conditions for the 'stopping'.

Could you help me? 

How I can solve this problem?

 

Thank you

p.s. in attachment the VI.

 

0 Kudos
Message 1 of 2
(1,912 Views)

"Button".

 

You are abusing the event structure.  Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2016 Help

You have long running while loops inside the event case.  Based on LabVIEW data flow principles, until the while loops finish executing, the event case can't end, the outer while loop iteration can't end until it is able to go around again to handle the newly triggered Stop button value change event.  (If you turn on highlight execution, you'll see how dataflow works!)

 

You need a separate while loop with the event structure to handle the events.  Have that send messages to your worker loop doing the scanning.  A queue is the preferred mechanism and this is known as a producer/consumer architecture.

 

Also, try to avoid the stacked sequence structure.  A flat sequence structure is a bit better.  But in reality, you should be using a state machine architecture that proceeds from step to step.  Actually, if you set it up correctly, you can get by with a single loop for your program as long as your state machine frequently goes through a state (case of the case structure) that "checks for events".  Don't have while loops inside of while loops as it traps your code execution.

 

Also, you are abusing local variables.  In timeout event, case "1",  and flat sequence frame 4 you write to the IF Conditions the value of 0 through a local variable.  However you are also reading from the local variable and writing out a value to the tunnel.  I can guarantee the value gets read and transferred to the tunnel before a new value gets written to that indicators local variable.  In your initial frame where you initialize code, that should have the local variable.  The terminal belongs inside your main while loop.  The value should passed to the next iteration via a shift register.  Wherever you write to a local variable now, that should be wired out of the event cases, to the indicator.

0 Kudos
Message 2 of 2
(1,892 Views)