0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCode + PlatformIOでアップロード前にシリアルモニターを閉じる

Posted at

はじめに

タイトル通りなのです、私の環境ではVSCode+PlatformIOで開発中にシリアルモニターが自動的に閉じてくれません。結構、ストレスなので何とかしてみる。

経緯

以下は、対応前の事象手順

  • Windows10
  • VSCode 1.105.0
  • PlatformIO IDE 3.3.4
  1. 「Upload And Monitor」実行
  2. ビルドが始まる
  3. アップロードが始まる
  4. シリアルモニターが開く

一回目はいいんだけど、ここからまた

「Upload And Monitor」実行

以下のような画面になる

image.png

COMポートがシリアルモニターに占有されているためのようです。

シリアルモニターを閉じてから再度「Upload And Monitor」実行すればできる。
これがどうもストレス。

設定

image.png

設定ではアップロード前に自動的に閉じるオプションのチェックは入ってるんだけどなぁ。ちゃんと動かないみたい。

対策

いろいろググって見たところ同じ方がおられるようで。

ツールバーの「Upload」ボタンの内容を変更します。
image.png

設定(Ctrl+,) → 拡張機能 → PlatformIO IDE → Toolbar → Settings.jsonで編集 →

修正前
        {
            "text": "$(arrow-right)",
            "tooltip": "PlatformIO: Upload",
            "commands": "platformio-ide.upload"
        },
        
修正後
        {
            "text": "$(arrow-right)",
            "tooltip": "PlatformIO: Upload and Monitor",
            "commands": [
                "workbench.action.terminal.kill",
                "platformio-ide.uploadAndMonitor"
            ]
        },

元は 「Upload」 だけだったんですけど、どうせシリアルモニターを開くので 「Upload and Monitor」にしてます。ちょっとチラつくけど許容範囲です。

あと、ショートカットキーも割り当てているのでそっちも変更しておく。
コマンド実行(Ctrl+Shift+P) → Open Keyboard Shortcuts (JSON) → 以下を追加

    {
        "key": "ctrl+shift+l",
        "command": "runCommands",
        "args": {
            "commands": [
                "workbench.action.terminal.kill",
                "platformio-ide.uploadAndMonitor"
            ]
        },
        "when": "resourceExtname == .cpp || resourceExtName == .c || resourceExtname == .h || resourceExtName == .ino"
    }

私は 「Ctrl+Shit+L」に割り当てていますがお好みで。
(拡張機能なしで複数コマンドを書けるようになったみたい)

おわりに

だいぶストレスがなくなりました。
もっと簡単な方法があれば教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?