Update: 优化在线版serial模块

This commit is contained in:
王立帮
2025-03-07 12:25:15 +08:00
parent ec7359c53e
commit 4bbd2dcc96
5 changed files with 46 additions and 48 deletions

View File

@@ -145,7 +145,7 @@ class USB extends Serial {
const portsName = Serial.getCurrentPortsName();
const currentPortName = this.getPortName();
if (!portsName.includes(currentPortName)) {
throw new Error('无可用串口');
throw new Error('no device available');
}
if (this.isOpened()) {
return;
@@ -192,11 +192,11 @@ class USB extends Serial {
}
async sendBuffer(buffer) {
if (typeof buffer.unshift === 'function') {
if (buffer.constructor.name !== 'Uint8Array') {
buffer.unshift(buffer.length);
buffer = new Uint8Array(buffer).buffer;
buffer = new Uint8Array(buffer);
}
return this.#dapLink_.send(132, buffer);
await this.#dapLink_.send(132, buffer);
}
async setDTRAndRTS(dtr, rts) {