[Python] Python writing list of bytes to serial port

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

  1. Stack

    Stack Membro Participativo

    From reading serial data input I have a queue named rxQueue, which is copied to a list named rxData.
    Then, for testing, the list should be send back to the sender over serial.
    But writing to serial, I always get the Exception " 'bytes' object cannot be interpreted as an integer ".
    I've read many posts, but none of the solutions seem to work for me. (Python 3.13.2 )
    What am I doing wrong?

    rxQueue shows in the debugger (in this case) something like

    0 = b'\x02'
    1 = b'\x01'
    2 = b'\x01'
    3 = b'\x00'
    4 = b'\x01'
    5 = b'\x00'
    6 = b'E'
    7 = b'T'
    8 = b'X'
    9 = b'\x03'
    len() = 10

    COMport = serial.Serial(COMportName, baudrate=baudRate, timeout=.5)

    rxData = list (rxQueue.queue) # rxData looks the same as rxQueue in the debugger

    byteArray = bytearray(rxData) # Exception: " 'bytes' object cannot be interpreted as an integer "

    COMport.write(byteArray)

    Continue reading...

Compartilhe esta Página