【问题标题】:Unable to open a file in Verilog无法在 Verilog 中打开文件
【发布时间】:2022-01-19 18:59:03
【问题描述】:

我在 Verilog 中编写了以下代码来打开文件:

initial begin
clk=0;  i=0;done=0;
data = $fopen(":P\Desktop\image.txt", "r");
if (data== `NULL) begin
    $display("data_file handle was NULL");
    $finish;
end
final = $fopen(".txt","w");
end

我已指定文件位置,但它返回错误:

WARNING: file PDesktopimage.txt could not opened

任何帮助我该如何解决这个问题?

【问题讨论】:

    标签: verilog


    【解决方案1】:

    当我运行您的代码时,我会收到以下消息:

    文件“:PDesktopimage.txt”打开失败。没有这样的文件或目录

    与您的消息一样,它没有作为目录分隔符的反斜杠字符。但是,我的消息确实有前导冒号 (:)。

    为了获得反斜杠,我使用 \\ 转义了反斜杠:

    initial data = $fopen(":P\\Desktop\\image.txt", "r");
    

    在运行模拟之前将要打开的文件放置到当前工作目录中,然后只打开不带路径的文件名,这是避免此类问题的好习惯:

    initial data = $fopen("image.txt", "r");
    

    通常使用脚本来管理文件和运行模拟。

    【讨论】:

    • 一种常见的解决方案是在工作目录中使用符号链接指向另一个位置的文件。
    猜你喜欢
    • 2019-01-06
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多