1 Star 0 Fork 5K

Kou_Ching / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
subsys-usbservice-guide.md 1.23 KB
一键复制 编辑 原始数据 按行查看 历史

USB Usage Guidelines

The following procedure uses bulk transfer as an example.

Procedure

  1. Obtain a USB service instance.
static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance();
  1. Obtain the USB device list.
std::vector<OHOS::USB::UsbDevice> deviceList;
int32_t ret = g_usbClient.GetDevices(deviceList);
  1. Apply for device access permissions.
int32_t ret = g_usbClient.RequestRight(device.GetName());
  1. Open the USB device.
USBDevicePipe pip;
int32_t et = g_usbClient.OpenDevice(device, pip);
  1. Configure the USB interface.
ret = g_usbClient.ClaimInterface(pip, interface, true);
**interface** indicates an interface of the USB device in **deviceList**.
  1. 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.
  1. Close the USB device.
ret = g_usbClient.Close(pip);
1
https://gitee.com/okc233/docs.git
git@gitee.com:okc233/docs.git
okc233
docs
docs
master

搜索帮助