[Python] pyserial doesnt read full line

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    I want to read data from my arduino and show it on a tkinter window, it works nicely but when I sent the Data on the arduino faster then every 10ms it resevieses many lines that are not full like this:

    'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']
    ⚠️ Invalid line, skipped: ['0', '0', '0', '0', '0', '0', '0', '0', '0', 'Malik']


    The weird thing is when i sent it at 10ms speed it works, just sometimes not when i move the window. Hope somebody can help me here is my code:

    def read_Serial_Values(self):
    read_Line = ReadLine(ser)
    self.raw_Input = read_Line.readline().decode('utf-8').strip()
    # if self.is_Data_Here():
    # print("!Overload!")
    # self.trash = ser.read_all()
    self.raw_Listet_Input = [x for x in self.raw_Input.split(",") if x]
    if len(self.raw_Listet_Input) < 21:
    print("⚠️ Invalid line, skipped:", self.raw_Listet_Input)
    return
    self.Inp_manager.save_Repeating_Input(self.raw_Listet_Input)

    def is_Data_Here(self):
    if ser.in_waiting >0:
    return True
    return False


    class ReadLine:
    def __init__(self, s):
    self.buf = bytearray()
    self.s = s

    def readline(self):
    i = self.buf.find(b"\n")
    if i >= 0:
    r = self.buf[:i+1]
    self.buf = self.buf[i+1:]
    return r
    while True:
    i = max(1, min(2048, self.s.in_waiting))
    data = self.s.read(i)
    i = data.find(b"\n")
    if i >= 0:
    r = self.buf + data[:i+1]
    self.buf[0:] = data[i+1:]
    return r
    else:
    self.buf.extend(data)


    I have tried changing the timeout but that didnt changed anything and I also changed the way the programm recevies the lines.

    Continue reading...

Compartilhe esta Página