I can not understand how to read a different number of characters from the serial .

Tried to use this code:

 import serial import time port = serial.Serial(port = "/dev/ttyAMA0", baudrate = 115200) def serial_read(): cde = 't\r' port.write(cde.encode('ascii')) print port.read('кол-во символов') 

if the number of characters / letters in the word " Привет " = 6, and in print port.read() we entered 6 , then we will read them all, if 5 , then only 5 letters, if 7 , then Python is waiting for an additional character / letters. How to force Python to count them by itself.

    1 answer 1

    Apparently, you are using pyserial. Try port.in_waiting to get the number of characters in the input buffer. And then read the amount that is in the buffer.

    • Could you enclose an example of such a code? - Insider
    • @Insider could not. At least, I have nothing to check, and the code is elementary. - Vladimir Martyanov