提交 626cb71c 编写于 作者: W wu-chengwen 提交者: 吴成文

fixed 799b559e from https://gitee.com/wu-chengwen/docs/pulls/3467

fix(usb):add language type
Signed-off-by: Nwu-chengwen <wuchengwen4@huawei.com>
上级 0056bc9f
...@@ -93,7 +93,7 @@ You can set a USB device as a host to connect to a device for data transfer. The ...@@ -93,7 +93,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
1. Obtain the USB device list. 1. Obtain the USB device list.
``` ```js
// Import the USB API package. // Import the USB API package.
import usb from '@ohos.usb'; import usb from '@ohos.usb';
// Obtain the USB device list. // Obtain the USB device list.
...@@ -153,7 +153,7 @@ You can set a USB device as a host to connect to a device for data transfer. The ...@@ -153,7 +153,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
2. Obtain the device operation permissions. 2. Obtain the device operation permissions.
``` ```js
var deviceName = deviceList[0].name; var deviceName = deviceList[0].name;
// Request the permissions to operate a specified device. // Request the permissions to operate a specified device.
usb.requestRight(deviceName).then(hasRight => { usb.requestRight(deviceName).then(hasRight => {
...@@ -165,7 +165,7 @@ You can set a USB device as a host to connect to a device for data transfer. The ...@@ -165,7 +165,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
3. Open the device. 3. Open the device.
``` ```js
// Open the device, and obtain the USB device pipe for data transfer. // Open the device, and obtain the USB device pipe for data transfer.
var pipe = usb.connectDevice(deviceList[0]); var pipe = usb.connectDevice(deviceList[0]);
/* /*
...@@ -177,7 +177,7 @@ You can set a USB device as a host to connect to a device for data transfer. The ...@@ -177,7 +177,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
4. Perform data transfer. 4. Perform data transfer.
``` ```js
/* /*
Read data. Select the corresponding RX endpoint from deviceList for data transfer. Read data. Select the corresponding RX endpoint from deviceList for data transfer.
(endpoint.direction == 0x80); dataUint8Array indicates the data to read. The data type is Uint8Array. (endpoint.direction == 0x80); dataUint8Array indicates the data to read. The data type is Uint8Array.
...@@ -208,7 +208,7 @@ You can set a USB device as a host to connect to a device for data transfer. The ...@@ -208,7 +208,7 @@ You can set a USB device as a host to connect to a device for data transfer. The
5. Release the USB interface, and close the USB device. 5. Release the USB interface, and close the USB device.
``` ```js
usb.releaseInterface(pipe, interface); usb.releaseInterface(pipe, interface);
usb.closePipe(pipe); usb.closePipe(pipe);
``` ```
......
# USB Usage Demo<a name="EN-US_TOPIC_0000001092792986"></a> # USB Usage Demo<a name="EN-US_TOPIC_0000001092792986"></a>
``` ```cpp
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <map> #include <map>
......
...@@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example. ...@@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example.
1. Obtain a USB service instance. 1. Obtain a USB service instance.
``` ```cpp
static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance();
``` ```
2. Obtain the USB device list. 2. Obtain the USB device list.
``` ```cpp
std::vector<OHOS::USB::UsbDevice> deviceList; std::vector<OHOS::USB::UsbDevice> deviceList;
int32_t ret = g_usbClient.GetDevices(deviceList); int32_t ret = g_usbClient.GetDevices(deviceList);
``` ```
3. Apply for device access permissions. 3. Apply for device access permissions.
``` ```cpp
int32_t ret = g_usbClient.RequestRight(device.GetName()); int32_t ret = g_usbClient.RequestRight(device.GetName());
``` ```
4. Open the USB device. 4. Open the USB device.
``` ```cpp
USBDevicePipe pip; USBDevicePipe pip;
int32_t et = g_usbClient.OpenDevice(device, pip); int32_t et = g_usbClient.OpenDevice(device, pip);
``` ```
5. Configure the USB interface. 5. Configure the USB interface.
``` ```cpp
ret = g_usbClient.ClaimInterface(pip, interface, true); ret = g_usbClient.ClaimInterface(pip, interface, true);
**interface** indicates an interface of the USB device in **deviceList**. **interface** indicates an interface of the USB device in **deviceList**.
``` ```
6. Transfer data. 6. Transfer data.
``` ```cpp
srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
``` ```
- **pipe** indicates the pipe for data transfer of the USB device opened. - **pipe** indicates the pipe for data transfer of the USB device opened.
...@@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); ...@@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
7. Close the USB device. 7. Close the USB device.
``` ```cpp
ret = g_usbClient.Close(pip); ret = g_usbClient.Close(pip);
``` ```
...@@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
1. 获取设备列表。 1. 获取设备列表。
``` ```js
// 导入usb接口api包。 // 导入usb接口api包。
import usb from '@ohos.usb'; import usb from '@ohos.usb';
// 获取设备列表。 // 获取设备列表。
...@@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
``` ```
2. 获取设备操作权限。 2. 获取设备操作权限。
``` ```js
var deviceName = deviceList[0].name; var deviceName = deviceList[0].name;
// 申请操作指定的device的操作权限。 // 申请操作指定的device的操作权限。
usb.requestRight(deviceName).then(hasRight => { usb.requestRight(deviceName).then(hasRight => {
...@@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
``` ```
3. 打开Device设备。 3. 打开Device设备。
``` ```js
// 打开设备,获取数据传输通道。 // 打开设备,获取数据传输通道。
var pipe = usb.connectDevice(deviceList[0]); var pipe = usb.connectDevice(deviceList[0]);
/* /*
...@@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
``` ```
4. 数据传输。 4. 数据传输。
``` ```js
/* /*
读取数据,在device信息中选取对应数据接收的endpoint来做数据传输 读取数据,在device信息中选取对应数据接收的endpoint来做数据传输
(endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。 (endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。
...@@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ...@@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例
``` ```
5. 释放接口,关闭设备。 5. 释放接口,关闭设备。
``` ```js
usb.releaseInterface(pipe, interface1); usb.releaseInterface(pipe, interface1);
usb.closePipe(pipe); usb.closePipe(pipe);
``` ```
# USB服务子系使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a> # USB服务子系使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
``` ```cpp
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <map> #include <map>
......
...@@ -8,46 +8,46 @@ ...@@ -8,46 +8,46 @@
1. 获取usb service实例 1. 获取usb service实例
``` ```cpp
static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance();
``` ```
2. 获取usb设备列表 2. 获取usb设备列表
``` ```cpp
std::vector<OHOS::USB::UsbDevice> deviceList; std::vector<OHOS::USB::UsbDevice> deviceList;
int32_t ret = g_usbClient.GetDevices(deviceList); int32_t ret = g_usbClient.GetDevices(deviceList);
``` ```
3. 申请设备权限 3. 申请设备权限
``` ```cpp
int32_t ret = g_usbClient.RequestRight(device.GetName()); int32_t ret = g_usbClient.RequestRight(device.GetName());
``` ```
4. 打开设备 4. 打开设备
``` ```cpp
USBDevicePipe pip; USBDevicePipe pip;
int32_t et = g_usbClient.OpenDevice(device, pip); int32_t et = g_usbClient.OpenDevice(device, pip);
``` ```
5. 配置设备接口 5. 配置设备接口
``` ```cpp
ret = g_usbClient.ClaimInterface(pip, interface, true); ret = g_usbClient.ClaimInterface(pip, interface, true);
interfacedeviceListdeviceinterface interfacedeviceListdeviceinterface
``` ```
6. 数据传输 6. 数据传输
``` ```cpp
srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); srvClient.BulkTransfer(pipe, endpoint, vdata, timeout);
``` ```
pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长. pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长.
7. 关闭设备 7. 关闭设备
``` ```cpp
ret = g_usbClient.Close(pip); ret = g_usbClient.Close(pip);
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册