Trying to read hex data from a file

Just a quick update because I realized at least one of my problems. I was using “%h” in the $fscanf function, which does not work. I changed it to %u so now its reading the 16 bits into my array. Also changed the variable it outputs into to “status”. I assume status = 1 is good, and status = 0 means something didn’t work?


integer file_handler;
int status;
reg [15:0] frame[0:18432];

begin
	file_handler = $fopen (file_name, "rb");
	if(file_handler == 0) begin
		$display("Failed to open file: %0s", file_name);
		$stop;
	end

	for(int i = 0; i < 5; i++) begin
		status = $fscanf(file_handler, "%u", frame[i] );
		$display("pixel read: %h", frame[i]);
		$display("read status: %d", status);
	end