cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
linsinga
Newbie
Newbie
9,703 Views
Registered: ‎08-12-2015

Writing nul character to file

Hi!

I'm currently developing a small test bench where a bitmap file is read (using std.textio.all). I have managed to read the bmp file and I can write all characters to a new bmp file except 0 (nul character). By opening the input bmp file in notepad++ I can see the nul characters and by using the attribute image on the read variable in the test bench I can see that the nul character has been read properly. The nul characters can, however, not be found in the new bmp file I write to. Here is my simple test bench:

 

test_proc: process (clk)
variable line_read     : line; 
variable line_write     : line;
variable char_buf     :    character;
file input_file       :    text OPEN read_mode IS "input_image.bmp"; -- Image to read from
file output_file      :     text OPEN write_mode IS "output_image.bmp"; -- Image to write to
    
begin
    if rising_edge(clk) then
        readline(input_file, line_read); -- Bitmap only consists of one line.
        while line_read'length > 0 loop
            read(line_read, char_buf);    
            write(line_write, char_buf);
        end loop;
        writeline(output_file, line_write);
        assert false report "NONE! Simulation Finished" severity failure;            
    end if;
end process;

Is it possible to write the nul character to a file using VHDL?

3 Replies
guillaumebres
Scholar
Scholar
9,627 Views
Registered: ‎03-27-2014

This guy, http://www.stefanvhdl.com/vhdl/vhdl/txt_util.vhd,

wrote a bunch of function handling the type 'character', maybe you could try something like:

 

   print(l_file, "\0");

 

gw.
Embedded Systems, DSP, cyber
0 Kudos
debrajr
Moderator
Moderator
9,565 Views
Registered: ‎04-17-2011

write(line, character'val(0)); , doesn't this work?
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
labbench1
Observer
Observer
3,723 Views
Registered: ‎05-17-2017

I'm having the exact same problem and it seems like it might be a problem with iSim.  I'm running iSim 14.7 and whenever I try to write character'val(0) to a file, it's writing binary 00001010 to the file instead of binary 00000000.  Everything else appears to work. 

 

Is there a work around for this or just a bug in iSim?  I'm trying to write binary files instead of ascii versions of binary files because it's a very inefficient way to write data to a file. 

 

Thanks.

Tags (5)
0 Kudos