harmony 鸿蒙@ohos.driver.deviceManager (Peripheral Management) (System API)
@ohos.driver.deviceManager (Peripheral Management) (System API)
The deviceManager module provides the functions of managing peripheral devices, including querying information about peripherals and their drivers.
NOTE
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. This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.driver.deviceManager (Peripheral Management).
Modules to Import
import { deviceManager } from '@kit.DriverDevelopmentKit';
deviceManager.queryDeviceInfo
queryDeviceInfo(deviceId?: number): Array<Readonly<DeviceInfo>>
Obtains the list of detailed information about peripherals. If the device has no peripheral device connected, an empty list is returned.
System API: This is a system API.
Required permissions: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
System capability: SystemCapability.Driver.ExternalDevice
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
deviceId | number | No | Device ID, which is obtained through queryDevices. If no device ID is passed, all device information is obtained by default. If no external device is connected and no device ID is passed, an empty array is returned. |
Return value
Type | Description |
---|---|
Array<Readonly<DeviceInfo>> | List of detailed information about peripherals. |
Error codes
ID | Error Message |
---|---|
201 | The permission check failed. |
202 | Permission denied. A non-system application cannot call a system API. |
401 | Parameter error. Possible causes: 1.Incorrect parameter types. |
26300001 | ExternalDeviceManager service exception. |
Example
import { deviceManager } from '@kit.DriverDevelopmentKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
// For example, deviceId is 12345678. You can use queryDevices() to obtain the deviceId.
let deviceInfos : Array<deviceManager.DeviceInfo> = deviceManager.queryDeviceInfo(12345678);
for (let item of deviceInfos) {
console.info(`Device id is ${item.deviceId}`)
}
} catch (error) {
let err: BusinessError = error as BusinessError;
console.error(`Failed to query device info. Code is ${err.code}, message is ${err.message}`);
}
deviceManager.queryDriverInfo
queryDriverInfo(driverUid?: string): Array<Readonly<DriverInfo>>
Obtains the list of detailed information about peripheral drivers. If the device has no peripheral device connected, an empty list is returned.
System API: This is a system API.
Required permissions: ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER
System capability: SystemCapability.Driver.ExternalDevice
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
driverUid | string | No | Driver UID, which can be obtained by using queryDeviceInfo. |
Return value
Type | Description |
---|---|
Array<Readonly<DriverInfo>> | List of detailed information about peripheral drivers. |
Error codes
ID | Error Message |
---|---|
201 | The permission check failed. |
202 | Permission denied. A non-system application cannot call a system API. |
401 | Parameter error. Possible causes: 1.Incorrect parameter types. |
26300001 | ExternalDeviceManager service exception. |
Example
import { deviceManager } from '@kit.DriverDevelopmentKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
// 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.
let driverInfos : Array<deviceManager.DriverInfo> = deviceManager.queryDriverInfo("driver-12345");
for (let item of driverInfos) {
console.info(`driver name is ${item.driverName}`)
}
} catch (error) {
let err: BusinessError = error as BusinessError;
console.error(`Failed to query driver info. Code is ${err.code}, message is ${err.message}`);
}
DeviceInfo
Defines the detailed information about a device.
System API: This is a system API.
System capability: SystemCapability.Driver.ExternalDevice
Name | Type | Mandatory | Description |
---|---|---|---|
deviceId | number | Yes | Device ID. |
isDriverMatched | boolean | Yes | Whether the device matches the driver. |
driverUid | string | No | UID of the driver matching the device. |
USBDeviceInfo
Defines detailed information about the USB device. It is inherited from DeviceInfo.
System API: This is a system API.
System capability: SystemCapability.Driver.ExternalDevice
Name | Type | Mandatory | Description |
---|---|---|---|
vendorId | number | Yes | Vendor ID of the USB device. |
productId | number | Yes | Product ID of the USB device. |
interfaceDescList | Array<Readonly<USBInterfaceDesc>> | Yes | List of interface descriptors of the USB device. |
USBInterfaceDesc
Defines the interface descriptor of a USB device.
System API: This is a system API.
System capability: SystemCapability.Driver.ExternalDevice
Name | Type | Mandatory | Description |
---|---|---|---|
bInterfaceNumber | number | Yes | Interface ID. |
bClass | number | Yes | Interface class. |
bSubClass | number | Yes | Interface subclass. |
bProtocol | number | Yes | Interface protocol. |
DriverInfo
Defines detailed information about a driver.
System API: This is a system API.
System capability: SystemCapability.Driver.ExternalDevice
Name | Type | Mandatory | Description |
---|---|---|---|
busType | BusType | Yes | Bus type. |
driverUid | string | Yes | Driver UID. |
driverName | string | Yes | Driver name. |
driverVersion | string | Yes | Driver version. |
driverSize | string | Yes | Driver size, in bytes. |
description | string | Yes | Driver description. |
USBDriverInfo
Defines detailed information about the USB device driver. It is inherited from DriverInfo.
System API: This is a system API.
System capability: SystemCapability.Driver.ExternalDevice
Name | Type | Mandatory | Description |
---|---|---|---|
productIdList | Array<number> | Yes | Product ID list of the USB devices supported by the driver. |
vendorIdList | Array<number> | Yes | Vendor ID list of the USB devices supported by the driver. |
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦