LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 1 occurred at Write to Text File

Hi everybody!

My state-machine should save data in file for 10 seconds when I press the Record Button and then read data again without saving.

The Random Number block will be replaced with the Analog Input of an acquisition device (myRio).

The program works but I am getting an "Error 1" at Write to Text File block in the saving loop. How could I solve it?

I've attached the VI.

 

Thank you in advance,

Lorenzo

0 Kudos
Message 1 of 9
(6,510 Views)

Unfortunately I don't have LabVIEW 2015 on my machine so I can't look at your VI - if you save it for 2014 or earlier, I can have a look.

 

Error 1 usually indicates that an input was invalid - what is the message that goes along with the error? If the code is running on the myRIO  - are you using a valid path on the myRIO (e.g. look at the Linux RT paths in this document: http://www.ni.com/tutorial/14669/en/)?


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 9
(6,498 Views)

Thank you Sam!

Here it is the VI for the version 13.0.

I don't have the myRio here right now but the error occurs also if I run the VI on my PC. There should be something wrong with the path but I don't know what.

 

Lorenzo

 

0 Kudos
Message 3 of 9
(6,489 Views)

Ok, thanks for reuploading. What are you entering on your 'Saving file' control? You need this to be valid folder on the target that exists (as per the paths I gave). Have you tried changing it to a constant? You might also need to add a directory separator.

 

It is normally better to use the 'build path' function rather than converting to a string and then back again (this handles things like directory separators for you!):

2016-03-21_13-23-07.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 9
(6,476 Views)

Put some probes on the file path wires.

 

Why are you closing the file in the event the queue times out?  A 200 millisecond timeout value on that queue seems kind of short.  I'm wondering if you are getting a timeout, that closes the file, and it is putting an empty file reference into the shift register.

 

Another concern I have is that whenever the record button is True, you wind up creating a new file everytime the lower loop iterates and never close the previous one.

 

I think your overall use of the timeout on the queue, and the mechanical behavior and use of local variables on the record button is just making a tangled mess of your state machine, that you'd have to get really lucky for it to work at all the way you have it.

 

I think right now, if you start the program and leave the record button as off, the lower loop will iterate, the queue will timeout, and the lower loop will try to write data to a file, but it has no valid file path because no good file path had been put into the shift register.

0 Kudos
Message 5 of 9
(6,467 Views)

In "Saving File" I enter something like "C:\Users\Lorenzo\Desktop\filename".

I've tried to run the VI with the Highlight Execution and the error occurs also if I don't press the Record Button (so no file is created).

Is it because Labview tries to write on the file but it finds no reference?

 

Thank you so much

0 Kudos
Message 6 of 9
(6,459 Views)

I just would like to create a new file everytime I press the record button, save 10000 samples and close the file. I used the queue timeout to close the file automatly if there are no more elements in the queue after 200 ms.

I have understood there is something wrong if I leave the record button as off. Should I initialize the reference shift register outside of the lower loop?

 

Thank you in advance

0 Kudos
Message 7 of 9
(6,450 Views)

I would move all things related to the file to the consumer loop.  Do you ever want to stop logging, but continue acquiring data, until sometime later you start logging again?

 

In your producer loop, send two things, the data and a command enum  This would be a cluster of enum and data.  The enum can have certain commands, like start logging, Log Data, stop logging. or even new file.  Possible one more which is Stop Program.

 

Let your consumer loop dequeue that cluster (without a timeout), and also maintain a boolean on a shift register that signifies whether loggin is currently active.

 

When you press the record button, let is queue up a Start Logging button and data.  When the consumer loop gets that, it executes a case of the case structure that creates the file name and opens the file, stores it in the shift register, and also puts a True value on the Logging? shift register.  When it gets a Log data command, it goes into a case for that, and if the shift regsiter is True, writes it to the file.  Stop logging case will close the file and put a False on the shift regsiter.  A stop program state would also  close the file and put a false on the shift register, but also wire a True to the stop terminal of the consumer while loop.

 

Now your code will always have a valid reference when it needs it, doesn't have timing issues with respect the producer loop, doesn't require you to set buttons to switch action and have to programmatically reset them back to false.

0 Kudos
Message 8 of 9
(6,431 Views)

Hey all,

 

what RavensFan is saying seems to be the best way to do this. The problem is the invalid reference after your consumer loops times out, because you just assign a default value to the path to it which should be an empty path, so that's what causes the error.

 

I would follow RavensFan's advice and move everything to the consumer loop, so you don't run into that issue.

 

Best,

 

Corrado

0 Kudos
Message 9 of 9
(6,402 Views)