Multiple While Loops Write to One File

Hello,
I have three different instruments from which I am sampling, each at a
different sampling rate.  Each instrument is being sampled in its
own While loop.  How do I write all the samples I collect to a
single text file?  I would like something in the following format:
[Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
[Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
...and so on..
Thank you,
Olyvia

ofro wrote:
I have three different instruments from which I am sampling, each at a different sampling rate.  Each instrument is being sampled in its own While loop.  How do I write all the samples I collect to a single text file?  I would like something in the following format:
[Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
[Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
...and so on..
This seems like a flawed project.
If each loop samples at a different rate, the samples will arrive at different times. Typically there won't be a single timestamp for all three samples. Can you explain what you actually want to write to the file from each loop?
Do you want to write to the file incrementally inside each loop, or do you want to write everything at once after all loops have finished?
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Stop multiple while loops in Vision Aquisition

    Hi,   I want to close multiple while loops with one stop button. I'm using the Vision Acquisition software for recording from multiple cameras and I want to close this recording from all cameras simultaneously. Since I'm knew to LABView I don't know how to do this. I'll include my VI here and maybe someone can help me.  Thanks!
    Solved!
    Go to Solution.
    Attachments:
    Aquire Images 2 with Cameras.vi ‏410 KB

    A local variable should be enough for your implementation. Look at the following article:
    Stopping Parallel While Loops in LabVIEW With One Stop Button
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Starting stopping multiple while loops

    I have a rather large VI that runs multiple while loops with case strutures inside.
    I would like to be able to shut off and on the while loops programmatically depending on events.(cycle complete or cycle started)
    I need to store my measured data in a table but everytime I shut off the while loop  the data I gathered is lost.
    So it goes like this- measure analog voltage-put it in a numeric indicator...now I want to put in a table only once per cycle of my machine.
    If the opeator pushes the reset button the table is available for a report generation acquisition.
    Any help would be appreciated.
    Thanks
    Solved!
    Go to Solution.

    Do you want something like this?
    Attachments:
    Loop_Control_Multi.vi ‏109 KB
    Loop_Control_Multi_Demo.vi ‏177 KB

  • How to use one single boolean button to control a multiple while loops?

    I've posted the attached file and you will see that it doesn't let me use local variable for stop button, but I need to stop all the action whenever I want but more than one single button on the front panel would look ugly... The file represents the Numeric Mode of
    HP 5371A. thanks for your time
    Attachments:
    NUMERIC.vi ‏580 KB

    In order to use a local variable, you can change the mechanical action of stop button (Switch When Pressed will work), or create a property node for it and select values. You'll also have to do a lot of work changing those for loops into while loops so that you can abort them.

  • How do I store 4 hours of data and get them out of the "while loop" into a spreadsheet file for documenting purposes? "See additional Text for additonal info"

    What a have is a VI that uses the following SUbvi's, starts with FP OPENvi, then FP Create Tagvi, into a "While Loop" which contains a FP READvi outputting data into a INDEX ARRAYvi outputting to a Display (DBL). This shows the output of a FP-AI-100 monitoring a 9v battery. I have to monitor this battery for a 4 hour period my problem is storing the 4 hours of data and getting it out of the "while loop" into a "Write to Spreadsheet File vi" all I seem to accomplish is just one data sample which I get into a spreed ship file with no problem. I just can't get 4 hours worth. By the way this is my first VI and I'm sel
    f trained so have mercy.

    I figured it out Thanks.
    John Morris
    Glendinning Marine

  • Multiple DAQ Cards, Multiple While Loops

    I'm writing a code to support 3 small test stands that each have the same outputs and inputs as the others. I'm running them all off of an 8-slot DAQ. Each test stand has its own dedicated RTD Card and Analog Out card, but they all share a 32-channel Analog Input card.
    I'd like to decouple the 3 test stands as much as possible - if I have to take out an RTD card or Analog Output card, I don't want the entire LabVIEW program to stop running. I want to be able to keep running and logging data on the other two test stands if I were working on the other test stand. Is there a way to do this with only 1 cDAQ? Is it simply a matter of creating separate, independent while loops for each test stand? If so, would LabVIEW have issues with each while loop writing its own measurement file in parallel with the others?
    Thank You.

    Is it safe to assume you've been running the three tests?  Some of your post makes it sound like you've run them coupled while other parts make it sound like you haven't successfully had all three tests running simultaneously.
    If you aren't running them, are you using hardware timing (counters) for your tasks?  If you're looking to use counters, you're only using one per task, correct?  The cDAQ will only have four counters total to be shared between your loops.
    I can't remember off the top of my head if it is the task or the computer that reserves a cDAQ chassis.  I want to say it's the computer so you can run multiple tasks from the same cDAQ.  But, you'd still need to choose ctr0, ctr1, ctr2, etc in each task so that you don't share these resources between tasks.
    Are you looking to pull the shared module out frequently?  If not, are you gaining enough functionality to justify buying two redundant modules to gain decoupling?

  • How do we save three 1D arrays in while loop as an excel file? I used build array, waveform. I could not make it work.

    I have three separate 1 dimensional arrays in a while loop. I need to combine these arrays and save as a excel file outside the loop.
    My second question is that is there any emergency STOP button in Labview so that when I press that button, it cuts all the power going to the system. Thanks...

    Just a comment on the Stop button.
    It's not really a good idea to rely solely on a software emergency shutdown. Especially if the shutdown is to prevent some type of hazardous condition to the people running the test. The problem is that if your application or PC in general is having some type of problem, it may not be able to shut everything down as needed.
    You should always have a mechanical �Big Red Stop Button� that you can hit to cut power to everything. In addition to the button, I usually do have LabVIEW monitor things and if conditions are not looking good, have it automatically shut things down. This has always worked good, and I can�t remember any time I�ve actually had to use the big button, but it�s nice to know it�s there.
    VERY IMPORT
    ANT:
    Using the �Abort� button on the LabVIEW toolbar is NOT the thing to do. This stops your application where ever it is in its execution and does not allow it to finish or execute any shutdown code you might have put in. A �Kill� button on the front panel works well. I�ve put a single Boolean terminal in its own little While loop to monitor it. It usually writes to a digital line that�s holding a relay on that will cut the power.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Multiple while loops

    I have two while loops in my application which run seperately. The program looks as follows
    :   while loop 1           :       :  while loop2        :
    I want to stop while loop 2 as soon as while loop 1 stops. I tried to connect the stop condition of while loop1 to the stop of while loop2, but the loop stops immediately after one iteration. How to go about it.
    Regards,
    Giridhar Rajan
    Automation Engineer
    Cruiser Controls
    Mumbai, India

    The big concept in LV is dataflow - a piece of code will execute when all its inputs are available. When you connected the two loops you caused a data dependency - the data in the wire coming out of loop one will only be available when the loop ends. So what happens is that you run loop 1 and when you stop it, the T value goes over to the second loop, which only starts running now. Since it gets T, it stops after one iteration. You can see this if you turn on Highlight Execution (the light bulb button). There are several ways to go around this - the simplest is a local variable - right click the stop button and select Create>>Local Variable. You can change this to be read and put it in the second loop. You will need to change the mechanical action of the button and make sure you set it back to false. A more advanced method is the event structure.
    These are the basics in LV. To learn more, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide.
    Try to take over the world!

  • Can we run two while loops independently in one application?

    I am acquiring two channels using PCI-6052.both channels to be read at 2ks/s,but I want to scans read at a time different for each channel,So I put two AI-read vi's in two different while loops.but the second while loop waits until the first is completed.Can we run independently both while loops?

    Dear Haider Abbas,
    you can scan two different channels at the same time with the same AI Read if your hardware device is cabable of it, e.g. you must have one A/D converter for each channel. If you have one A/D converter only and your channels are multiplexed then it won't work.
    You can try running both loops indepentendly by using delays but in this case the data acquisition will not be at the same time. You have also to consider that every time you call for AI Read the DAQ card will be initialised with takes some time
    Hope this will help you.
    Stephan

  • How do you prevent display glitches with multiple while loops.

    I would like to use 2 while loops, 1 for displaying elapsed time and the other for executing a sequence of initialization steps. Every time the sequence transistions from one frame to the next, I get a glitch in the elapsed time display. How can this be avoided? Should I be going about this in a different way?
    Attachments:
    timeTest.vi ‏265 KB

    I would drop the whole semaphore thing and hold the cluster in a functional global (also called a shift register database or LV2-style global, you can find info on the concept here). Add methods to update different parts of the cluster. Much easier code and the required protection of the cluster is there.
    MTO

  • Writing multiple images to one file using ImageIO

    I am having trouble saving and reading multiple images from to/from one file. Here is the best i can come up with:
    //this is utilizing an ObjectOutputStream because i need to also save some objects to the file
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\images.dat"));
    oos.writeInt(ImageTable.size());
    for(int k = 0; k  < ImageTable.size(); k++)
        ImageIO.write((BufferedImage)ImageTable.get(k), "png", oos);
        oos.flush();
    //////////////////////////read function/////////////////////////
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\images.dat"));
    int size = ois.readInt();
    for(int k = 0; k < size; k++)
        ImageTable.add(ImageIO.read(ois));
    }What it seems to do is read the first image and then place the marker at the end of the file so each consecutive calls to reading the file end up in either null, -1, or an EOF exception (bleh). Does anyone know how i can do this properly?
    The code does run and saves something, although it is hard to tell exactly what it is saving since it is all in png format, it also loads the first image properly.

    Is it possible to pack the different images in one big image?Conversely, some image formats let you store multiple images in a single image file.
    Here's a demo. My results are that I don't have a gif writer, tiff can write sequences (this
    is a well-known tiff property), I can trick (?) jpeg into stroring multiple images and I
    can't get png to work: three images go in, one comes out.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.swing.*;
    import java.util.List;
    public class MultiImageTest {
        public static void main(String[] args) throws IOException {
            URL url1 = new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg");
            URL url2 = new URL("http://today.java.net/jag/bio/JAG2001small.jpg");
            URL url3 = new URL("http://today.java.net/jag/Image24-small.jpeg");
            BufferedImage[] images = {ImageIO.read(url1), ImageIO.read(url2), ImageIO.read(url3)};
            display(images, "original", 0, 0);
            String[] suffixes = {"gif", "jpeg", "png", "tiff"};
            int x = 30, y = 20;
            for(int j=0; j<suffixes.length; ++j) {
                String suffix = suffixes[j];
                try {
                    writeFile(images, suffix);
                    display(readFile(suffix), suffix, x, y);
                    x += 30;
                    y += 20;
                } catch (Exception e) {
                    System.err.println(suffix + ": " + e.getMessage());
        static void writeFile(BufferedImage[] images, String suffix) throws IOException {
            Iterator ws = ImageIO.getImageWritersBySuffix(suffix);
            if (!ws.hasNext())
                throw new IOException("no writer for: " + suffix);
            ImageWriter w = (ImageWriter) ws.next();
            File file = new File("temp." + suffix);
            file.delete();
            w.setOutput(ImageIO.createImageOutputStream(file));
            if (w.canWriteSequence()) {
                System.out.println("Using writeToSequence for format " + suffix);
                w.prepareWriteSequence(null);
                for(int j=0; j<images.length; ++j)
                    w.writeToSequence(new IIOImage(images[j], null, null), null);
                w.endWriteSequence();
            } else {
                System.out.println("cross fingers for format " + suffix);
                for(int j=0; j<images.length; ++j)
                    w.write(images[j]);
        static BufferedImage[] readFile(String suffix) throws IOException {
            Iterator rs = ImageIO.getImageReadersBySuffix(suffix);
            if (!rs.hasNext())
                throw new IOException("no reader for: " + suffix);
            ImageReader r = (ImageReader) rs.next();
            File file = new File("temp." + suffix);
            if (!file.exists())
                throw new IOException("no file: " + file.getName());
            r.setInput(ImageIO.createImageInputStream(file));
            List images = new ArrayList();
            for(int j=0; true; ++j) {
                try {
                    images.add(r.read(j));
                } catch (IndexOutOfBoundsException e) {
                    break;
            return (BufferedImage[]) images.toArray(new BufferedImage[images.size()]);
        static void display(BufferedImage[] images, String title, int x, int y) {
            JPanel cp = new JPanel(new GridLayout(1,0));
            for(int j=0; j<images.length; ++j)
                cp.add(new JLabel(new ImageIcon(images[j])));
            JFrame f = new JFrame(title);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(cp));
            f.pack();
            f.setLocation(x, y);
            f.setVisible(true);

  • Lost Document folder while moving one file? Need help!

    While attempting to move one file from my documents folder into Planbook the whole documents folder disappeared from the row icons on the bottom of the screen! Have had my MacBook Pro for a week and still find it confusing....not sure where document folder went but I need it! Hope someone can help!

    Open Finder, New Finder Window from the menu options, and look in your Home folder. Or under Macintosh HD/User folder.
    I take it from your description it is no longer in the Dock (row of icons at bottom of screen) where it usually is on the right hand side of that row.

  • Code golf: stop two while loops with guaranteed iteration ratio

    Proposal
    In the vein of the Perl tradition, I'd like to see if there's any interest in solving short programming puzzles in LabVIEW. Anyone can post a problem and define the rules for solving it.
    Here's a beginning/intermediate question to whet your "palette".
    Description
    With one user-action, how would you stop two while loops such that the ratio of their iterations is the always the same? One concrete way to visualize this situation is in taking measurements: two instruments use the same timing source to take measurements, but second divides the clock down so that it is an integer factor slower than the first. For example, if the slower instrument is four times slower, then at the end of the VI, if the slower instrument takes 100 measurements, the faster instrument has taken 400.
    Rules
    You may only use vi.lib
    You cannot include any other subVIs
    Your solution must pass for loop1 interval as low as 25 ms
    Template (attached in LabVIEW 2009)
    If folks are interested in this, then let's figure out how to make future problems better. Please post your suggestions and critiques, but only if you also post a submission ;-)
    Solved!
    Go to Solution.
    Attachments:
    Multirate Loop Code Golf.vi ‏11 KB

    Norbert_B wrote:
    a) You work with an integer factor of speed. While this matches many application areas, there are still cases where the factor has to be floating point (e.g. 2.5). Additionally, the factor might "invert", so the master loop runs slower than the slave (factor 0.5 for instance).
    It sounds like you're about to post another code golf question. If you think the problem scope is too small, you're welcome to fashion one to your taste. Thanks for volunteering :-D
    Norbert_B wrote:
    b) This example does not take into account that the hardware has to be synchronized with more accuracy than the software supplies (PXI?). If hardware synchronization is required, there are two possible ways:
    - The factor can be included in the synchronization (using PLL for instance)
    - The factor has to be software implemented by data reduction for the task running at the lower pace.
    Hrm, maybe puzzles aren't really your thing after all. You are correct: I did not define every constraint that can lead to a provable best closed-form solution, but that does not prevent people from stating their assumptions and forming creative, well-reasoned, and still correct designs. I overlooked this reading of the description and neglected to add a statement that said solvers were free to add their own conditions. I will do so in the fugure :-)
    If we choose the first of your suggestions, the VI must still retrieve the data at different rates. You can dedicate a loop for each instrument to decouple any jitter and latency introduced by their connectivity or internal operation; this adds some margin of safety when there is thread and driver contention. You can also implement a single counting loop like altenbach and forego the multiloop complexity.
    Norbert_B wrote:
    c) You don't state anything about "what happens with the data". Is this time consuming? Does it introduce additional delay in loop iterations? Is it OK to have data loss?
    I don't know -- you decide, you disclose, and you solve :-)
    In my specific situation, the measurements are time consuming and do add delay (each data "sample" is 5-20 megabytes), none can be lost, and the data must be available for others to analyze later. In addition, the amount of data is saturating the hard disk throughput. If a particular write takes too long, the instrument driver may overwrite a yet unfetched sample, which is unacceptable. I did not add these details to the problem discripton becuase they don't impact the puzzle.
    I don't want to burden people with my situation and ask them to solve my problem: I want to encourage them to bring their intuition and experience to a discussion. This is the design process at its heart: understanding why and how constraints affect your decisions. If a person states the additional conditions they've assumed, readers can learn why, and more importantly, when a Notifier might be more desirable than an Occurance or a Queue more robust than a Data Value Reference.
    The best NI-published advice for stopping multiple while loops (https://www.google.com/search?q=labview+stop+multiple+while+loops) is laughable (and is the "solution" in my template).
    Would you care to re-approach and contribute to this puzzle? I suspect you have a lot to offer :-)

  • Write to measurement file will not ask for file name once as selected.

    When using the Write to Measurement file Express VI.  I select "Ask user to choose file" and "Ask only once" with the intention that the data from each iteration simply be appended to the chosen file.
    I select "Run continuous" and the VI asks for me to choose a file repeatedly anyway instead of just appending the first file.  Selecting "Write to one file" properly appends data to the file specified in the box.
    Am I doing something wrong?

    DianeS wrote:
    Personally I can't figure out why that particular button even exists (I'm told it's occasionally useful for debugging).  
    I find it useful if I am creating a subVI that is supposed to be a part of another VI.  No while, loop just some inputs and outputs as a function.  If I want to test it out stand alone and try a variety of inputs, then Run Continuous and change the inputs, then I see immediate feedback on the outputs.  Once I'm satisfied its working right, then there is no need to clean up.  Just save it and drop it in the large VI as a subVI.
    Beyond that, I see no need for Run Continuous.

  • Keeping data on graph once while loop exits

    Hi, I have the attached vi where I am reading in Bluetooth data, plotting and saving the data. My inner while loop is the one performing the plotting, where I have the error out of the Bluetooth Read function wired to the boolean control of the loop. If for some reason the connection gets distrupted, the loop exits and the BT automatically reconnects.  The problem here is that one the inner loop stops, the graph plotting the data clears.  I am looking for a way to keep the data plotted on the graph, so once the connection is lost and reconneted again, the data continues plotting from where the connection was lost.  I cannot figure out how to do this, I tried to use local variables to plot the data outside the graph while the loop is running but that didn't work. Can somene provide me assistance?
    Attachments:
    test.vi ‏55 KB

    moderator1983 wrote:
    My bad...!!
    I was working late night and misinterpretate "Write to File" express VI with "Build XY Graph" express VI..!!
    Anyways the attached code should work fine.
    Here, I took care of some of your Rube Goldbergs.
    I'll try to get something written up to show a Queued Message Handler...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    I love clean code more.vi ‏53 KB

Maybe you are looking for

  • HP LaserJet 2840 not working with Leopard (Wireless Printing)

    I just upgraded to Leopard and my HP 2840 LaserJet Printer will no work. There is no Leopard driver and I have re-installed the software many times from the internet and from a CD. Im printing wirelesly with a Airport Extreme Base station (Last gener

  • Replacement panels for a G3

    Hi- can anyone tell me where I can obtain the plastic panels and corners for a g3? I'm trying to fix up my daughter's first Mac. Thanks- Ray

  • Reinstall of MV creates duplicates in /etc/services

    Another day, another stupid problem. Mac Server wouldn't reboot, went for an OSX install via a Diskmaker X USB boot drive. Server now reboots (for now) and get back in. As usual, /etc/services has been overwritten, as sshd was back on the default 22,

  • WRT54G.connection help needed

    so here is the problem,do not have great computer knowledge so i will try to explain in my terms. im presently online using my router although it does not connect automaticaly when turn my computer on.well it says that the internet is now connected a

  • Process Stopped while running BR-Backup

    Hi All, I am getting problem in while I am backup through BR-backup.... log in here Screen Shot here: http://www.flickr.com/photos/38842895@N04/4328933272/sizes/o/ I treid to find out Google, but I didn't get good answer... please advise Thanks angel