Remote device monitor crashes on first keypress

I’m trying to get remote development working with PlatformIO. I’ve successfully uploaded to my STM32 device using the remote upload command. Unfortunately the remote device monitor isn’t working.

The remote monitor connects successfully. I get the serial monitor window up in VSCode, and on the other machine I see the log message saying serial monitoring started and it’s using the correct COM port. As soon as I press a key, however, I get the following crash:

Unhandled Error
Traceback (most recent call last):
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/", line 86, in callWithContext
    return{ILogContext: newCtx}, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/python/", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/", line 243, in doRead
    return self._dataReceived(data)
  File "/home/vscode/.platformio/packages/contrib-pysite/twisted/internet/", line 249, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/", line 33, in dataReceived
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/", line 68, in send_to_server
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/platformio/commands/remote/client/", line 222, in acwrite_data
    self._acwrite_buffer += data
builtins.TypeError: can only concatenate str (not "bytes") to str

Exception in thread rx:
Traceback (most recent call last):
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/urlhandler/", line 171, in read
    raise SerialException('socket disconnected')
serial.serialutil.SerialException: socket disconnected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/", line 954, in _bootstrap_inner

--- exit ---
  File "/usr/lib/python3.9/", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/tools/", line 499, in reader
    data = or 1)
  File "/home/vscode/.platformio/penv/lib/python3.9/site-packages/serial/urlhandler/", line 178, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: socket disconnected

I wasn’t able to find any existing topics on this. Anyone encountered this before and know what might be wrong?

Might be a Python 3.9 incompatibility.

Pert bug to the core at Issues · platformio/platformio-core · GitHub.

Bug opened: Remote device monitor crashes on first keypress · Issue #4068 · platformio/platformio-core · GitHub