How to increase pyserial input buffer size

I want to communicate with the phone through the serial port. After writing some command to the phone, I used ser.read(ser.inWaiting()) to get the return value, but I always had a total number of characters of 1020 bytes , and in fact the desired income should be exceeded 50KB .

I tried installing ser.read(50000) , but the interpreter will hang.

How can I expand the input buffer to get all the results right away?

+6
source share
3 answers

I had exactly the same problem, including a buffer size of 1020 bytes and did not find a way to change this. My solution was to implement a cycle like:

 in_buff='' while mbed.inWaiting(): in_buff+=mbed.read(mbed.inWaiting()) #read the contents of the buffer time.sleep(0.11) #depending on your hardware, it can take time to refill the buffer 

I would be very happy if someone could come up with a solution to resize the buffer!

+3
source

I assume that you read 1020 bytes, because that's all there is in the buffer, which is what ser.inWaiting () returns. Depending on the baud rate of 50 KB, it may take some time for the transfer, or the phone expects something else. Handshake?

Check the value of ser.inWaiting and then the contents of what you get for tips.

+1
source

pySerial uses its own OS drivers for serial reception. For Windows, the size of the input driver is based on the device driver.

You may be able to increase the size in the Device Manager settings, if possible, but in the end you just need to read the data quickly enough.

0
source

Source: https://habr.com/ru/post/924743/


All Articles