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
.
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?
I have had exactly the same problem, including the 1020 byte buffer size and haven't found a way to change this. My solution has been to implement a loop 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 pleased if someone can come up with a buffer-resize solution!
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With