fix(core): 修复在线版下usb mini在移动端由于波特率配置错误导致导致工作异常

This commit is contained in:
王立帮
2025-10-23 11:55:33 +08:00
parent 07651c3285
commit b0ccec821d

View File

@@ -212,9 +212,10 @@ class USBMini extends Serial {
this.#endpointOut_ = endpoint.endpointNumber;
}
}
await this.#device_.claimInterface(0);
await this.#device_.claimInterface(this.#interfaceNumber_);
await this.setBaudRate(baud);
super.open(baud);
await this.setBaudRate(baud);
this.onOpen();
this.#addEventsListener_();
}
@@ -237,6 +238,28 @@ class USBMini extends Serial {
if (!this.isOpened() || this.getRawBaudRate() === baud) {
return;
}
const dwDTERate = new Uint8Array([
baud & 0xFF,
(baud >> 8) & 0xFF,
(baud >> 16) & 0xFF,
(baud >> 24) & 0xFF
]);
const bCharFormat = 0x00;
const bParityType = 0x00;
const bDataBits = 0x08;
const lineCoding = new Uint8Array([
...dwDTERate,
bCharFormat,
bParityType,
bDataBits
]);
await this.#device_.controlTransferOut({
requestType: 'class',
recipient: 'interface',
request: 0x20,
value: 0x0000,
index: 0
}, lineCoding);
await super.setBaudRate(baud);
}