+ Reply to Thread
Results 1 to 5 of 5

Can I open a binary file twice, for simultaneous read and write?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    0

    Default Can I open a binary file twice, for simultaneous read and write?

    I have a situation where I am streaming binary data in via USB from a piece of custom gear, and I want to write the data to a binary file as it comes in. At the same time I want to be able to generate a monitor display of the data while the acquisition is in progress, by reading from the file (behind the write) . Can I simply open the same file twice, for writing and reading, using two separate file-open VIs? The writes will always append to the end of the file, and the read location may be random up to the current end of the file.
     

  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    0

    Default Re: Can I open a binary file twice, for simultaneous read andwrite?

    I need to have effectively two location pointers into the file: one to where I'm writing (appending), and one to where I'm reading. I don't want to reposition the pointer in order to read, because this will (if I understand correctly) change the location for the writes, which will be asynchronous (probably interrupt-driven).
     
    One question that occurs to me is: if the file is extended while it's open for reading, do I have to close and open it again in order to read the new data?
     

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    0

    Default Re: Can I open a binary file twice, for simultaneous read andwrite?

    In the time it took to write this question, you probably could have made a simple demo VI and try for yourself.
     
    Yes, you can open a file twice, and yes you can write to it and read from it from different locations. There is nothing special about all that. Attached is a very quick draft to illustrate my point (probably needs a few tweaks and error handling).
     
    I also don't think you need to do anything special to keep things up to date. I don't think a "flush file" operation is needed.
     Message Edited by altenbach on 09-27-2007 09:24 AM


    OpenTwice.vi:
    http://forums.ni.com/attachments/ni/...1/OpenTwice.vi

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    0

    Default Re: Can I open a binary file twice, for simultaneous read andwrite?

    There could be a LOT of data, and I don't want to hold it all in memory; I have to write it to the file anyway for preservation. I already have the viewer portion working, reading from a (dummy data) file. The viewer will be used for ****yzing the data offline after acquisition. I would also like to use it to monitor the acquisition process if possible. It seemed that the simplest way, programming-wise, was to read the file as it's being written.
     

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    0

    Default Re: Can I open a binary file twice, for simultaneous read andwrite?

    Thanks for all your responses. My last reply (out of sequence) was to Matthew K. To altenbach: I agree, I don't think a flush operation is needed, except after the final write. As soon as I get a chance I'm going to play with your example and do a few of my own.  - dhfx
     

+ Reply to Thread

Similar Threads

  1. read write integer in binary into a file
    By Application Development in forum RUBY
    Replies: 9
    Last Post: 12-13-2007, 08:41 AM
  2. FAQ 5.14 How come when I open a file read-write it wipes it out?
    By Application Development in forum Perl
    Replies: 0
    Last Post: 10-12-2007, 08:03 PM
  3. FAQ 5.14 How come when I open a file read-write it wipes it out?
    By Application Development in forum Perl
    Replies: 0
    Last Post: 07-23-2007, 02:03 AM
  4. Replies: 8
    Last Post: 06-10-2007, 12:36 AM
  5. FAQ 5.14 How come when I open a file read-write it wipes it out?
    By Application Development in forum Perl
    Replies: 0
    Last Post: 04-30-2007, 08:03 AM