1# @ohos.driver.deviceManager (Peripheral Management) (System API) 2 3The **deviceManager** module provides the functions of managing peripheral devices, including querying information about peripherals and their drivers. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.driver.deviceManager (Peripheral Management)](js-apis-driver-deviceManager.md). 9 10## Modules to Import 11 12```ts 13import { deviceManager } from '@kit.DriverDevelopmentKit'; 14``` 15 16## deviceManager.queryDeviceInfo 17 18queryDeviceInfo(deviceId?: number): Array<Readonly<DeviceInfo>> 19 20Obtains the list of detailed information about peripherals. If the device has no peripheral device connected, an empty list is returned. 21 22**System API**: This is a system API. 23 24**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 25 26**System capability**: SystemCapability.Driver.ExternalDevice 27 28**Parameters** 29 30| Name | Type | Mandatory | Description | 31|----------|--------|-----|------------------------| 32| deviceId | number | No | Device ID, which can be obtained by **queryDevices**.| 33 34**Return value** 35 36| Type | Description | 37|--------------------------------------------------------|-------------| 38| Array<Readonly<[DeviceInfo](#deviceinfo)>> | List of detailed information about peripherals.| 39 40**Error codes** 41 42| ID | Error Message | 43|----------|-----------------------------------------------------------------------| 44| 201 | The permission check failed. | 45| 202 | Permission denied. A non-system application cannot call a system API. | 46| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 47| 26300001 | ExternalDeviceManager service exception. | 48 49**Example** 50 51```ts 52import { deviceManager } from '@kit.DriverDevelopmentKit'; 53import { BusinessError } from '@kit.BasicServicesKit'; 54 55try { 56 // For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId. 57 let deviceInfos : Array<deviceManager.DeviceInfo> = deviceManager.queryDeviceInfo(12345678); 58 for (let item of deviceInfos) { 59 console.info(`Device id is ${item.deviceId}`) 60 } 61} catch (error) { 62 let err: BusinessError = error as BusinessError; 63 console.error(`Failed to query device info. Code is ${err.code}, message is ${err.message}`); 64} 65``` 66## deviceManager.queryDriverInfo 67 68queryDriverInfo(driverUid?: string): Array<Readonly<DriverInfo>> 69 70Obtains the list of detailed information about peripheral drivers. If the device has no peripheral device connected, an empty list is returned. 71 72**System API**: This is a system API. 73 74**Required permissions**: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER 75 76**System capability**: SystemCapability.Driver.ExternalDevice 77 78**Parameters** 79 80| Name | Type | Mandatory | Description | 81|-----------|--------|-----|----------------------------| 82| driverUid | string | No | Driver UID, which can be obtained by using **queryDeviceInfo**.| 83 84**Return value** 85 86| Type | Description | 87|--------------------------------------------------------|---------------| 88| Array<Readonly<[DriverInfo](#driverinfo)>> | List of detailed information about peripheral drivers.| 89 90**Error codes** 91 92| ID | Error Message | 93|----------|-----------------------------------------------------------------------| 94| 201 | The permission check failed. | 95| 202 | Permission denied. A non-system application cannot call a system API. | 96| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 97| 26300001 | ExternalDeviceManager service exception. | 98 99**Example** 100 101```ts 102import { deviceManager } from '@kit.DriverDevelopmentKit'; 103import { BusinessError } from '@kit.BasicServicesKit'; 104 105try { 106 // In this example, driver-12345 is the driver UID. During application development, you can use queryDeviceInfo to query the driver UID and use it as the input parameter. 107 let driverInfos : Array<deviceManager.DriverInfo> = deviceManager.queryDriverInfo("driver-12345"); 108 for (let item of driverInfos) { 109 console.info(`driver name is ${item.driverName}`) 110 } 111} catch (error) { 112 let err: BusinessError = error as BusinessError; 113 console.error(`Failed to query driver info. Code is ${err.code}, message is ${err.message}`); 114} 115``` 116 117## DeviceInfo 118 119Defines the detailed information about a device. 120 121**System API**: This is a system API. 122 123**System capability**: SystemCapability.Driver.ExternalDevice 124 125| Name | Type | Mandatory | Description | 126|-----------------|---------|-----|-------------| 127| deviceId | number | Yes | Device ID. | 128| isDriverMatched | boolean | Yes | Whether the device matches the driver. | 129| driverUid | string | No | UID of the driver matching the device.| 130 131## USBDeviceInfo 132 133Defines detailed information about the USB device. It is inherited from [DeviceInfo](#deviceinfo). 134 135**System API**: This is a system API. 136 137**System capability**: SystemCapability.Driver.ExternalDevice 138 139| Name | Type | Mandatory | Description | 140|-------------------|--------------------------------------------------------------------|-----|------------------| 141| vendorId | number | Yes | Vendor ID of the USB device. | 142| productId | number | Yes | Product ID of the USB device.| 143| interfaceDescList | Array<Readonly<[USBInterfaceDesc](#usbinterfacedesc)>> | Yes | List of interface descriptors of the USB device. | 144 145## USBInterfaceDesc 146 147Defines the interface descriptor of a USB device. 148 149**System API**: This is a system API. 150 151**System capability**: SystemCapability.Driver.ExternalDevice 152 153| Name | Type | Mandatory | Description | 154|------------------|--------|-----|--------| 155| bInterfaceNumber | number | Yes | Interface ID. | 156| bClass | number | Yes | Interface class. | 157| bSubClass | number | Yes | Interface subclass.| 158| bProtocol | number | Yes | Interface protocol. | 159 160## DriverInfo 161 162Defines detailed information about a driver. 163 164**System API**: This is a system API. 165 166**System capability**: SystemCapability.Driver.ExternalDevice 167 168| Name | Type | Mandatory | Description | 169|---------------|----------------------------------------------------|-----|----------------| 170| busType | [BusType](js-apis-driver-deviceManager.md#bustype) | Yes | Bus type. | 171| driverUid | string | Yes | Driver UID. | 172| driverName | string | Yes | Driver name. | 173| driverVersion | string | Yes | Driver version. | 174| driverSize | string | Yes | Driver size, in bytes.| 175| description | string | Yes | Driver description. | 176 177## USBDriverInfo 178 179Defines detailed information about the USB device driver. It is inherited from [DriverInfo](#driverinfo). 180 181**System API**: This is a system API. 182 183**System capability**: SystemCapability.Driver.ExternalDevice 184 185| Name | Type | Mandatory | Description | 186|---------------|---------------------|-----|-------------------------| 187| productIdList | Array<number> | Yes | Product ID list of the USB devices supported by the driver.| 188| vendorIdList | Array<number> | Yes | Vendor ID list of the USB devices supported by the driver. | 189