diff --git a/en/application-dev/device/usb-guidelines.md b/en/application-dev/device/usb-guidelines.md index 71c6d0b796827db454b51c1e439deec9ddb738c7..46304e882adcc8f8fbd69daf30cbe58a565696cd 100644 --- a/en/application-dev/device/usb-guidelines.md +++ b/en/application-dev/device/usb-guidelines.md @@ -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. - ``` + ```js // Import the USB API package. import usb from '@ohos.usb'; // 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 2. Obtain the device operation permissions. - ``` + ```js var deviceName = deviceList[0].name; // Request the permissions to operate a specified device. 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 3. Open the device. - ``` + ```js // Open the device, and obtain the USB device pipe for data transfer. 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 4. Perform data transfer. - ``` + ```js /* 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. @@ -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. - ``` + ```js usb.releaseInterface(pipe, interface); usb.closePipe(pipe); ``` diff --git a/en/device-dev/subsystems/subsys-usbservice-demo.md b/en/device-dev/subsystems/subsys-usbservice-demo.md index 80506e955cea844f4cca1b3552f0f1828fcc77f8..d39ca0544427d05db7b8a8b55f29ed5e8955b280 100644 --- a/en/device-dev/subsystems/subsys-usbservice-demo.md +++ b/en/device-dev/subsystems/subsys-usbservice-demo.md @@ -1,7 +1,7 @@ # USB Usage Demo -``` +```cpp #include #include #include diff --git a/en/device-dev/subsystems/subsys-usbservice-guide.md b/en/device-dev/subsystems/subsys-usbservice-guide.md index 6ccfc2594dafaab234dac597c3aee24b1d60ccb5..090bb05fc948ab10e824ddf7839a2c421e8d5dfe 100644 --- a/en/device-dev/subsystems/subsys-usbservice-guide.md +++ b/en/device-dev/subsystems/subsys-usbservice-guide.md @@ -7,40 +7,40 @@ The following procedure uses bulk transfer as an example. 1. Obtain a USB service instance. -``` +```cpp static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); ``` 2. Obtain the USB device list. -``` +```cpp std::vector deviceList; int32_t ret = g_usbClient.GetDevices(deviceList); ``` 3. Apply for device access permissions. -``` +```cpp int32_t ret = g_usbClient.RequestRight(device.GetName()); ``` 4. Open the USB device. -``` +```cpp USBDevicePipe pip; int32_t et = g_usbClient.OpenDevice(device, pip); ``` 5. Configure the USB interface. -``` +```cpp ret = g_usbClient.ClaimInterface(pip, interface, true); **interface** indicates an interface of the USB device in **deviceList**. ``` 6. Transfer data. -``` +```cpp srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); ``` - **pipe** indicates the pipe for data transfer of the USB device opened. @@ -50,6 +50,6 @@ srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); 7. Close the USB device. -``` +```cpp ret = g_usbClient.Close(pip); ``` diff --git a/zh-cn/application-dev/device/usb-guidelines.md b/zh-cn/application-dev/device/usb-guidelines.md index e652c76123af68d7a4237af194761bc5eaf15490..d3bf99be8b12623e47df7d87fa28c013ed48b2ad 100644 --- a/zh-cn/application-dev/device/usb-guidelines.md +++ b/zh-cn/application-dev/device/usb-guidelines.md @@ -38,7 +38,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 1. 获取设备列表。 - ``` + ```js // 导入usb接口api包。 import usb from '@ohos.usb'; // 获取设备列表。 @@ -97,7 +97,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ``` 2. 获取设备操作权限。 - ``` + ```js var deviceName = deviceList[0].name; // 申请操作指定的device的操作权限。 usb.requestRight(deviceName).then(hasRight => { @@ -108,7 +108,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ``` 3. 打开Device设备。 - ``` + ```js // 打开设备,获取数据传输通道。 var pipe = usb.connectDevice(deviceList[0]); /* @@ -119,7 +119,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ``` 4. 数据传输。 - ``` + ```js /* 读取数据,在device信息中选取对应数据接收的endpoint来做数据传输 (endpoint.direction == 0x80);dataUint8Array是要读取的数据,类型为Uint8Array。 @@ -149,7 +149,7 @@ USB设备可作为Host设备连接Device设备进行数据传输。开发示例 ``` 5. 释放接口,关闭设备。 - ``` + ```js usb.releaseInterface(pipe, interface1); usb.closePipe(pipe); ``` diff --git a/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md b/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md index 523c048db6533490476a5721d2f66adace16fcd9..ad6e84ec1ce098166779ea978ed39345448eda09 100644 --- a/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md +++ b/zh-cn/device-dev/subsystems/subsys-usbservice-demo.md @@ -1,7 +1,7 @@ # USB服务子系统使用实例 -``` +```cpp #include #include #include diff --git a/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md b/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md index b62be12bf360bdcce24ef621ca349d4d629dad90..d66d7c654940a5098e480d3ba18eb8fa40ec2b00 100644 --- a/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md +++ b/zh-cn/device-dev/subsystems/subsys-usbservice-guide.md @@ -7,46 +7,46 @@ 1. 获取usb service实例 -``` +```cpp static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance(); ``` 2. 获取usb设备列表 -``` +```cpp std::vector deviceList; int32_t ret = g_usbClient.GetDevices(deviceList); ``` 3. 申请设备权限 -``` +```cpp int32_t ret = g_usbClient.RequestRight(device.GetName()); ``` 4. 打开设备 -``` +```cpp USBDevicePipe pip; int32_t et = g_usbClient.OpenDevice(device, pip); ``` 5. 配置设备接口 -``` +```cpp ret = g_usbClient.ClaimInterface(pip, interface, true); interface为deviceList中device的interface。 ``` 6. 数据传输 -``` +```cpp srvClient.BulkTransfer(pipe, endpoint, vdata, timeout); ``` pipe为打开设备后的数据传输通道,endpoint为device中数据传输的端点,vdata是需要传输或读取的二进制数据块,timeout为传输超时时长。 7. 关闭设备 -``` +```cpp ret = g_usbClient.Close(pip); ```