- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 pySerial==3.4
,但发现关于 serial.Serial.flush()
的文档相当缺乏:
Flush of file like objects. In this case, wait until all data is written.
问题
flush
而不是单独重置输入/输出缓冲区?serial = Serial("COM3")
# Option 1
serial.flush()
# Option 2
serial.reset_input_buffer()
serial.reset_output_buffer()
相关问题
最佳答案
看起来像这样:
什么是“文件类对象”?
What is exactly a file-like object in Python?
file-like objects are mainly StringIO objects, connected sockets and well.. actual file objects. If everything goes fine, urllib.urlopen() also returns a file-like objekt supporting the necessary methods.
file-like object
A synonym for file object.file object
An object exposing a file-oriented API (with methods such as read() or write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.). File objects are also called file-like objects or streams.There are actually three categories of file objects: raw binary files, buffered binary files and text files. Their interfaces are defined in the io module. The canonical way to create a file object is by using the open() function.
io — Core tools for working with streams
The io module provides Python’s main facilities for dealing with various types of I/O. There are three main types of I/O: text I/O, binary I/O and raw I/O. These are generic categories, and various backing stores can be used for each of them. A concrete object belonging to any of these categories is called a file object. Other common terms are stream and file-like object.
刷新了什么?
保存在输出缓冲区中的数据。
什么时候会使用刷新而不是单独重置输入/输出缓冲区?
有数据已经输出(write()
),关闭前调用。
flush()
与输入缓冲区或 reset_input_buffer()
无关。
flush()
与 reset_output_buffer()
有不同的功能。flush()
将输出缓冲区中的所有数据发送给对端,而reset_output_buffer()
丢弃输出缓冲区中的数据。
reset_output_buffer()
Clear output buffer, aborting the current output and discarding all that is in the buffer.Note, for some USB serial adapters, this may only flush the buffer of the OS and not all the data that may be present in the USB part.
关于python - pySerial:刷新 vs reset_input_buffer + reset_output_buffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60766714/
我正在尝试使用 pySerial==3.4,但发现关于 serial.Serial.flush() 的文档相当缺乏: Flush of file like objects. In this case,
我是一名优秀的程序员,十分优秀!