#鸿蒙通关秘籍#如何在鸿蒙系统中使用USB DDK发送控制读请求?

HarmonyOS
2024-12-13 12:04:46
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
hm673ff11b3d583

在发送控制读请求前,确保已声明接口并获取接口句柄,代码如下:

c struct UsbDdkConfigDescriptor *config = nullptr; OH_Usb_GetConfigDescriptor(deviceId, 1, &config); uint8_t interfaceIndex = 0; uint64_t interfaceHandle = 0; OH_Usb_ClaimInterface(deviceId, interfaceIndex, &interfaceHandle); OH_Usb_FreeConfigDescriptor(config);

然后,定义请求参数并发送控制读请求:

c uint32_t timeout = 1000; struct UsbControlRequestSetup setupRead; setupRead.bmRequestType = 0x80; setupRead.bRequest = 0x08; setupRead.wValue = 0; setupRead.wIndex = 0; setupRead.wLength = 0x01; uint8_t dataRead[256] = {0}; uint32_t dataReadLen = 256; OH_Usb_SendControlReadRequest(interfaceHandle, &setupRead, timeout, dataRead, &dataReadLen);

分享
微博
QQ
微信
回复
2024-12-13 12:54:25
相关问题