Jump to content

Stopping while loop


Recommended Posts

Hi all,

We built a labview program to control a triaxial scanner. There is a subVI that initializes an automated scan, which means it calculates steps in the X and Y direction depending on the dimensions you enter.

First we used a for-loop inside a for-loop to move first a few times in the X-direction, then change Y, move in X-direction again etc...

Now we have to be able to stop the scanner at anytime. As I read in this forum, a for-loop can't be stopped until it reaches the final iteration. That's why we changed this to a while-loop inside a while-loop.

Unfortunately this also doesn't seem to work. Activation of the stop-button is always ignored (not seen). Probably this has to do with the fact some subVI's are executed inside the while-loop.

Is there anyway of jumping unconditionally out of these while-loops (without terminating the program and labview that is)? We thought about event structures but this doesn't seem to work either...

regards

Filip

Link to comment

Thanks for the replies.

In attachment I put the code as it is. We do not have labview 8.5 (yet).

We did break the while-loops in the subVIs by using references to the stop.

Probably you won't be able to execute the code without the external equipment, but maybe you can have a look at it as it is.

regards,Filip

QUOTE(Aitor Solar @ Nov 20 2007, 10:36 AM)

The stop command should be detected even if there are subVIs (but the loop won't stop till the end of the iteration). Could you post the code, in a simplified form?

BTW, in LV85 you can stop a for-loop too.

Saludos,

Aitor

Link to comment

I addition to what Ton said, in the code you're not breaking the inner while loops. I'm not sure what's your goal, so:

1) If you want to check from an inner loop if the stop button have been pressed, you can use a local.

2) If you want to check from a running subVI if the stop button have been pressed, you can use the reference, but is probably better to implement some kind of communication as queues.

Hope that helps.

Saludos,

Aitor

Link to comment

We have tried using the for loops, but doesn't the problem remain the same then.

The reason for using string controls is they are used as a string to send commands to our CNC controller.

I can't answer you regarding the code used there, it is written by my student, i am just helping him out where he gets stuck :) . Seems like it has something to do with adding more controls that perform a certain action.

But we are trying out some of the hints you gave us right now.

Link to comment

The code after the button start measurement is placed because earlier I had more start buttons.

But now to the point. The two while loops in the code I sent to you are loops which where originally for loops. So, I thought: I'm gone replace them by while loops

so that it is possible to step out of the loops. Because, when using the for loops I had exactly the same problem. After replacing them I saw that the problem wasn't solved.

This program is written for a stepper motor controller and a receiver. The program you see is made to scan every point of a given surface with an adjustable step. At each point

the motors have to stop and a measaurement must be made. For the measurement another subVi is called. With the "reference" I made of the button 'stop measurement'

it is possible to step out of the subVi. But then comes the big problem: There will be a motion to the next point and a measurement starts again, thats because I can't step

out of the while loop.

One of the other remarks of you is that i didn't use numeric values: This is a good remark, but the controller reads the code which is sent to it in string format. And so...

My question to you: Do you see a solution to completely stop the masurement. With other words to step out of the while loops.

regards,

Sacha

Link to comment

QUOTE(Phantom Lord @ Nov 20 2007, 04:35 AM)

My question to you: Do you see a solution to completely stop the masurement. With other words to step out of the while loops.

regards,

Sacha

I haven't looked at your code, but in theory, you could replace while loops with timed loops and use "Abort timed loop" to step out of it.

Neville.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.