From f224d7b3da8ba411b32282dfbf362cc0603ee3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 9 Mar 2025 16:15:58 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E4=B8=8Bmixgo=E5=92=8Cmpython=E6=9D=BF=E5=8D=A1?= =?UTF-8?q?=E4=BD=BF=E7=94=A8ampy=E6=97=A0=E6=B3=95=E4=B8=8A=E8=BD=BD?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boards/default/micropython_esp32/config.json | 10 ++++- .../micropython_esp32/origin/config.json | 10 ++++- .../mixly-modules/common/statusbar-serial.js | 12 +++--- common/modules/mixly-modules/deps.json | 1 + common/modules/mixly-modules/electron/ampy.js | 4 +- common/modules/mixly-modules/web/ampy.js | 38 +++++++++---------- common/msg/mixly/en.json | 3 ++ common/msg/mixly/zh-hans.json | 3 ++ common/msg/mixly/zh-hant.json | 3 ++ 9 files changed, 55 insertions(+), 29 deletions(-) diff --git a/boards/default/micropython_esp32/config.json b/boards/default/micropython_esp32/config.json index 000cc780..5507c71f 100644 --- a/boards/default/micropython_esp32/config.json +++ b/boards/default/micropython_esp32/config.json @@ -52,7 +52,15 @@ "yMin": 0, "pointNum": 100, "rts": false, - "dtr": true + "dtr": true, + "micropython:esp32:mixgo": { + "rts": true, + "dtr": true + }, + "micropython:esp32:mpython": { + "rts": true, + "dtr": true + } }, "lib": { "mixly": { diff --git a/boards/default_src/micropython_esp32/origin/config.json b/boards/default_src/micropython_esp32/origin/config.json index 000cc780..5507c71f 100644 --- a/boards/default_src/micropython_esp32/origin/config.json +++ b/boards/default_src/micropython_esp32/origin/config.json @@ -52,7 +52,15 @@ "yMin": 0, "pointNum": 100, "rts": false, - "dtr": true + "dtr": true, + "micropython:esp32:mixgo": { + "rts": true, + "dtr": true + }, + "micropython:esp32:mpython": { + "rts": true, + "dtr": true + } }, "lib": { "mixly": { diff --git a/common/modules/mixly-modules/common/statusbar-serial.js b/common/modules/mixly-modules/common/statusbar-serial.js index b5954df4..d312917c 100644 --- a/common/modules/mixly-modules/common/statusbar-serial.js +++ b/common/modules/mixly-modules/common/statusbar-serial.js @@ -458,13 +458,11 @@ class StatusBarSerial extends PageBase { async open() { await this.#serial_.open(this.#config_.baud); - if (goog.isElectron || Env.hasSocketServer) { - await this.#serial_.sleep(200); - try { - await this.#serial_.setDTRAndRTS(this.#config_.dtr, this.#config_.rts); - } catch (error) { - Debug.error(error); - } + await this.#serial_.sleep(200); + try { + await this.#serial_.setDTRAndRTS(this.#config_.dtr, this.#config_.rts); + } catch (error) { + Debug.error(error); } if (SELECTED_BOARD?.serial?.ctrlCBtn) { await this.#serial_.sleep(500); diff --git a/common/modules/mixly-modules/deps.json b/common/modules/mixly-modules/deps.json index f90fa53a..57506ad8 100644 --- a/common/modules/mixly-modules/deps.json +++ b/common/modules/mixly-modules/deps.json @@ -1236,6 +1236,7 @@ "Mustache", "Mixly.Ampy", "Mixly.Env", + "Mixly.Msg", "Mixly.Serial", "Mixly.Electron" ], diff --git a/common/modules/mixly-modules/electron/ampy.js b/common/modules/mixly-modules/electron/ampy.js index 441c3b8b..adeed219 100644 --- a/common/modules/mixly-modules/electron/ampy.js +++ b/common/modules/mixly-modules/electron/ampy.js @@ -4,6 +4,7 @@ goog.require('path'); goog.require('Mustache'); goog.require('Mixly.Ampy'); goog.require('Mixly.Env'); +goog.require('Mixly.Msg'); goog.require('Mixly.Serial'); goog.require('Mixly.Electron'); goog.provide('Mixly.Electron.Ampy'); @@ -11,6 +12,7 @@ goog.provide('Mixly.Electron.Ampy'); const { Ampy, Env, + Msg, Serial, Electron } = Mixly; @@ -102,7 +104,7 @@ class AmpyExt extends Ampy { async exec(port, command) { const portsName = Serial.getCurrentPortsName(); if (!portsName.includes(port)) { - throw new Error('无可用串口'); + throw new Error(Msg.Lang['statusbar.serial.noPort']); return; } const { mainStatusBarTabs } = Mixly; diff --git a/common/modules/mixly-modules/web/ampy.js b/common/modules/mixly-modules/web/ampy.js index 54e8cd93..5fa9e2a3 100644 --- a/common/modules/mixly-modules/web/ampy.js +++ b/common/modules/mixly-modules/web/ampy.js @@ -84,10 +84,10 @@ class AmpyExt extends Ampy { } } if (nowTime - startTime >= timeout) { - throw new Error(ending + '查找失败'); + return ''; } if (!this.isActive()) { - throw new Error('数据读取中断'); + throw new Error(Msg.Lang['ampy.dataReadInterrupt']); } await this.#device_.sleep(100); } @@ -163,14 +163,14 @@ class AmpyExt extends Ampy { } this.#active_ = true; await this.#device_.open(115200); - await this.#device_.sleep(500); + /*await this.#device_.sleep(500); const { SELECTED_BOARD } = Config; if (SELECTED_BOARD?.serial && SELECTED_BOARD.serial?.dtr !== undefined && SELECTED_BOARD.serial?.rts !== undefined) { const { dtr, rts } = SELECTED_BOARD.serial; await this.#device_.setDTRAndRTS(dtr, rts); - } + }*/ await this.#device_.sleep(500); await this.#device_.sendBuffer([2]); if (!await this.interrupt()) { @@ -197,7 +197,7 @@ class AmpyExt extends Ampy { async get(filename, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.GET, { path: filename @@ -205,7 +205,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); str = str.replace('\x04\x04', ''); @@ -218,7 +218,7 @@ class AmpyExt extends Ampy { async put(filename, code) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } let str = `file = open('${filename}', 'wb')\n`; const buffer = this.#device_.encode(code); @@ -241,7 +241,7 @@ class AmpyExt extends Ampy { async ls(directory = '/', longFormat = true, recursive = false, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } let code = ''; if (longFormat) { @@ -260,7 +260,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); let info = null; @@ -273,7 +273,7 @@ class AmpyExt extends Ampy { async mkdir(directory, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.MKDIR, { path: directory @@ -281,7 +281,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); if (str.indexOf('OSError') === -1) { @@ -292,7 +292,7 @@ class AmpyExt extends Ampy { async mkfile(file, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.MKFILE, { path: file @@ -300,7 +300,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); if (str.indexOf('OSError') === -1) { @@ -311,7 +311,7 @@ class AmpyExt extends Ampy { async rename(oldname, newname, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.RENAME, { oldPath: oldname, @@ -320,7 +320,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); if (str.indexOf('OSError') === -1) { @@ -331,7 +331,7 @@ class AmpyExt extends Ampy { async rm(filename, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.RM, { path: filename @@ -339,7 +339,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); if (str.indexOf('OSError') === -1) { @@ -350,7 +350,7 @@ class AmpyExt extends Ampy { async rmdir(directory, timeout = 5000) { if (!this.isActive()) { - throw new Error('串口未打开'); + throw new Error(Msg.Lang['ampy.portIsNotOpen']); } const code = Mustache.render(AmpyExt.RMDIR, { path: directory @@ -358,7 +358,7 @@ class AmpyExt extends Ampy { await this.exec(code); await this.#device_.sleep(100); if (!await this.readUntil('ok', true, timeout)) { - throw new Error('无法执行python代码'); + throw new Error(Msg.Lang['ampy.executePythonCodeFailed']); } let str = await this.readUntil('>', false, timeout); if (str.indexOf('OSError') === -1) { diff --git a/common/msg/mixly/en.json b/common/msg/mixly/en.json index 2a44ede1..c3658ab0 100644 --- a/common/msg/mixly/en.json +++ b/common/msg/mixly/en.json @@ -317,6 +317,9 @@ "ampy.enterRawREPLFailed": "Unable to enter Raw REPL", "ampy.exitRawREPLFailed": "Unable to exit Raw REPL", "ampy.exitREPLFailed": "Unable to exit REPL", + "ampy.portIsNotOpen": "Serial port is not open", + "ampy.executePythonCodeFailed": "Unable to execute python code", + "ampy.dataReadInterrupt": "Data reading interrupted", "editor.contextMenu.cut": "Cut", "editor.contextMenu.copy": "Copy", "editor.contextMenu.paste": "Paste", diff --git a/common/msg/mixly/zh-hans.json b/common/msg/mixly/zh-hans.json index ef3266d4..5a26c732 100644 --- a/common/msg/mixly/zh-hans.json +++ b/common/msg/mixly/zh-hans.json @@ -317,6 +317,9 @@ "ampy.enterRawREPLFailed": "无法进入Raw REPL", "ampy.exitRawREPLFailed": "无法退出Raw REPL", "ampy.exitREPLFailed": "无法退出REPL", + "ampy.portIsNotOpen": "串口未打开", + "ampy.executePythonCodeFailed": "无法执行python代码", + "ampy.dataReadInterrupt": "数据读取中断", "editor.contextMenu.cut": "剪切", "editor.contextMenu.copy": "复制", "editor.contextMenu.paste": "粘贴", diff --git a/common/msg/mixly/zh-hant.json b/common/msg/mixly/zh-hant.json index 82df240b..ef15734f 100644 --- a/common/msg/mixly/zh-hant.json +++ b/common/msg/mixly/zh-hant.json @@ -317,6 +317,9 @@ "ampy.enterRawREPLFailed": "無法進入Raw REPL", "ampy.exitRawREPLFailed": "無法退出Raw REPL", "ampy.exitREPLFailed": "無法退出REPL", + "ampy.portIsNotOpen": "串列埠未開啟", + "ampy.executePythonCodeFailed": "無法執行python程式碼", + "ampy.dataReadInterrupt": "資料讀取中斷", "editor.contextMenu.cut": "剪下", "editor.contextMenu.copy": "複製", "editor.contextMenu.paste": "貼上",