LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed loops with visa

Solved!
Go to solution

Hi, i am new in labview and i need some help.

 

I have a microscope shutter that is controlled by VISA.

 

I want this shutter to open for X milisecs (eg. 100 msecs) and then close, wait  W secs (eg. 3 secs ) until it opens again wait the same X milisecs until it closes again and wait W secs again and so on . And I want to repeat this cycle Z times (eg. 100 times). I use shift operators in a time loop but I can not stop the loop in the middle of the operation. 

 

thanks,

 

carlos

0 Kudos
Message 1 of 6
(2,501 Views)

What you want to use is a state machine architecture.  You'd essentially have 3 states that would be open shutter, close shutter, and wait.  In shift registers, you'd pass your iteration count and whether you are currently open or closed.

0 Kudos
Message 2 of 6
(2,495 Views)
Solution
Accepted by topic author carlosgarzon

Hi Carlos,

 

As Raven suggested would indeed be the way to go.  I've attached a first draft of that thing with the needed documentation.  If something is not clear, don't hesitate to ask.

 

ShutterStateMachine_Snippet.png

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 3 of 6
(2,483 Views)

hi guys,

 

thanks for the help. i am still confused with one aspect. I want to start that process only when a button is pressed (a boleam) and stop it if the button is again pressed to the stop state or if the stop button is pressed. I put your code into a event structure but somehow i cannot stop the loop once this has started.

 

Howe could I just initiate the proces and stop it any time i want ???

 

sorry i am just a biologist trying to work with microscopes and my background in signals, equipment, programin etc is very limited !!! ooops  🙂

 

 

0 Kudos
Message 4 of 6
(2,459 Views)

I realized that it is better if I show you my complete VI.

 

I have a microscope shutter that is controlled by VISA. I am should be able to open or close manually with the panel on the left side (That is working) or I should be able to initiate a cycles and i am doing that with the right panel. If the number of cycles is reached the process should stop (that is working as well) the only problem is that is nor reseting to 0 the number of cycles and is letting the shutter open (but i guess i could solve that by my self). But if I want to stop in the middle of the process with the "stop" button on the right panel i can not do it (THAT IS NOT WORKING). somehow the event structure does not allow me to stop the loop until it finished. and i need help for this part.

 

I copied-pasted your VI in my VI. And the boolean is for now indicating if the shutter is open or close (I have not yet conected the VISA with your VI)

 

sorry for so many question, but this programing in labview is driving me crazy and in my lab there is no people that could really help me.

 

cheers,

 

carlos

0 Kudos
Message 5 of 6
(2,443 Views)

I don't have the time to be able to help you untangle the code.  But I can tell you where you are having problems.

 

1.  Embedded event structures.  You actually have event structures inside of loops inside of event structures.  Even if an event structure is not currrently in the line of execution, it is still queueing up any events that occur.  That is going to cause all sorts of unpredictable behavior.  Particular with the Stop Value Change event which is in both the inside event structure and the outer event structure.

 

2.  Loops inside of event cases.  If you have a loop inside a particular event case, your code is going to stay running inside that case for a long period of time.  That is going to make any other user interactions seem unresponsive because the event structure is not going to be able to handle these events until the current event case completes.  An event case should not take any longer to run than the amount of time the user could tolerate an unresponsive application.  That means the event case should probably be done in a second or less.

 

3.  Lock front panel until event case completes.  Your outer event structure has this checked for the Stop Value Change event.  That means the front panel won't react to any sort of button presses and will basically be locked.  Going back to #1, the front panel will not unlock until the structure of your code ends the other cases it is in and the line of execution gets back around to executing the Stop event in the outer most case structure.  It is very possible that you get yourself into a deadlock and that may never happen.

 

You basically need to flatten out your architecture and eliminate the embedded event structures and loops inside of event cases.

0 Kudos
Message 6 of 6
(2,436 Views)