LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save files on Excel one time

Hi everyone

I made a program to read and save the Voltaje and current from a powersupply, but sometimes this program save more than one time

So I would like to know how can I make sure to only take one measure and save it?

 

Can you help me?

I attached the VI and file

Download All
0 Kudos
Message 1 of 4
(1,267 Views)

Let's review some things about your LabVIEW code.  First, you use a Frame Sequence, which is almost never needed, particularly if you correctly use the Error Line and Resource References (the "VISA" line) as you (correctly) do.  Interestingly, one of the few proper uses for the Frame Sequence until the VIM was introduced in LabVIEW 2017? 2018? was to force a "Wait on a Wire" like the 500 ms delays you've put between VISA Writes.  But if you look in the Timing sub-Palette, you can find the "Stall" VIM which "does the same thing" but doesn't need the big, ugly, obtrusive Frame.

 

Look at the first two Time Delays in your code.  Do you see that neither has any effect (in your code as it is written)?  Remember the Three Laws of Data Flow:

  • A Structure (or Function) doesn't start until all of its inputs have data.
  • A Structure (or Function) doesn't present any data to the Outputs until it exits.
  • If two Structures (or Functions) have no Output-to-Input wiring association, you can't say which starts (or finishes) first.

The last principle means, for example, that the 100 ms Delay inside the For loop runs at the same time as all the rest of the code inside the loop, particularly the Case Statement.  Note that the Case Statement has Delays of at least 500 ms.  So you have two Delays running in parallel -- 100 ms and 500 ms.  Because they are happening at the same time, the 100 ms delay has no effect (as the Case Statement starts at the same time as the Delay).  You can use a similar argument to say that the 100 ms delay just inside the Case Statement is running in parallel to code that has at least 2000 ms of delay (in the True case), so it also has no effect.

 

I assume you are concerned that all the Column 1 entries in the Delimited Spreadsheet File (which, by the way, is not an "Excel" file -- Microsoft Excel can open CSV files, and Windows decided to "assign" Excel as the default program for this extension.  However, it is not a .xls or .xlsx file (which are the "real" Excel file types).  You didn't specify a Time Format code, so it is showing Time as Hours:Minutes, but you probably want Hours:Minutes:Seconds (and possibly fraction-of-seconds).  Right-click the Function, choose "Help", read the detailed Help, and choose an appropriate Time Format string.

 

If you "do this yourself", you'll Learn LabVIEW faster and more thoroughly.

 

Bob Schor

 

Message 2 of 4
(1,246 Views)

Hello Bob!

I modified my code and now it's working and apparently it's taking only one measurement

Can you take a look?

I would like to do it the right way or more correctly

0 Kudos
Message 3 of 4
(1,225 Views)

I think the problem is configuring the Write Delimited Spreadsheet so that it allows you to do the following:

  • On the first time through the Loop, open a named file for writing, write one record, and close the file.
  • For all subsequent times through the Loop, re-open the (existing) file and write one record at the end of the file.

I don't (myself) use Write Delimited Spreadsheet too often, and I also don't write out a Time as a column.  So I did what I encourage you to do -- I wrote a little test routine to "play" with "Write Delimited Spreadsheet with Column 1 being the Time, and Column 2 was a known datum".

 

Here's what I created (not the first time -- I had a few errors, not everything worked, so this is the Final Result).  Note I'm saving it as a "Pure Picture" (not a Snippet, not runnable LabVIEW code, because "your assignment from me" is to create this for yourself, using LabVIEW Help for any function you don't understand, so that you learn about it).

Test CSV.png

 

Note that the Time Format specifier is (more-or-less) deduced from the Help for Format Date/Time String.  There (however) seems to be a bug (which I'm reporting to NI) -- there needs to be a space before the Hour format (%H), otherwise Hours is not reported.  Weird!  Note that I also made the delimiter ",<space>".  Both spaces (the one before the Hour, and the one following the delimiter) show up in the output file.  Try opening the .CSV file with Notepad -- it should open just fine, as it is an ordinary Text file.

 

See if changing the way you code your Write Delimited Spreadsheet in your code (after you write, test, and confirm that the code I'm posting here does "what you want") makes your code work to your liking.

 

Bob Schor

 

Bob Schor 

Message 4 of 4
(1,213 Views)