LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loop question - beginner user

Basic question about loops:

I am new to LabView and have written the attached simple VI to read data from a serial port.  I have attempted to add a loop that will save data to a file if activated, however when it is activated, it seems to open a dialog box evertime the loop cycles, not just once.  I am having trouble visualizing where this loop should be located to avoid this problem, and I am interested in knowing why the program behaves this way as written (not just in a fix, as I am learning the program and will get much more involved...).  Any comments would be appreciated and in the meantime, I'll busy myself with some tutorials and try to stumble upon the answer myself.
0 Kudos
Message 1 of 9
(3,978 Views)
What type of dialog are you getting? I modified your VI a bit so that the serial acquisition is inside the while loop and don't get any dialogs. If you were running this with the "Run Continuously" button, that might have been the cause. You shouldn't use this option normally. Here's the modified VI. If you still get a dialog pop-up, post back with details on what it says.
0 Kudos
Message 2 of 9
(3,966 Views)

If you change the mechnical action of your boolean so that it does not latch, then the boolean value will revert back to False after cycling the save one time (see attached JPG).  You get there by right clicking on the Boolean.  Additionally, if you want to continuously read your device, then you will need to 'wrap' you while loop around your device read as well. 

Hope this helps.


Paul
0 Kudos
Message 3 of 9
(3,956 Views)
Thank you Dennis, those modifications helped with other quirks, but not the dialog about which I was posting. 

That dialog appears if the text box containing the file path is left blank.  According to the subVI, when blank, it will open up a standard file browsing dialog box.  When I select a file, and click OK, it saves a single data point, and then it reopens the dialog box.  Interestingly, when I type a file path in to the text box before telling the program to save the data, it saves data smoothly.  It probably is caught in the same loop, but the answer is obvious to the computer because the file name is already typed in for it. 

So remedying this problem would simply make the VI more user friendly - but it works as is as long as a file path is typed in by the user.  I'd still appreciate any input anyone may have.
0 Kudos
Message 4 of 9
(3,955 Views)
Not the most elegant solution, but a simple one.  Put a local variable for filepath on the output of the save VI so that the control gets updated.
 
See modified example

Paul
0 Kudos
Message 5 of 9
(3,937 Views)
After the first time through the loop (when you get the file dialog) put the File Path output from the file write VI into a shift register (right terminal). Inside the loop wire the left terminal of the shift register to the file path input of the file write VI. Outside the loop initialize the shift register with your predefined file name or an empty path if you want the dialog. The shift register will keep the file path available to the VI until the loop is stopped.

Lynn
Message 6 of 9
(3,934 Views)

My first thought was the shift register, but I believe we are not seeing everything, and to a new person, shift registers can be difficult to get a grasp on, especially as the application grows and you have to start carrying the shift register through lots of case structures.  BUT it is the most appropriate way of solving the problem. 

That being said, it is not good programming practice to use local variables everywhere, but as you are a self-proclaimed newbie, I thought it might be the simplest to get a grasp on.

Attached is an example using the shift register with one method to do it.   I also took the liberty to adjust your time calculation to calculate from the start of testing, otherwise it will almost always be zero of close to it. 


Paul
Message 7 of 9
(3,925 Views)
Thank you for all of the information.  I have fixed the problem with the shift register although you are all right that it seems a bit abstract to me as a beginner.  I will be doing a lot of this type of programming so I don't want to form bad habits.  Again, thanks for all the suggestions, and hopefully my next post will more advanced, although I don't think I'll be posting responsed any time soon.

Smiley Wink
0 Kudos
Message 8 of 9
(3,895 Views)
Hopefully you got some good tips and heck the advice is free,  thats what we are all here for.

Paul
0 Kudos
Message 9 of 9
(3,880 Views)