如何在 Python 3.7 中向 bytearray 添加字节?

sal*_*inx 4 python arrays pyserial python-3.x

我是 Python 3.7 的新手,我正在尝试使用以下代码从串行端口读取字节。我正在使用pySerial模块并且read()函数返回bytes.

self.uart = serial.Serial()
self.uart.port = '/dev/tty/USB0'
self.uart.baudrate = 115200
self.uart.open()
# buffer for received bytes
packet_bytes = bytearray()
# read and process data from serial port
while True:
    # read single byte from serial port
    current_bytes = self._uart.read()
    if current_bytes is B'$':
        self.process_packet(packet_bytes)
        packet_bytes = bytearray()
    else:
        packet_bytes.append(current_bytes)        <- Error occurs here
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

类型错误:需要一个整数

一些想法如何解决?

Olv*_*ght 11

packet_bytes += bytearray(current_bytes)
Run Code Online (Sandbox Code Playgroud)