[Python] Serial.read in python is losing data

Discussão em 'Python' iniciado por Stack, Fevereiro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I wrote the function below to read data from a serial port. When I call it to read 33 bytes, it stops reading halfway. The bytearray msg returned contains only the first few bytes, the rest is lost. And the last byte read is different from '\n', so I don't know what could be interrupting the reading. But if I set a delay of microseconds between one byte and another on the device that is sending the bytes, the reading occurs normally. How can I solve this in my code, without adding this delay?

    comm = serial.Serial(slaveName, baudrate=115200, timeout=10000)
    def readLen(length):
    msg = comm.read(length)
    return bytearray(msg)
    data = readLen(33)

    Continue reading...

Compartilhe esta Página