harmony 鸿蒙USB Usage Guidelines
USB Usage Guidelines
The following procedure uses bulk transfer as an example.
Procedure
- Obtain a USB service instance.
static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance();
- Obtain the USB device list.
std::vector<OHOS::USB::UsbDevice> deviceList;
int32_t ret = g_usbClient.GetDevices(deviceList);
- Apply for device access permissions.
int32_t ret = g_usbClient.RequestRight(device.GetName());
- Open the USB device.
USBDevicePipe pip;
int32_t et = g_usbClient.OpenDevice(device, pip);
- Configure the USB interface.
ret = g_usbClient.ClaimInterface(pip, interface, true); // **interface** indicates an interface of the USB device in **deviceList**.
- Transfer data.
srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
Parameter description: - pipe: pipe for data transfer of the USB device opened. - endpoint: endpoint for data transfer on the USB device. - vdata: binary data block to be transferred or read. - timeout: timeout duration of data transfer.
- Close the USB device.
ret = g_usbClient.Close(pip);
你可能感兴趣的鸿蒙文章
harmony 鸿蒙AI Framework Development
harmony 鸿蒙Application Privilege Configuration Guide
harmony 鸿蒙Setting Up a Development Environment
harmony 鸿蒙Development Guidelines
harmony 鸿蒙Application Framework Overview
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦