From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

low-level file I/O functions

Solved!
Go to solution

I'm trying to develop a VI that 

  1. generates random numbers at a given frequency 
  2. convert numeric data into strings 
  3. store the loop iteration time and random numbers to a file using low-level file I/O functions. (write to text, open and close)

I've attached my VI along with the output I want to obtain. I'm stuck at the last step and not sure how to proceed. I'm trying to develop the header part of the txt file. In addition, I'm not sure how to get the iterations in 0.1 s time interval as an output.

Expected output 

Zoalkara_0-1578762371803.png 

My output 

Zoalkara_1-1578762836502.png

I've attached the VI.

 

Thanks,

Download All
0 Kudos
Message 1 of 7
(3,286 Views)

You are almost there.  I just saw two things in your VI that need to be fixed.

 

1.  I couldn't pick a file path using the browse button on the path control.  You need to right click on the control and pick Browse Options....  Choose New or Existing.  The default setting is existing which means it won't let you enter a new file name.

2.  Once I did #1, I ran and had an error on the file open.  You need to right click on the Open File function's Operation terminal and pick Create Constant.  Default is Open which means the file must exist already.  Change the enum to Open or Create.

0 Kudos
Message 2 of 7
(3,264 Views)
Solution
Accepted by topic author Zoalkara

Although I've been using LabVIEW for more than a decade, I only realized the reason and use of Wait until Next ms (Multiple) a few months ago, and now that I know and understand it, I wonder why NI doesn't explain it better and stress its very-limited utility.  So the first change (which is actually pretty trivial, and won't significantly change the function of this VI) is to use Wait (ms) -- you will probably never need the "Metronome" Wait function, which is used only to synchronize (emphasis mine, but this is the key word in the Help for the Metronome Wait) independent timed loops.

 

So you need to output the time (not the iteration number) in the first column.  You have an input, "Frequency", that you currently are wiring to a Delay (or "time") function. 

  • What are the units of Frequency?  (Answer:  Hz, which has the units of what?)
  • What are the units of Time?  (Answer:  Seconds, which has the units of "seconds").
  • What are the units of the numeric that you wire into the Wait functions?  (Answer -- read the Help)
  • If you know how long the Wait is (in seconds) and know the iteration number ("i"), how do you compute the elapsed time?  (Hint -- it is not by division).

Bob Schor

0 Kudos
Message 3 of 7
(3,247 Views)
Solution
Accepted by topic author Zoalkara

A few more quick notes:

 

  • Don't call the control "frequency" if it controls the inverse of that. Also watch the units, the wait is in ms.
  • You can combine the format and write function into one using "format into file". (of course then you won't see the string, though. Is that important?)
  • Do some error handling and stop the loop also on error.
  • Not sure why you need all these zero decimals for the integer. Wouldn't %d be a more reasonable format for [i]?
  • You might want to skip the loop if an error occurs opening the file. (fail to open, dialog canceled, etc.)
  • You can calculate the time based on [i] and the wait (if it never changed during the run), or actually measure relative time.
  • Your format contains many more spaces than the "expected output" shown. Modify the format.
  • ...
0 Kudos
Message 4 of 7
(3,245 Views)

Here's how you can measure the time relative to the start of the loop:

 

altenbach_0-1578769866137.png

0 Kudos
Message 5 of 7
(3,239 Views)

Thank you. I was just confused because I assumed that time lapsed was already included. Is it possible to format the output such that I have the header " time (s), number" on the top of the data written to txt as shown in the first image?

0 Kudos
Message 6 of 7
(3,218 Views)

Yes, write the header line before the loop.

0 Kudos
Message 7 of 7
(3,185 Views)