LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building array and writing to multiple files

Solved!
Go to solution

Greetings,

 

I have a VI wherein, I am collecting data from 3 channels (using Global Virtual Channels with scaling). I am collecting 100 samples at a time with sampling frequency of 1000 Hz. I am then taking average and st. dev of 100 data points/channel and write it to a file (‘*.dat’). I would like to limit the file size to 1000 entries, and so after that limit is reached I would like to create a new file and write the subsequent set of data to the next file and so on. I am doing this in a case structure, wherein I build an array of the values until the condition of file limit is reached and then I write that array to a ‘*.dat’ file. (I’m hoping that this logic is correct, if not please suggest the correct method)

I am also taking average and st. dev of data/channel over period of 1 sec and write it to another ‘*.sum’ file. The VI has other features like writing time stamp to file, stopping the VI after preset time limit is reached or certain safety limit is reached.

 

When I run the VI, I get an error message:

Error 7 occurred at Open/Create/Replace File in Global Channel with Multiple file Write.vi

Possible reason(s):

LabVIEW:  File not found. The file might have been moved or deleted, or the file path might be incorrectly formatted for the operating system. For example, use \ as path separators on Windows, : on Mac OS X, and / on Linux. Verify that the path is correct using the command prompt or file explorer.

=========================

NI-488:  Nonexistent GPIB interface.

 

 

I have indicated the location of the error in the attached picture, as well as I’m attaching the VI.

 

I would really appreciate if someone would tell me what is causing the error and how to fix it.

Thanks,
Dinesh

Download All
0 Kudos
Message 1 of 12
(3,630 Views)

Check your file path names.  In the botton and top Build Path functions, there is a space being inserted, which I don't believe was your intention. Use your probing tool to check the names when you run the program.  The space is comming from your string control on your FP.  This could be your problem.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 2 of 12
(3,625 Views)

Thanks a bunch. That did solve one problem, and I was able to find out that my logic of writing data to multiple files is partially correct. I am able to write data to multiple files, but each file contains only 1 row and not 1000 rows (preset limit). Would you please look at the VI to tell me the glitch in my logic?

Thanks,

Dinesh

0 Kudos
Message 3 of 12
(3,618 Views)

You want to use the Set File Position function to set the file position to the end of the file before you do a write.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 12
(3,616 Views)

I did try that but it does not solve the problem. I think I'm missing something while building the array in the Case Structure. I would like to write the average & st. dev values/channel in an array while the loop coount < file limit, and once the file limit is reached write that array to a *.dat file. And keep repeating this procedure till the target time is reached.

 

Another issue that I discovered is that TestFile_1.dat is not generted, after TestFile_0.dat TestFile_2.dat gets generated. I'm not sure why this is happening.

 

I would really appreciate if you would take another look and suggest some debugging tips.

Thanks.

 

P.S. I am attaching the updated VI

0 Kudos
Message 5 of 12
(3,605 Views)

@db0101 wrote:

.

 

Another issue that I discovered is that TestFile_1.dat is not generted, after TestFile_0.dat TestFile_2.dat gets generated. I'm not sure why this is happening.

 

 


Because the file name is based off the result of the Quotient remainder function.  You actually write to a file in case 0, default.  In case 1, you don't do anything with your data, and certainly not writing to a file.  Thus case 1, nothing happens.  All other cases 0, 2, 3, 4, ... up to 999, a file is created.

0 Kudos
Message 6 of 12
(3,597 Views)

Thanks. I now see the flaw in my logic, but still can't figure out the correct way of implementing the plan.

 

I am collecting 100 data points/channel at a time and computing average and std. deviation of those data points. I would like to build an array of those computed values, and once the number of rows reach 1000 write that array to a file. The file name should contain the loop iteration number at which the file is written. This array is then initialized to 0 and the process if repeated for next 1000 loop iterations.

 

I would really appreciate if someone would point me to an example which does something similar to this, or tell me how to implement this.

Thanks.

0 Kudos
Message 7 of 12
(3,591 Views)

Hi

 

Just made some changes to your code regarding file IO. This will remove the other two errors that keep occuring, 'File Not found' and 'Duplicate Path'. Its in version 2010SP1.

 

I am still working on the '1 row' and '1000 rows' thing. Please explain again what you want in the TestFile_i.dat. The '.sum' file seems ok but gotta understand little more of the work going on.

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 8 of 12
(3,585 Views)

Thanks a bunch.

 

Here is the description of the implementation of .dat file.

I am collecting 100 data points/channel at a time and computing average and std. deviation of those data points. I would like to build an array of those computed values, and once the number of rows reach 1000 write that array to a file. The file name should contain the loop iteration number at which the file is written. This array is then initialized to 0 and the process if repeated for next 1000 loop iterations.

 

I am not sure if I have to use For loop with Case Structure within it to build array and write to file.

 

I would appreciate any help in programming the correct logic.

Thanks.

0 Kudos
Message 9 of 12
(3,565 Views)
Solution
Accepted by topic author db0101

You can use a For loop to build your array.  Your file write should happen afterwards and should not be part of your loop process.  Only when your array count has reached 1000 should you stop looping and then write your array to the file.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 10 of 12
(3,561 Views)