OpenHarmony开发者论坛
标题:
usb.bulkTransfer批量传输的时候,返回-1
[打印本页]
作者:
mrszhang
时间:
2024-9-7 16:09
标题:
usb.bulkTransfer批量传输的时候,返回-1
[md]### 【问题描述】
1. 单次传输没问题,连续不停的传输的时候,read返回-1。场景需求rfid实时传输,实时获取值,
```
//写
usb.bulkTransfer(this.pipe, outEndpoint, send).then((dataLength: number) => {
if (dataLength >= 0) {
this.message = '发送数据 result write length :' + dataLength
this.regissterUsb = JSON.stringify(send)
console.info("usb writeData result write length : " + dataLength);
} else {
this.message = '发送数据 writeData failed:' + dataLength
console.info("writeData failed");
}
}).catch((error) => {
this.message = '发送数据 writeData error ' + JSON.stringify(error)
console.info("usb writeData error : " + JSON.stringify(error));
})
setTimeout(()=>{
this.inventoryStop()
let buffer = new Uint8Array(270);
//读
usb.bulkTransfer(this.pipe, inEndpoint, buffer).then((dataLength: number) => {
if (dataLength >= 0) {
this.message = '接到数据 result write length :' + dataLength
this.regissterUsb = JSON.stringify(buffer)
showSaveToast('有数据')
console.info("usb writeData result write length : " + dataLength);
} else {
this.message = '接到数据 writeData failed:' + dataLength
console.info("writeData failed");
}
}).catch((error) => {
this.message = '发送数据 writeData error ' + JSON.stringify(error)
console.info("usb writeData error : " + JSON.stringify(error));
})
},3000)
```
### 【运行环境】
硬件:
ROM版本:
DevEvoStudio版本:4.1
SDK版本:
9
[/md]
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5