如何扩展pyserial的输入缓冲区大小 [英] How to expand input buffer size of pyserial
问题描述
我想通过串口与电话通信。将一些命令写入电话后,我使用了 ser.read(ser.inWaiting())
来获取其返回值,但我总是总得到 1020个字节
个字符,实际上,期望的返回值应该超过 50KB
。
I want to communicate with the phone via serial port. After writing some command to phone, I used ser.read(ser.inWaiting())
to get its return value, but I always got total 1020 bytes
of characters, and actually, the desired returns is supposed to be over 50KB
.
我尝试设置 ser.read(50000)
,但是解释器将挂起。
I have tried to set ser.read(50000)
, but the interpreter will hang on.
如何我会扩展输入缓冲区以一次获得所有返回值吗?
How would I expand the input buffer to get all of the returns at once?
推荐答案
如果在Windows平台上运行代码,只需在代码中添加一行即可。
If you run your code on Windows platform, you simply need to add a line in your code.
ser.set_buffer_size(rx_size = 12800, tx_size = 12800)
其中12800是我选择的任意数字。您可以使接收(rx)和发送(tx)缓冲区最大为2147483647(等于2 ^ 31-1)
Where 12800 is an arbitrary number I chose. You can make receiving(rx) and transmitting(tx) buffer as big as 2147483647 (equal to 2^31 - 1)
这将允许您扩展输入缓冲区
this will allow you to expand the input buffer to get all of the returns at once.
请注意,由于这是建议,因此仅对某些驾驶员有效。该驱动程序可能不会接受您的建议,并会保留其原始缓冲区大小。
Be aware that this will work only with some drivers since it is a recommendation. The driver might not take your recommendation and will stick with its' original buffer size.
这篇关于如何扩展pyserial的输入缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!