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: 

problem in writing to the file

I use this labview code to read and save some electrical measurement data from a set of instruments. I am having a problem that the code stops writing to the file after a while. It stops responding too. The only way to stop it then is to use the task manager and kill it. The code was written for an older version of labview but now I am using labview 9. Everything else seems updated but there's a section that uses Write characters to file vi and that may be causing the problem. I made a few futile attempts to change it. I would highly appreciate if someone takes a look at it and could tell me what's going wrong.

0 Kudos
Message 1 of 4
(2,109 Views)

Have you ever looked at the size of the file when the program locks up? There is a problem with file that are bigger than 2Gig.

 

I would also reccomend a look into state machine ans producer consumer loops. You have a lot going on in you code and it would run more efficently if you looked into these structures for programming. It would also make it easier in the future to upgrade and change you code,

Tim
GHSP
0 Kudos
Message 2 of 4
(2,084 Views)

Definitely check on the file size and processor usage when it crashes. The software should give an error if it's writing too big of a file or the GPIB device times out. If the program is just freezing after a period of time, it's probably getting stuck in a loop somewhere.

 

How long does the program run before it freezes?

Jake H | Product Manager
0 Kudos
Message 3 of 4
(2,069 Views)

I will second aeastet's advice - please look into how state machines and producer/consumer loops work and use them.  Your program is very inefficient, but is very similar to what I would have written before I learned about state machines and producer/consumer loops.  Start with the LabVIEW help and go from there.  These forums and the National Instruments website can give you lots of help.

 

Two things that will help you for this particular problem:

 

  1. At every loop iteration, you are opening the file, seeking to the end of it, appending data, then closing the file.  This is very slow and the code you use, as mentioned above, will not work if the file size exceeds 2GBytes.  I would recommend you open the file once, then use the write primitive to write to it until you finish, then close it.  You do not need the write character to file VI.  No seeking.  No repetitive opening and closing.  You can either open and close outside the loop, or use case structures and boolean flags (as you have done for other things) to open and close inside the loop.
  2. After you write to the file, if you choose to graph, you are reopening the file, reading the entire thing, and plotting this data.  This is another major slowdown that will only get worse as your file gets bigger.  You would be far better off caching the data in a shift register and plotting it on demand.  It would probably take less memory, as well.  You may want to read the tutorial Managing Large Data Sets in LabVIEW.
One last tip.  You use Value properties to read and set the values of front panel controls.  Local variables are far faster (about three orders of magnitude).  However, do not make the mistake of using local variables for data storage.  Data is wires.  Local variables are a way to communicate to the front panel.  You seem to have this down, but a reminder to others reading this thread is in order.
Let us know if you need more explanation or help.  Good luck!

 

0 Kudos
Message 4 of 4
(2,041 Views)