Writing & reading same file

Discussion in 'VHDL' started by Niv (KP), Sep 13, 2010.

  1. Niv (KP)

    Niv (KP) Guest

    In my testbench, is it possible to write to a file, then read that
    file, then write to the file again, then read the file again, etc etc.
    It doesn't matter if the file is re-opened and destrots the previous
    data written.

    Seem to be having trouble doing this.

    i.e. in my tb, unit 1 writes several lines of binary data (as text) to
    file A, then unit 2 needs to read this file A before it then writes
    out other data to file B.

    This is then repeated several times/
     
    Niv (KP), Sep 13, 2010
    #1
    1. Advertisements

  2. Niv (KP)

    debayan_p

    Joined:
    Jun 2, 2009
    Messages:
    23
    Likes Received:
    0
    Sure you can do it!!

    But I am not very sure if it can be done with the same process!

    If you do the writing and the readings in different processes, then it can be done! Just chk it out, I am not 100% sure about this....
     
    debayan_p, Sep 13, 2010
    #2
    1. Advertisements

  3. On Mon, 13 Sep 2010 06:29:59 -0700 (PDT), "Niv (KP)" wrote:

    >In my testbench, is it possible to write to a file, then read that
    >file, then write to the file again, then read the file again, etc etc.
    >It doesn't matter if the file is re-opened and destrots the previous
    >data written.
    >
    >Seem to be having trouble doing this.
    >
    >i.e. in my tb, unit 1 writes several lines of binary data (as text) to
    >file A, then unit 2 needs to read this file A before it then writes
    >out other data to file B.


    hi Kevin

    Did you close file A before attempting to re-open and then
    read from it? (Of course this requires using the -93
    form of file declaration, and FILE_OPEN and FILE_CLOSE
    procedures.)

    When you write new data to a file, I don't think there is
    any guarantee of that file's contents until it's closed.

    While we're thinking about this, it's worth mentioning
    that you need to be very careful when multiple processes
    access the same file. The file is in effect a shared
    variable with no kind of interlock or scheduling, so it
    is quite easy to get indeterminacy - one of the very few
    places this can happen in VHDL. Unless you have really
    huge amounts of data (many tens of megabytes) it may be
    better to use shared variables of protected type.
    --
    Jonathan Bromley
     
    Jonathan Bromley, Sep 13, 2010
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,667
    HNguyen
    Dec 21, 2004
  2. darrel
    Replies:
    2
    Views:
    587
    darrel
    Apr 5, 2006
  3. evenrik
    Replies:
    3
    Views:
    490
    Vinay Sajip
    Dec 11, 2007
  4. id10t error
    Replies:
    3
    Views:
    949
    Alexey Smirnov
    Aug 31, 2009
  5. A. Farber
    Replies:
    8
    Views:
    731
    Mike Amling
    Oct 20, 2009
  6. Thomas Adam

    Read/Writing to the same file

    Thomas Adam, Sep 2, 2003, in forum: Ruby
    Replies:
    1
    Views:
    132
  7. it_says_BALLS_on_your forehead

    question about forked processes writing to the same file

    it_says_BALLS_on_your forehead, Oct 17, 2005, in forum: Perl Misc
    Replies:
    47
    Views:
    507
    it_says_BALLS_on_your forehead
    Oct 29, 2005
  8. Jens Thoms Toerring

    Writing to same file from two threads

    Jens Thoms Toerring, Feb 26, 2013, in forum: Python
    Replies:
    6
    Views:
    273
    Antoine Pitrou
    Mar 1, 2013
Loading...