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. Advertising

  2. Niv (KP)

    debayan_p

    Joined:
    Jun 2, 2009
    Messages:
    23
    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. Advertising

  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. Advertising

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,371
    HNguyen
    Dec 21, 2004
  2. darrel
    Replies:
    2
    Views:
    458
    darrel
    Apr 5, 2006
  3. evenrik
    Replies:
    3
    Views:
    371
    Vinay Sajip
    Dec 11, 2007
  4. id10t error
    Replies:
    3
    Views:
    712
    Alexey Smirnov
    Aug 31, 2009
  5. A. Farber
    Replies:
    8
    Views:
    551
    Mike Amling
    Oct 20, 2009
Loading...

Share This Page