openharmony 鸿蒙 js-apis-driver-deviceManager-sys

2025-06-12 浏览 (1)

@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

NameTypeMandatoryDescription
deviceIdnumberNoDevice 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

TypeDescription
Array<Readonly<DeviceInfo>>List of detailed information about peripherals.

Error codes

IDError Message
201The permission check failed.
202Permission denied. A non-system application cannot call a system API.
401Parameter error. Possible causes: 1.Incorrect parameter types.
26300001ExternalDeviceManager 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

NameTypeMandatoryDescription
driverUidstringNoDriver UID, which can be obtained by using queryDeviceInfo.

Return value

TypeDescription
Array<Readonly<DriverInfo>>List of detailed information about peripheral drivers.

Error codes

IDError Message
201The permission check failed.
202Permission denied. A non-system application cannot call a system API.
401Parameter error. Possible causes: 1.Incorrect parameter types.
26300001ExternalDeviceManager 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

NameTypeMandatoryDescription
deviceIdnumberYesDevice ID.
isDriverMatchedbooleanYesWhether the device matches the driver.
driverUidstringNoUID 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

NameTypeMandatoryDescription
vendorIdnumberYesVendor ID of the USB device.
productIdnumberYesProduct ID of the USB device.
interfaceDescListArray<Readonly<USBInterfaceDesc>>YesList 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

NameTypeMandatoryDescription
bInterfaceNumbernumberYesInterface ID.
bClassnumberYesInterface class.
bSubClassnumberYesInterface subclass.
bProtocolnumberYesInterface protocol.

DriverInfo

Defines detailed information about a driver.

System API: This is a system API.

System capability: SystemCapability.Driver.ExternalDevice

NameTypeMandatoryDescription
busTypeBusTypeYesBus type.
driverUidstringYesDriver UID.
driverNamestringYesDriver name.
driverVersionstringYesDriver version.
driverSizestringYesDriver size, in bytes.
descriptionstringYesDriver 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

NameTypeMandatoryDescription
productIdListArray<number>YesProduct ID list of the USB devices supported by the driver.
vendorIdListArray<number>YesVendor ID list of the USB devices supported by the driver.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Driver Development Kit

harmony 鸿蒙Base DDK

harmony 鸿蒙DDK_Ashmem

harmony 鸿蒙Hid_AbsAxesArray

harmony 鸿蒙Hid_Device

harmony 鸿蒙Hid_EmitItem

harmony 鸿蒙Hid_EventProperties

harmony 鸿蒙Hid_EventTypeArray

harmony 鸿蒙Hid_KeyCodeArray

harmony 鸿蒙Hid_MscEventArray

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/xFW3Ed