原创

Arduino在VS Code中输出乱码解决方法


Arduino在VS Code中输出乱码解决方法

一、问题描述

安装了最新版本的Arduino(1.8.13)之后使用VS Code中的插件编译输出中文乱码,如下图所示:
中文乱码
问题的原因应该是插件使用的编码有问题,经过网上搜索发现主要有两种解决方法,第一种是降低Arduino IDE的版本,这显然不是好的解决方案,第二种是修改插件中的一点点代码,目前感觉这种方案没有什么问题,在这里分享一下。

二、操作步骤

1、找到VS Code的Arduino拓展的安装目录,找到util.js这个文件,不同的电脑路径不同,例如我的是:
C:\Users\Daozhi\.vscode\extensions\vsciot-vscode.vscode-arduino-0.4.3\out\src\common\util.j
2、 找到该文件第205行附近的如下代码:

if (os.platform() === "win32") {
    try {
        const chcp = child_process.execSync("chcp.com");
        codepage = chcp.toString().split(":").pop().trim();
    }
    catch (error) {
        outputChannel_1.arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.\
        \rEnsure your path includes %SystemRoot%\\system32\r${error.message}`);
        codepage = "850";
    }
}

3、 将上面的一段代码注释掉。
注释代码
4、重启VS Code,可以看到问题已经修复:
问题解决

软件教程
  • 作者:Daozhi(联系作者)
  • 发表时间:2021-02-23 20:30
  • 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
  • 公众号转载:请在文末添加作者公众号二维码
  • 评论