Update: Arduino下自动根据代码中设置的串口波特率配置串口监视器 (#IAWTZG)

This commit is contained in:
王立帮
2024-10-14 20:24:05 +08:00
parent f82839e936
commit 3eec19ff4a
5 changed files with 98 additions and 65 deletions

View File

@@ -177,17 +177,19 @@ class ElectronSerial extends Serial {
async setBaudRate(baud) {
return new Promise((resolve, reject) => {
if (!this.isOpened() || this.getBaudRate() === baud) {
if (!this.isOpened()
|| this.getBaudRate() === baud
|| !this.baudRateIsLegal(baud)) {
resolve();
return;
}
this.#serialport_.update({ baudRate: baud - 0 }, (error) => {
this.#serialport_.update({ baudRate: baud }, (error) => {
if (error) {
reject(error);
} else {
super.setBaudRate(baud);
resolve();
return;
}
super.setBaudRate(baud);
this.setDTRAndRTS(this.getDTR(), this.getRTS()).finally(resolve);
});
});
}