# USB Service Development<a name="EN-US_TOPIC_0000001177435986"></a>
# USB Service Development
## When to Use<a name="section312612461984"></a>
## When to Use
In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer.
In Host mode, you can obtain the list of connected devices, enable or disable the devices, manage device access permissions, and perform data transfer or control transfer.
## APIs<a name="section912mcpsimp"></a>
## APIs
The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
The following table lists the USB APIs currently available. For details, see the _API Reference_.
The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md).
| hasRight(deviceName: string): boolean | Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise. |
| requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. |
</th>
| connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device information returned by **getDevices()**. |
</tr>
| getDevices(): Array<Readonly\<USBDevice>> | Obtains the USB device list. |
</thead>
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. |
| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. |
</td>
| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | Claims a USB interface |
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p8666818458"><aname="p8666818458"></a><aname="p8666818458"></a>Checks whether the user, for example, the application or system, has the device access permissions. The value <strongid="b106930333555"><aname="b106930333555"></a><aname="b106930333555"></a>true</strong> is returned if the user has the device access permissions; the value <strongid="b72426431937"><aname="b72426431937"></a><aname="b72426431937"></a>false</strong> is returned otherwise.</p>
| getFileDescriptor(pipe: USBDevicePipe): number | Obtains the file descriptor. |
</td>
| getRawDescriptor(pipe: USBDevicePipe): Uint8Array | Obtains the raw USB descriptor. |
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p18677811454"><aname="p18677811454"></a><aname="p18677811454"></a>Requests the temporary permission for a given application to access the USB device.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p467178204510"><aname="p467178204510"></a><aname="p467178204510"></a>Connects to the USB device based on the device information returned by <strongid="b191413527412"><aname="b191413527412"></a><aname="b191413527412"></a>getDevices()</strong>.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p176715864514"><aname="p176715864514"></a><aname="p176715864514"></a>Obtains the USB device list.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p126812817456"><aname="p126812817456"></a><aname="p126812817456"></a>Sets the USB device configuration.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p136868164513"><aname="p136868164513"></a><aname="p136868164513"></a>Sets a USB interface.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p20859028134917"><aname="p20859028134917"></a><aname="p20859028134917"></a>Claims a USB interface</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p686013285492"><aname="p686013285492"></a><aname="p686013285492"></a>Closes a USB device pipe.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p14860202813493"><aname="p14860202813493"></a><aname="p14860202813493"></a>Releases a USB interface.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p16860202864913"><aname="p16860202864913"></a><aname="p16860202864913"></a>Obtains the file descriptor.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p486042804917"><aname="p486042804917"></a><aname="p486042804917"></a>Obtains the raw USB descriptor.</p>
<tdclass="cellrowborder"valign="top"width="41.410000000000004%"headers="mcps1.2.3.1.2 "><pid="p78605286493"><aname="p78605286493"></a><aname="p78605286493"></a>Performs control transfer.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section980mcpsimp"></a>
You can set a USB device as a host to connect to a device for data transfer. The development procedure is as follows:
You can set a USB device as a host to connect to a device for data transfer. The development procedure is as follows:
...
@@ -211,6 +152,4 @@ You can set a USB device as a host to connect to a device for data transfer. The
...
@@ -211,6 +152,4 @@ You can set a USB device as a host to connect to a device for data transfer. The