05-10-2011 02:54 PM
Hi, I've got problem with writing to a binary file with Binary File Function. I'd like to append the array to the existing file during each loop. My program generate a 4 row, 500column 2D array during each loop. However, after I stop the vi and open the binary file, there are only 4 row, 500column data in the file. I assume it's becuase in each loop the data is overwritten. I've already used Set file position to End. I don't understand why it still overwrites my file. Thank you very much.
Solved! Go to Solution.
05-10-2011 03:30 PM
It seems to work okay for me. How do you know it only has one set of data in it?
You could actually set your file position to the end just once outside the loop where you open the file, you don't need to do it every time in the loop. As long as you don't close the file, the file system knows where the current file pointer is.
05-10-2011 03:40 PM
Because I used another vi "binary file reader" to read the file. I only get 4 row and 500 elements in each row. That corresponds to one loop only. I let the vi run many loops before I stopped it.
05-10-2011 04:20 PM
@Ravens Fan wrote:
It seems to work okay for me. How do you know it only has one set of data in it?
You could actually set your file position to the end just once outside the loop where you open the file, you don't need to do it every time in the loop. As long as you don't close the file, the file system knows where the current file pointer is.
Hi, Ravens,
I think you are right.... The file size does grow with the time that I collect data. So I think all the data is in the file. Somehow I can't read them out. They might be segmented due to each loop. Do you have any suggest how to read them all out into one 2D array? Thank you so much.
Best,
Charles
05-10-2011 04:44 PM - edited 05-10-2011 04:45 PM
Yes. The Read Binary File has an input connector that is called Count. When it is not wired up, the default value is 1 and it reads 1 element (your 2-D array) from the file. If you wire up another number you get more. If you wire up -1, you read the entire file.
If you wire up a number, you get a 1-D array of a cluster of your data (the 2-D array). So if you read data this way, you can index the array, unbundle the cluster, then build the resulting 2-D array concatenating it a shift register.
05-10-2011 04:58 PM - edited 05-10-2011 05:00 PM
You can also read the file one piece of data at a time if you do it inside a loop.
05-10-2011 08:41 PM
Thank you so much! I wanted to concatenate the array horizontally, but I figure that out with your help. Thanks a lot!!!
11-08-2012 09:44 PM
hi how to append the binay file using the file path...
Thanks in advance
11-08-2012 09:52 PM
I don't understand your question.
Rather than hijacking a year and a half old thread, you'd be better served to start your own new thread. Be sure to provide some detail with your question. Perhaps post your VI so we can see what you are doing and tell us where you are having problems.
11-08-2012 10:33 PM
ya sure please see the attached file actually i am opening the excel workbook and write in to binay file and if i open the next workbook that value should append to the same binay file and like that i have append the many excel (Tab delimited)
Thanks in advance