06-20-2022 01:42 PM
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
06-20-2022 02:56 PM
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:
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
06-20-2022 05:21 PM - edited 06-20-2022 05:24 PM
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
06-20-2022 08:28 PM
I think the problem is configuring the Write Delimited Spreadsheet so that it allows you to do the following:
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).
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