LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Homework question help

Hey everyone, 

 

I am having trouble with a homework problem. The question I am doing is asking to create a VI that logs a time-stamped numeric value to a spreadsheet file whenever a Save button is pressed.

The issue I’m running into is with file handling: my VI only works if the specified file already exists. I need to make sure the VI can also create the file if it doesn’t exist, but I’m not sure how to do that properly. Looking to get some pointers / some help with how to do this if possible.

 

Any help is much appreciated!!  

 

TIA 🙂

 

(Note: Saved for LV 2016 + screenshot of block diagram) 

Paddle_to_the_sea21_0-1744154606288.png

Paddle_to_the_sea21_1-1744154614521.png

 

 

0 Kudos
Message 1 of 4
(372 Views)

Did you know that LabVIEW ships with a bunch of "Examples"?  Open LabVIEW, click Help, click "Find Examples".  You should be able to find a few that will give you some ideas.  Also, if there is an item on a Palette, say the "File I/O" Palette, whose function you don't know, drop it on a Block Diagram, right-click it and read its "Help" entry.  Pay attention to the Examples it suggests.

 

Have you talked with your Professor, or fellow students?  Things you work out for yourself will "stick" with you longer.

 

Bob Schor

0 Kudos
Message 2 of 4
(343 Views)

Hello,

first things first: your while loop hasn't a time control. This consumes a lot of CPU. Connect the iteration variable to an indicator and have a look how it grows o_O. 

Actually, although your code can be improved and simplified, it works fine even if the file doesn't exist (I also added the time control). 

 

Improvements: think about putting your code in an event structure.

0 Kudos
Message 3 of 4
(325 Views)

There is plenty wrong with your VI.

 

  • You already do a "open or create", but if the file is already locked by another application (e.g. open in excel), you won't be allowed to open it. Similarly, of you enter a folder path instead of a file path or many other potential errors. Typically you should open the file once before the loop (or better in an init state of a proper state machine) and then just write to it as needed. Close the file after the loop ends. Use a file dialog. You can write the header once, right after opening. No need for another case structure.
  • Your counting shift register is completely pointless. All you need is one case structure triggered by the save button. Counting should also be done in blue, not orange.
  • All your formatting only needs to be done when you append to the file, and not with every iteration of the loop.
  • For relative times, all you need is the difference between two high resolution relative timers, which is already DBL. Dragging along time stamps is clumsy.
  • Connect an indicator to the iteration terminal and you'll see that your loops spins millions of times per second doing basically nothing useful. It should not spin faster than the fastest possible time to press the button. So place a reasonable wait (e.g. 100ms) to prevent your computer from overheating!
  • The path should not change during the run (else the new file won't have a header!) so that control should not be accessible.
  • It should not need three concatenate strings and two formatting operations to build your string.

 

altenbach_0-1744219264702.png

 

 

 

0 Kudos
Message 4 of 4
(301 Views)