Stopping output tasks properly before exiting a For-loop

Hi,
I've been having some trouble exiting a For-loop conditionally. The problem is that when the loop is stopped conditionally (a button is pressed) the DAQ (NI USB 6353) outputs get stuck to whatever value they were in. I tried stopping the DAQ Assistant output task (1 sample on demand)  before exiting the loop but that didn't solve the problem. Should this perhaps be done one iteration before exiting the loop or can it be done in the same iteration round?
What would be the "right" way to exit a for loop with output tasks so that the output signals would be 0V after exiting? I know that I could "force" feed the DAQ Assistant with 0V control before exiting but in this case that would be quite difficult...
Any ideas? Help is appriciated.

Yes, I get it... However at this point I don't think that's an option.
Would this kind of solution work? ( I am not able to test all possible solutions in the real system which is why I would like to get a confirmation first)
The idea is to connect the output of the "Or" port to the "Stop" -ports of the DAQ Assistants in the loop.
Edit. Will the output automatically go to 0V if I just stop the task? I am not really sure about this.
Thank you.
Attachments:
exit-loop.jpg ‏8 KB

Similar Messages

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Can I exit a FOR loop before it has completed its iterations?

    Or is there a way to easily slave a while loop to an array input? I essentially need to search an array for a specific entry. Non of the built in VI's will search the array the way I need to do it. I tried wiring the array to a while loop and searching each element, but if the match is never found, the while loop never returns. Is there a setting on a while loop to force it to return if an input array completes?
    The For loop will work, but it forces me to step through the entire array each time and I have to play games to ignore values after I have found and set the one I need.
    Thanks for any help
    Chris

    Hello –
    I am attaching a very simple example program to show what Alberto and Dennis explained (or at least what I understood their approach would be, please apologize if I misunderstood).
    Another option is to use the Search 1D Array function, located in the Functions >> All Functions >> Array subpalette.
    Hope this helps.
    SVences
    Applications Engineer
    National Instruments
    Attachments:
    Example.vi ‏29 KB

  • How to output last 4 arrays from a For Loop?

    Hi People,
    I am almost at the end of my tether. I really hope someone could please help me.
    Any input would be welcome. VI attached.
    VI explanation:
    I initialize an array.
    The random number generator simulates my camera input.
    Depending on which iteration it is, the data is added into one of four output arrays.
    'x-y*floor(x/y)' gives a remainder value of 0, 1, 2 or 3.
    'Case Selector' just adds 1 to 'x-y*floor(x/y)' to get case 1, 2, 3 or 4.
    Shots 1, 5, 9 etc are added to Array 1 (Case 1).
    Shots 2, 6, 10 etc are added to Array 2 (Case 2).
    Shots 3, 7, 11 etc are added to Array 3 (Case 3).
    Shots 4, 8, 12 etc are added to Array 4 (Case 4).
    Averaged Output displays the averaged value i.e. the total value divided by the number of shots saved in that array ('Set (IQ+1)').
    My problems are:
    1) I would like to output only the last 4 sets of data from the Averaged Output 1, 2, 3 and 4 to 4 different files (i.e. save as .csv what is displayed onscreen in indicators 'Averaged Output 1', 2, 3 and 4 at the end of all iterations.
    Where should I place my file save diagram disable so that it does this?
    Putting it outside the main For Loop with auto-indexing on gives me one file with all previous data. (This is not feasible as my number of shots should number in the thousands)
    Putting it outside the main For Loop with auto-indexing off gives me only the last set of data. (I need the output for 4 Arrays, not just the last run)
    Putting it inside the main For Loop (as shown) gives me the same number of files as number of iterations. (Again not feasible due to large number of files that will be generated and slow camera capture)
    For the sake of fast camera capture, I would like these 4 files to only output once all the image captures are complete.
    2) Would preferably like to name the file once and for the programme to append '(1)', '(2)', '(3)' and '(4)' to filename of the appropriate 'Averaged Output' Arrays but file path controls are another big headache for me.
    3) P.s. is initializing one array enough to avoid using Memory Manager? Or should I initialize 4 arrays?
    I am using Labview 2010.
    Thanks so much,
    Jaslyn
    Solved!
    Go to Solution.
    Attachments:
    Help Understanding Arrays and file paths (10).vi ‏26 KB

    Thanks so much Lennard!!
    Hi JKSH,
    I've been busy trying to complete the dang code, but for completeness so that other users can learn too, I shall answer your queries. Thanks for looking in.
    First, what do you mean by "add"? Your code in your case strcuture sums your input values, so your array size doesn't change. However, you also said "Putting it outside the main For Loop with auto-indexing on gives me one file with all previous data. (This is not feasible as my number of shots should number in the thousands)" -- it sounds like you are expecting an array with thousands of elements. So, what should "Output Array N" look like?
    Ans: Output Array N should be a 4x4 array of the summation of all the numbers generated during every 4th iteration.
    i.e. if random number 1=1, random number 2=2, etc, And 'No of iterations' is 12,
    Output Array 1 should be 1+5+9:
    15 15 15 15
    15 15 15 15
    15 15 15 15
    15 15 15 15
    (Note: Most of your arrays are 4x4, but in Case #2 you created 128x128. I prersume this is a typo?)
    Ans: Kind of, I'm using a 4x4 array of randomly generated numbers as an example but my actual data will be the 128x128 pixel output of a camera. And during actual experimentation, 'No of Iterations' will number in the thousands.
    Second, why do you add your "simulated camera input" to the "Initialized Array"? You can add it direcly to the previous output inside your case structure.
    Ans: See answer to question 3
    Third, have a look at shift registers: http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm. Use them instead of Feedback Nodes to make your code tidier.
    Ans: I did try.. But I can't seem to add shift registers to the case structure, only the for loops outside. Are you sure it can be done..?
    jaslyn wrote:
    1) I would like to output only the last 4 sets of data from the Averaged Output 1, 2, 3 and 4 to 4 different files (i.e. save as .csv what is displayed onscreen in indicators 'Averaged Output 1', 2, 3 and 4 at the end of all iterations.
    Where should I place my file save diagram disable so that it does this?
    For the sake of fast camera capture, I would like these 4 files to only output once all the image captures are complete.
    You will need to call "Write to Text File.vi" 4 times to write 4 files. So, you should finish your loop, then call this VI 4 times.
    Ans: How do I get it to extract the data from each of the 4 cases in my case structure?
    jaslyn wrote:
    2) Would preferably like to name the file once and for the programme to append '(1)', '(2)', '(3)' and '(4)' to filename of the appropriate 'Averaged Output' Arrays but file path controls are another big headache for me.
    You can create strings first, then convert them into paths: http://zone.ni.com/reference/en-XX/help/371361G-01/glang/string_to_path/
    Thanks
    jaslyn wrote:
    3) P.s. is initializing one array enough to avoid using Memory Manager? Or should I initialize 4 arrays?
    I'm not sure what you're asking; can you please clarify what you mean by "avoid using Memory Manager"? But anyway, you've actually initialized FIVE arrays: 1 outside the loop, and 1 inside each case.
    I've read that to avoid fluctuations in memory usage, it is a good idea to initialize arrays to their expected size before the start of data collection. That was just what I was trying to do.

  • How do I exit a For Loop? Just Kidding! VISA and LVRT and App

    Builder/Installer. Hi,
    I am using LV6i and App Builder. I built a little program using the
    VISA Config, Read Write, and Bytes at Serial port vi's.
    I attached the build file also for ref.
    [Image]
    When built using the option to include the run time engine then
    installed on a laptop, I get an illegal operation in lvrt.dll.
    I have tried to install VISA on the laptop but this makes no difference.
    I am new to VISA so any help is appreciated.
    Thanks in advance for any help.
    [See first answer for additional information]

    [Attachment(s) for question]
    Attachments:
    Simple_Terminal.bld ‏2 KB

  • Stopping a For Loop, part 2

    Hello. Thank you everyone for your help, getting to this point. I asked for help to create a stop condition, while a For Loop is running. I was given many ideas and selected the one that used local variables. It works well however, if I am in the "Test in progress" state, in the first For Loop, and the "Stop" button is selected from the front panel, when it stops the Vi, it sends the value "5" to the second For Loop before going to the "End" state, which puts it to "0", then stops the Vi. What this Vi is doing is feeding 0-200VDC signal to an eddy current sensor, then it feeds 200-0VDC going the other direction. I have tried sequencing, putting in timers and a few other goofy things but I can not get the Vi to stop in the first For Loop, without the Vi performing the initial "5" to the second For Loop. Someone had mentioned using an event handler, in my previous post. I practiced for quite some time, trying to understand how to use an event handler but am not much the wiser. Any and all input would be greatly appreciated.

    altenbach wrote:
    ceilingwalker wrote:
    You are autoindexing way too many thing between the two FOR loops I was doing this to create a data dependency, at least that was my thought process behind it. As far as the physical channels and VISA refnums, I did it this way so I didn't create more controls for the front panel. Being my first project, I am very certain my logic is flawed, this is why I like posting here and getting feedback from
     You have many visa sessions that (hopefully) never change during the execution of the loops, so why woold you turn them into an array of 11 identical elements just to autoidex them out again at the next loop. Change the tunnels to no autoindexing and things would look cleaner. Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results?
    Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!!
     If you don't want the second loop to run when the first one is ended prematurely with the stop button, put it in a case structure I tried a Case structure for the second For Loop. I couldn't find a way to change conditions that didn't affect the Vi's overall performance.
    Then show us what you tried! That should be trivial to implement. Why would a case structure affect performance? Makes no sense!
    Why would a case structure affect performance? Makes no sense! I used a boolean operator to change the state. When I used a false, it worked for that problem but shut down my Vi before the second For Loop. 
    Wounld't it be easier to simply create an up&down ramp once and use a single FOR loop, autoindexing on the ramp? You have way too much duplicate code!!!  I tried using one For Loop to begin with but because I had to ramp up, then ramp down, I couldn't figure out how to use just one. I needed an Add function for the ramp up and a Subtract function for the ramp down.
    Why are these session controls inside the loop? Are you expect them to be changeable during loop execution or would that screw up the results? No Sir, the values are not changed during operation. I did this because I wanted it to display the data on the front panel, during operation of the Vi. For display only.
     

  • For Loop exits prematurel​y - Arrays and Shift Registers

    I have attached some preliminary code (work in progress) for the RC4 encryption algorithm. For some reason the middle for loop exits prematurely. In other words it exits after 2 iterations instead of the 256 iterations that N is set to.
    I thought this was not possible and therefore I am presuming I have made some not so obvious error in attempting to use a shift register with an array.
    Please have a look. Thanks.
    Attachments:
    RC4 Encryption beta.vi ‏78 KB

    You misunderstand how a for loop operates. You can either wire a number to the N terminal or you can wire an array into it with auto-indexing turned on. With an array input, the for loop will iterate equal to the size of the array. When you wire both (a practice I do not recomend), the for loop will iterate to whichever is smaller - the array size or the N terminal. Both of your for loops on the left side is creating arrays with only two elements. I suspect that what you need in both of them is a shift register instead of exiting the for loop with auto-indexing turned off.

  • For loop, possible to increment counter/exit loop?

    I would like to know if it is possible to exit a For loop. I know
    I can use a while loop but it would be nice to be able to
    increment the loop counter in a for loop. Is this possible?
    Thanks,
    Mike

    Jim,
    OK, that clears it up. Coming from VB I'm still figuring out the
    differences.
    Thanks,
    Mike
    James Morrison/Joan Lester wrote:
    >
    > Also remember you can make while loops auto index. Right pop on the tunnel
    > and enable this and the loop will then act more like a for loop.
    >
    > Jim
    >
    > "Kevin B. Kent" wrote:
    >
    > > Mike Scirocco wrote:
    > >
    > > > I would like to know if it is possible to exit a For loop. I know
    > > > I can use a while loop but it would be nice to be able to
    > > > increment the loop counter in a for loop. Is this possible?
    > > >
    > > > Thanks,
    > > > Mike
    > >
    > > No sorry it is not possible.
    > > If you need this kind of functionality you will have to use a while loop.
    > > You can then setup all manner of conditions to exit the lo
    op.
    > > Be aware that the loop will always run at least ONCE.
    > >
    > > A for loop will run X number of times. This is determined either
    > > at compile time (if the count is hard coded) or at run time
    > > (if you use auto-indexing, or the count is a variable).
    > >
    > > Kevin Kent

  • PNA Guided Calibration: GPIB write error in for loop

    Hi,
    I have a LabVIEW program that creates a Guided Power Calibration on a PNA.
    After initializing everything properly, I have a for loop that loops through all the manual steps that the user must go through (ex: Connect Channel A of Power meter to Port 1" "Connect male Short to port 1" etc).
    The problem is, the program displays an error at the first command: sens:corr:coll:guid:acq STAN1
    I says there is an error with the GPIB Write function.
    Here are the commands I send:
    SYSTRES
    DISPlay:WINDow2TATE ON
    CALCulate2ARameterEFine:EXT 'MyMeas',S21
    DISPlay:WINDow2:TRACe1:FEED 'MyMeas'
    CALC1AREL 'CH1_S11_1'
    SENS:FREQTAR 2e9
    SENS:FREQTOP 4e9
    SENSWEOINTS 3
    SENS:CORR:COLL:GUID:CONNORT1 'APC 2.4 male'
    SENS:CORR:COLL:GUID:CONNORT2 'APC 2.4 male'
    SENS:CORR:COLL:GUID:CKITORT1 '85056D'
    SENS:CORR:COLL:GUID:CKITORT2 '85056D' 
    SENSe:CORRection:COLLect:GUIDedSENsor1 ON
    SYSTem:COMMunicateSENsor gpib, "13"   
    SENSe:CORRection:COLLect:GUIDedSENsor1OWer:LEVel -20
    sens:corr:coll:guid:init
    sens:corr:coll:guid:steps?
    //for loop from 1 to total_number_of_steps
    sens:corr:coll:guid:desc? <step#>
    sens:corr:coll:guid:acq STAN<step#>
    The program quits right at the first step, when I send "sens:corr:coll:guid:acq STAN1", although the command is executed.
    Also, the VBScript with the same commands works fine.
    Can anybody help me? I've been stuck for a while now.
    I attached the block diagram of the for loop.
    Thanks in advance,
    Nicolas
    Attachments:
    Guided cal for loop.vi ‏27 KB

    Sending SENS:corr:coll:guid:acq STAN1 \n gives me a different error: -101 "Invalid Character".
    From my different attempts at figuring this out, I thought the problem would come from LabVIEW, since the vbscript with the same commands works on the PNA.
    I also modified the for loop because I thought each iteration should be linked to the previous one with the error wire (see attached).
    I still have the same issue, only the first iteration is executed, then the program quits.
    Attachments:
    Guided cal for loop.vi ‏28 KB

  • How to skip for loop execution

    Hi all,
    How to skip execution of for loop , if one particular condition is satisfied within that loop .
    I know that we can use exit within for loop to come out of for loop, please let me know if there is any other approach .
    Thanks,
    P Prakash

    BluShadow wrote:
    11g (new feature) - it is called the CONTINUE statement.Blergh! it's horrible. May as well use a GOTO.... :{noformat}/{noformat}Hehe.. Yeah - it essentially creates another exit point in the loop, except that it falls into the top of the loop and not out of the bottom.
    So in that respect, the EXIT statement ain't much better. {noformat} ;-) {noformat}
    Personally I don't think it that bad - could be useful for very tight loops where you want to cut down machine code to the absolute minimum. But then why would one ever write such a loop in PL/SQL?
    Reserving judgement on this one for the time being. I very very seldom have used a continue or skip instruction in programming... As far as I recall - only in bash shell scripts.
    So yeah, I would like to see the code and justification for that code using the CONTINUE statement. There always could be The Real And Seldom Seen Bigfoot-like Exception that justifies using that statement... {noformat} :-) {noformat}

  • Zero iteration for loop

    Hi folks,
    There's an old behavior that I'm pretty used to, but it still occasionally bites me (usually with references).  It happened again today, and it got me to wondering if it's really intended behavior.
    If you pass a value into a zero iteration for loop, then send it out the other side, the value exiting the for loop is returned to default, not the value you fed in (see simple.vi, LV7.1).
    Any ideas?
    Joe Z.
    Attachments:
    simple.vi ‏11 KB

    This is expected behavior...the workaround is to use shift registers to pass the value through instead of tunnels.  I believe this is discussed in the LabVIEW Help.
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • How to send trigger pulse for every 0.25 sec until user stops the task?

    Hi All,
    Iam using NI_DAQ PCI 6221 Card for the Data Acquisition.
    Can any body please tell me how to send trigger pulse for every 0.25 sec until the user stop the task??
    Please suggest me the methods I should use to meet this requirement.
    Thanks In Advance,
    Sindhu

    Hi Sindhu,
    Am I correct in thinking that you do not want to use your 6221 to output a digital pulse, but that you are getting a digital pulse from somewhere else that you want to use as a trigger for the analog input?  And you will have more than one trigger?  If this is the case, then it can be accomplished by doing a retriggerable operation.  The way that this works is you use the counter on your board to generate the sample clock for your analog input because analog input cannot do retriggerable operations with its own sample clock.  You can modify the example GenDigPulseTrainContinuous_DigStart that is in the same location as the example I referenced before to be retriggerable by using the property DAQmxSetStartTrigRetriggerable.
    After doing that and testing to make sure that it works, you can setup an analog input task like the example ContAcqVoltageSamples_IntClk but specify the source of the sample clock to be the internal output of the counter you used in the counter portion of your program.  If you need help with the terminal names (You will need to use Ctr0InternalOutput for example), you can reference the NI-DAQmx C Reference Help at Start >> Programs >> National Instruments >> NI-DAQ.  After doing this, you will acquire the same number of samples as the number of pulses you choose to generate in the counter portion of your code every time a trigger is received.
    Also, I have come across an example that does retriggerable analog input using the counter as a sample clock in C++.  Either by using this example or modifying the shipping examples as I stated above you should be able to achieve what you are trying to do.
    Let us know if you have any questions.
    Thanks,
    Laura

  • Whenever you try to save a PDF file to a location other than the default location ('My Documents'), Firefox freezes & you have to go to the 'Task Manager' to exit Firefox and stop the error, so you can load Firefox again.

    Whenever you try to save a PDF file to a location other than the default location ('My Documents'), Firefox freezes & you have to go to the 'Task Manager' to exit Firefox and stop the error. I have Windows XP (Media Center Edition) and all updates (Firefox, Adobe PDF, Microsoft, virus protection, etc) are installed. This has only been a problem since Firefox 4, and isn't a problem in Internet Explorer.

    Hi David,
    Thank you for your detailed question. It sounds like the real issue is pdf files. Are there any antivirus/firewalls that might be blocking this specific file type? or are there any preferences in your control panel that might be blocking this?
    Do you have any stored preferences for PDF files in Firefox?
    *[[Applications panel - Set how Firefox handles different types of files]]

  • HT3209 why does my movie rental download stop and reload just before it completes the download. I've tried 4 times now after waiting hours for the download. Ugh!

    why does my movie rental download stop and reload just before it completes the download. I've tried 4 times now after waiting hours for the download. Ugh!

    This Apple article might help ya out -> iTunes Store: "Error (-50)" when downloading purchased content
    Try following along with the article and deleting the cached downloads, then try again.

  • How to detect window close event and do some task before exiting

    Hi 
    Anyone knows how to detect window close event and do some task before exiting ?
    Sridhar
    Solved!
    Go to Solution.
    Attachments:
    window close event.JPG ‏34 KB

    Yes .You can discard the panel close event by passing "TRUE" boolean value to the "discard ?" terminal which is lied in the right side of that panel close(filter) event.& It will work in executables.  See attached picture.
    Attachments:
    Panel Close.JPG ‏12 KB

Maybe you are looking for

  • Link in lotus notes to view SAP document

    Dear All, I have implemented the Z workflows through which I am sending the notification to all the cost centers mentioned in the invoice through rule(Agent determination:Function to be executed). This will cause notification to be sent to SAP inbox

  • Attempting to apply Patch 5639232 to 10.2.0.2 client

    When the client was installed, OPatch was not installed. Patch will not install without OPatch. Has anyone experienced this problem? How did you work around the missing OPatch?

  • Error in posting Inventory documents for a serialized material

    hi., Can someone update me the reason for: 1. Error in posting inventory documents for a serialized material What are the steps to be followed during the 1. Creation of Serialized material 2. Creating a Purchase document for a serialized material 3.

  • Error in itunes store, msn messenger, and software update

    hello, i seem to have a problem since someone changed my proxies settings for the internet. My internet browser works just fine and I can download stuff from the internet. But, neither Msn Messenger, nor iTunes store, nor Software Update are able to

  • Sharing custom preset local adjustment brushes between 2 computers?

    As I start to do more and more of my work in either Lightroom 2.2 or ACR, I'm creating "preset" local adjustment brushes. I run on a desktop and a lap top. Is there a way to copy and move the new preset brushes from one computer to another? Asked ano