完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
DAYU200的开发板,openharmony3.2的系统,sdk版本是V9;
1、打开设备,获取权限,连接设备以及注册通讯接口,都成功; 批量传输写入数据的时候,catch到-1的错误,是什么原因? 2、控制传输时,控制传输参数中没有长度的参数,发送的时候usb请求头中的长度位是0,没有发送要发送的数据,是什么问题? 代码片段: let usbDevices: any [] = usb.getDevices() Logger.info(TAG, `usb getDeviceList 000 is : ${JSON.stringify(usbDevices)}`) if (CheckEmptyUtils.isEmpty(usbDevices)) { Logger.info(TAG, `usbDevices is null`) return -4; } if (CheckEmptyUtils.isEmptyArray(usbDevices)) { Logger.info(TAG, `usb getDeviceList is null`) return -4; } for (let index = 0; index < usbDevices.length; index++) { Logger.info(TAG, `usb this.devices ${index} : ${usbDevices[index].vendorId}`) if(usbDevices[index].vendorId==0x2796){ this.device =usbDevices[index]; if(!usb.hasRight(this.device.name)) { Logger.info(TAG, "usb requestRight"); usb.requestRight(this.device.name).then(hasRight => { Logger.info(TAG, "usb device request right result: " + hasRight); this.pipe = usb.connectDevice(this.device); this.interface1 = this.device.configs[0].interfaces[0]; this.inEndpoint = this.interface1.endpoints[0]; this.outEndpoint = this.interface1.endpoints[1]; let r = usb.claimInterface(this.pipe, this.interface1,true); Logger.info(TAG, "usb claimInterface : " + r); }).catch(error => { Logger.info(TAG, "usb device request right failed : " + error); return -1; }); }else{ this.pipe = usb.connectDevice(this.device); this.interface1 = this.device.configs[0].interfaces[0]; this.inEndpoint = this.interface1.endpoints[0]; this.outEndpoint = this.interface1.endpoints[1]; let r = usb.claimInterface(this.pipe, this.interface1,true); Logger.info(TAG, "usb claimInterface : " + r); } return 0; } } 批量传输 let outParam= { request: 9, reqType: 1, target:1, value: 0x0200, index: 0x0000, data: sendStr } usb.bulkTransfer(that.pipe, that.outEndpoint, sendStr, timeout*1000).then(dataLength => { if (dataLength >= 0) { Logger.info(TAG,"usb writeData result write length : " + dataLength); } else { Logger.info(TAG,"writeData failed"); reject("writeData failed"); } }).catch(error => { Logger.info(TAG,"usb writeData error : " + JSON.stringify(error)); reject("usb writeData error : " + JSON.stringify(error)); }); 控制传输 usb.controlTransfer(that.pipe,outParam,3000).then(dataLength => { Logger.info(TAG,"usb writeData result write length : " + dataLength); if (dataLength >= 0) { Logger.info(TAG,"usb writeData result write susses length : " + dataLength); } else { Logger.info(TAG,"writeData failed"); reject("writeData failed"); } }).catch(error => { Logger.info(TAG,"usb writeData error : " + JSON.stringify(error)); reject("usb writeData error : " + JSON.stringify(error)); }); |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
575 浏览 0 评论
764 浏览 0 评论
666 浏览 0 评论
线上逛展 | 沉浸探索第三届OpenHarmony技术大会五大展区
653 浏览 0 评论
947 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-21 19:56 , Processed in 0.504238 second(s), Total 40, Slave 32 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号