无论如何,是否可以使用 std textio 在 vhdl 中多次读取文件? [英] Is there anyway to read through a file multiple times in vhdl using std textio?

查看:41
本文介绍了无论如何,是否可以使用 std textio 在 vhdl 中多次读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解在 vhdl 中读取文件的工作原理,如果我打开一个文件,通读它,测试文件结尾,关闭文件,然后重新打开该文件,然后再次开始读取它会从文件的开头?

I am trying to understand how reading a file works in vhdl if I open a file, read through it, test for end of file, close the file and then re open that file and then start to read again will it start from the beginning of the file?

非常感谢

推荐答案

向 VHDL 语言权威寻求答案.

Look to the authority on the VHDL language for your answer.

IEEE 标准 1076-2008

IEEE Std 1076-2008

5.5 文件类型
5.5.1 总则

5.5 File types
5.5.1 General

文件类型定义定义文件类型.文件类型用于定义表示主机系统环境中文件的对象.文件对象的值是包含在主机系统文件中的值序列.

A file type definition defines a file type. File types are used to define objects representing files in the host system environment. The value of a file object is the sequence of values contained in the host system file.

5.5.2 文件操作

FILE_OPEN 过程打开一个由 External_Name 参数指定的外部文件,并将其与文件对象 F 关联.如果对 FILE_OPEN 的调用成功(见下文),则称该文件对象已打开,并且该文件对象具有依赖于提供给 Open_Kind 参数的值的访问模式(见 16.3).

The FILE_OPEN procedures open an external file specified by the External_Name parameter and associate it with the file object F. If the call to FILE_OPEN is successful (see the following), the file object is said to be open and the file object has an access mode dependent on the value supplied to the Open_Kind parameter (see 16.3).

——如果提供给 Open_Kind 参数的值为 READ_MODE,则文件对象的访问模式为只读.此外,文件对象被初始化,以便后续的 READ 将返回外部文件中的第一个值.值按照它们在外部文件中出现的顺序从文件对象中读取.

— If the value supplied to the Open_Kind parameter is READ_MODE, the access mode of the file object is read-only. In addition, the file object is initialized so that a subsequent READ will return the first value in the external file. Values are read from the file object in the order that they appear in the external file.

...
如果文件对象 F 与外部文件相关联,过程 FILE_CLOSE 终止对与 F 相关联的外部文件的访问并关闭外部文件.如果 F 未与外部文件关联,则 FILE_CLOSE 无效.在任一情况下,在调用 FILE_CLOSE 将文件对象与形参 F 相关联后,文件对象不再打开.
...
过程 READ 从文件中检索下一个值;如果文件对象的访问模式为只写或文件对象未打开,则会出现错误.过程 WRITE 将一个值附加到文件中.过程 FLUSH 请求实现完成所有先前对文件的 WRITE 过程调用的效果.对于 WRITE 和 FLUSH 过程,如果文件对象的访问模式为只读或文件未打开,则会出错.如果对访问模式为只读的打开文件对象的后续 READ 操作可以从文件中检索另一个值,则函数 ENDFILE 返回 FALSE;否则,它返回 TRUE.对于访问模式为只写的打开文件对象,函数 ENDFILE 始终返回 TRUE.如果在未打开的文件对象上调用 ENDFILE,则会出错.

...
If a file object F is associated with an external file, procedure FILE_CLOSE terminates access to the external file associated with F and closes the external file. If F is not associated with an external file, then FILE_CLOSE has no effect. In either case, the file object is no longer open after a call to FILE_CLOSE that associates the file object with the formal parameter F.
...
Procedure READ retrieves the next value from a file; it is an error if the access mode of the file object is write-only or if the file object is not open. Procedure WRITE appends a value to a file. Procedure FLUSH requests that the implementation complete the effect of all previous calls to the WRITE procedure for a file. For the WRITE and FLUSH procedures, it is an error if the access mode of the file object is read-only or if the file is not open. Function ENDFILE returns FALSE if a subsequent READ operation on an open file object whose access mode is read-only can retrieve another value from the file; otherwise, it returns TRUE. Function ENDFILE always returns TRUE for an open file object whose access mode is write-only. It is an error if ENDFILE is called on a file object that is not open.

进一步阅读将发现文件访问是独占的,如果没有 FILE_CLOSE,您将无法执行另一个 FILE_OPEN.您可以通过查找没有前面的 FILE_CLOSE 的后续 FILE_OPEN 将返回 STATUS_ERROR 来证明这一点.

Further reading will reveal that file access is exclusive, you can't execute another FILE_OPEN without a FILE_CLOSE. You can demonstrate this by finding a subsequent FILE_OPEN without a preceding FILE_CLOSE will return a STATUS_ERROR.

所以 FILE_OPEN 从头开始​​访问.重置到文件开头的唯一方法是 FILE_CLOSE 然后 FILE_OPEN.

So a FILE_OPEN starts access from the beginning. The only way to reset to the beginning of a file is to FILE_CLOSE then FILE_OPEN.

这篇关于无论如何,是否可以使用 std textio 在 vhdl 中多次读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆