fix(core): 修复一些情况下串口波特率设置异常
This commit is contained in:
@@ -107,7 +107,7 @@ class Serial {
|
|||||||
#bufferLength_ = 0;
|
#bufferLength_ = 0;
|
||||||
#encoder_ = new TextEncoder('utf8');
|
#encoder_ = new TextEncoder('utf8');
|
||||||
#decoder_ = new TextDecoder('utf8');
|
#decoder_ = new TextDecoder('utf8');
|
||||||
#baud_ = 115200;
|
#baud_ = 0;
|
||||||
#dtr_ = false;
|
#dtr_ = false;
|
||||||
#rts_ = false;
|
#rts_ = false;
|
||||||
#isOpened_ = false;
|
#isOpened_ = false;
|
||||||
@@ -254,6 +254,10 @@ class Serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBaudRate() {
|
getBaudRate() {
|
||||||
|
return this.#baud_ || Serial.getConfig().baudRates;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRawBaudRate() {
|
||||||
return this.#baud_;
|
return this.#baud_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class ElectronSerial extends Serial {
|
|||||||
async setBaudRate(baud) {
|
async setBaudRate(baud) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isOpened()
|
if (!this.isOpened()
|
||||||
|| this.getBaudRate() === baud
|
|| this.getRawBaudRate() === baud
|
||||||
|| !this.baudRateIsLegal(baud)) {
|
|| !this.baudRateIsLegal(baud)) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ class WebSocketSerial extends Serial {
|
|||||||
async setBaudRate(baud) {
|
async setBaudRate(baud) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isOpened()
|
if (!this.isOpened()
|
||||||
|| this.getBaudRate() === baud
|
|| this.getRawBaudRate() === baud
|
||||||
|| !this.baudRateIsLegal(baud)) {
|
|| !this.baudRateIsLegal(baud)) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class WebSerialPort extends Serial {
|
|||||||
|
|
||||||
async setBaudRate(baud) {
|
async setBaudRate(baud) {
|
||||||
if (!this.isOpened()
|
if (!this.isOpened()
|
||||||
|| this.getBaudRate() === baud
|
|| this.getRawBaudRate() === baud
|
||||||
|| !this.baudRateIsLegal(baud)) {
|
|| !this.baudRateIsLegal(baud)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class USBMini extends Serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setBaudRate(baud) {
|
async setBaudRate(baud) {
|
||||||
if (!this.isOpened() || this.getBaudRate() === baud) {
|
if (!this.isOpened() || this.getRawBaudRate() === baud) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await super.setBaudRate(baud);
|
await super.setBaudRate(baud);
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ class USB extends Serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setBaudRate(baud) {
|
async setBaudRate(baud) {
|
||||||
if (!this.isOpened() || this.getBaudRate() === baud) {
|
if (!this.isOpened() || this.getRawBaudRate() === baud) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.#dapLink_.setSerialBaudrate(baud);
|
await this.#dapLink_.setSerialBaudrate(baud);
|
||||||
|
|||||||
Reference in New Issue
Block a user