openharmony 鸿蒙 js-apis-usbManager

2025-06-12 浏览 (1)

@ohos.usbManager (USB Manager)

The usbManager module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as USB interface management, and function switch and query on the device side.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { usbManager } from '@kit.BasicServicesKit';

usbManager.getDevices

getDevices(): Array<Readonly<USBDevice>>

Obtains the list of USB devices connected to the host. If no device is connected, an empty list is returned. When the developer mode is disabled, undefined may be returned if no device is connected. Check whether the return value of the API is empty.

System capability: SystemCapability.USB.USBManager

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
801Capability not supported.

Return value

TypeDescription
Array<Readonly<USBDevice>>USB device list.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
console.log(`devicesList = ${devicesList}`);
/*
The following is a simple example of the data structure for devicesList:
[
  {
    name: "1-1",
    serial: "",
    manufacturerName: "",
    productName: "",
    version: "",
    vendorId: 7531,
    productId: 2,
    clazz: 9,
    subClass: 0,
    protocol: 1,
    devAddress: 1,
    busNum: 1,
    configs: [
      {
        id: 1,
        attributes: 224,
        isRemoteWakeup: true,
        isSelfPowered: true,
        maxPower: 0,
        name: "1-1",
        interfaces: [
          {
            id: 0,
            protocol: 0,
            clazz: 9,
            subClass: 0,
            alternateSetting: 0,
            name: "1-1",
            endpoints: [
              {
                address: 129,
                attributes: 3,
                interval: 12,
                maxPacketSize: 4,
                direction: 128,
                number: 1,
                type: 3,
                interfaceId: 0,
              },
            ],
          },
        ],
      },
    ],
  },
]
*/

usbManager.connectDevice

connectDevice(device: USBDevice): Readonly<USBDevicePipe>

Connects to the USB device based on the device information returned by getDevices(). If the USB service is abnormal, undefined may be returned. Check whether the return value of the API is empty.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the permission to use the device.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
deviceUSBDeviceYesUSB device. The busNum and devAddress parameters obtained by getDevices are used to determine a USB device. Other parameters are passed transparently.

Return value

TypeDescription
Readonly<USBDevicePipe>USB device pipe for data transfer.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400001Access right denied. Call requestRight to get the USBDevicePipe access right first.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
console.log(`devicepipe = ${devicepipe}`);

usbManager.hasRight

hasRight(deviceName: string): boolean

Checks whether the application has the permission to access the device.

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.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
deviceNamestringYesDevice name, which can be obtained from the device list returned by getDevices.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
booleanReturns true if the application has the permission to access the device; returns false otherwise. If this API fails to be called, the following error codes are returned:
- 88080385: This API is not initialized.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let right: boolean = usbManager.hasRight(device.name);
console.log(`${right}`);

usbManager.requestRight

requestRight(deviceName: string): Promise<boolean>

Requests the temporary device access permission for the application. This API uses a promise to return the result. System applications are granted the device access permission by default, and you do not need to apply for the permission separately.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
deviceNamestringYesDevice name, which can be obtained from the device list returned by getDevices.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. The value true indicates that the temporary device access permissions are granted; and the value false indicates the opposite. If this API fails to be called, the following error codes are returned:
- 88080385: This API is not initialized.
- 88080392: An error occurs when the API data packet is written.
- 88080393: An error occurs when the API data packet is read.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name).then(ret => {
  console.log(`requestRight = ${ret}`);
});

usbManager.removeRight

removeRight(deviceName: string): boolean

Removes the device access permission for the application. System applications are granted the device access permission by default, and calling this API will not revoke the permission.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
deviceNamestringYesDevice name, which can be obtained from the device list returned by getDevices.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
booleanPermission removal result. The value true indicates that the access permission is removed successfully; and the value false indicates the opposite. If this API fails to be called, the following error codes are returned:
- 88080382: An invalid value or parameter occurs during the API operation.
- 88080385: This API is not initialized.
- 88080392: An error occurs when the API data packet is written.
- 88080393: An error occurs when the API data packet is read.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
if (usbManager.removeRight(device.name)) {
  console.log(`Succeed in removing right`);
}

usbManager.claimInterface

claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number

Claims a USB interface.

  1. Call usbManager.getDevices to obtain the USB device list and interfaces.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.
ifaceUSBInterfaceYesUSB interface. You can use getDevices to obtain device information and identify the USB interface based on its ID.
forcebooleanNoWhether to forcibly claim a USB interface. The default value is false, which means not to forcibly claim a USB interface. You can set the value as required.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns 0 if the USB interface is successfully claimed; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
let ret: number= usbManager.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`);

usbManager.releaseInterface

releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number

Releases a USB interface.

Before you do this, ensure that you have claimed the interface by calling usbManager.claimInterface.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.
ifaceUSBInterfaceYesUSB interface. You can use getDevices to obtain device information and identify the USB interface based on its ID.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns 0 if the USB interface is successfully released; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080381: Invalid interface operation.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
let ret: number = usbManager.claimInterface(devicepipe, interfaces);
ret = usbManager.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`);

usbManager.setConfiguration

setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number

Sets the device configuration.

  1. Call usbManager.getDevices to obtain the USB device list and device configuration.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.
configUSBConfigurationYesUSB configuration. You can use getDevices to obtain device information and identify the USB configuration based on the ID.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns 0 if the USB configuration is successfully set; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.
- -17: I/O failure.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
let config: usbManager.USBConfiguration = device.configs[0];
let ret: number= usbManager.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`);

usbManager.setInterface

setInterface(pipe: USBDevicePipe, iface: USBInterface): number

Sets a USB interface.

  1. Call usbManager.getDevices to obtain the device list and interfaces.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.
  4. Call usbManager.claimInterface to register a communication interface.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.
ifaceUSBInterfaceYesUSB interface. You can use getDevices to obtain device information and identify the USB interface based on its id and alternateSetting.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns 0 if the USB interface is successfully set; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
let interfaces: usbManager.USBInterface = device.configs[0].interfaces[0];
let ret: number = usbManager.claimInterface(devicepipe, interfaces);
ret = usbManager.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`);

usbManager.getRawDescriptor

getRawDescriptor(pipe: USBDevicePipe): Uint8Array

Obtains the raw USB descriptor. If the USB service is abnormal, undefined may be returned. Check whether the return value of the API is empty.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
Uint8ArrayReturns the raw USB descriptor if the operation is successful; returns undefined otherwise.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

usbManager.requestRight(devicesList[0].name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
let ret: Uint8Array = usbManager.getRawDescriptor(devicepipe);

usbManager.getFileDescriptor

getFileDescriptor(pipe: USBDevicePipe): number

Obtains the file descriptor.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns the file descriptor corresponding to the device if this API is successful called; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

usbManager.requestRight(devicesList[0].name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
let ret: number = usbManager.getFileDescriptor(devicepipe);

usbManager.controlTransfer(deprecated)

controlTransfer(pipe: USBDevicePipe, controlparam: USBControlParams, timeout ?: number): Promise<number>

Performs control transfer.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

NOTE

This API is supported since API version 9 and deprecated since API version 12. You are advised to use usbControlTransfer.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe. You need to call connectDevice to obtain its value.
controlparamUSBControlParamsYesControl transfer parameters. Set the parameters as required. For details, see the USB protocol.
timeoutnumberNo(Optional) Timeout duration, in ms. The default value is 0. You can set this parameter as required.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

Return value

TypeDescription
Promise<number>Promise used to return the result, which is the size of the transferred or received data block if the transfer is successful. If the API call fails, the following error codes are returned:
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

class PARA {
  request: number = 0
  reqType: usbManager.USBControlRequestType = 0
  target: usbManager.USBRequestTargetType = 0
  value: number = 0
  index: number = 0
  data: Uint8Array = new Uint8Array()
}

let param: PARA = {
  request: 0x06,
  reqType: 0x80,
  target:0,
  value: 0x01 << 8|0,
  index: 0,
  data: new Uint8Array(18)
};

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

usbManager.requestRight(devicesList[0].name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
usbManager.controlTransfer(devicepipe, param).then((ret: number) => {
console.log(`controlTransfer = ${ret}`);
})

usbManager.usbControlTransfer12+

usbControlTransfer(pipe: USBDevicePipe, requestparam: USBDeviceRequestParams, timeout ?: number): Promise<number>

Performs control transfer.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the USB device.
requestparamUSBDeviceRequestParamsYesControl transfer parameters. Set the parameters as required. For details, see the USB protocol.
timeoutnumberNo(Optional) Timeout duration, in ms. The default value is 0, indicating no timeout.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error.Possible causes:1.Mandatory parameters are left unspecified.2.Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
Promise<number>Promise used to return the result, which is the size of the transferred or received data block if the transfer is successful. If the API call fails, the following error codes are returned:
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

class PARA {
  bmRequestType: number = 0
  bRequest: number = 0
  wValue: number = 0
  wIndex: number = 0
  wLength: number = 0
  data: Uint8Array = new Uint8Array()
}

let param: PARA = {
  bmRequestType: 0x80,
  bRequest: 0x06,

  wValue:0x01 << 8|0,
  wIndex: 0,
  wLength: 18,
  data: new Uint8Array(18)
};

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

usbManager.requestRight(devicesList[0].name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
usbManager.usbControlTransfer(devicepipe, param).then((ret: number) => {
console.log(`usbControlTransfer = ${ret}`);
})

usbManager.bulkTransfer

bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise<number>

Performs bulk transfer.

  1. Call usbManager.getDevices to obtain the USB device list and endpoints.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain the returned devicepipe.
  4. Obtain the usbManager.claimInterface API.
  5. Call the usbManager.bulkTransfer API.

NOTE

The total amount of data (including pipe, endpoint, buffer, and timeout) transferred in bulk must be less than 200 KB.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe. You need to call connectDevice to obtain its value.
endpointUSBEndpointYesUSB endpoint, which is used to determine the USB interface for data transfer. You need to call getDevices to obtain the device information list and endpoint. Wherein, address is used to determine the endpoint address, direction is used to determine the endpoint direction, and interfaceId is used to determine the USB interface to which the endpoint belongs. Other parameters are passed transparently.
bufferUint8ArrayYesBuffer used to write or read data.
timeoutnumberNo(Optional) Timeout duration, in ms. The default value is 0. You can set this parameter as required.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
Promise<number>Promise used to return the result, which is the size of the transferred or received data block if the transfer is successful. If the API call fails, the following error codes are returned:
- 63: The data exceeds the expected maximum volume.
- 88080385: This API is not initialized.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080492: An error occurs when the service data packet is written.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.
- -3: The parameter is invalid.
- -202: The device is not found.

Example

NOTE

The following sample code is only a basic process for calling the bulkTransfer API. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.

// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);

let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
for (let i = 0; i < device.configs[0].interfaces.length; i++) {
  if (device.configs[0].interfaces[i].endpoints[0].attributes == 2) {
    let endpoint: usbManager.USBEndpoint = device.configs[0].interfaces[i].endpoints[0];
    let interfaces: usbManager.USBInterface = device.configs[0].interfaces[i];
    let ret: number = usbManager.claimInterface(devicepipe, interfaces);
    let buffer =  new Uint8Array(128);
    usbManager.bulkTransfer(devicepipe, endpoint, buffer).then((ret: number) => {
      console.log(`bulkTransfer = ${ret}`);
    });
  }
}

usbManager.usbSubmitTransfer18+

usbSubmitTransfer(transfer: UsbDataTransferParams): void

Requests a USB data transfer.

This API uses an asynchronous callback to return the result.

  1. Call usbManager.getDevices to obtain the USB device list and endpoints.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain the returned devicepipe.
  4. Obtain the usbManager.claimInterface API.
  5. Call the usbManager.usbSubmitTransfer API.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
transferUsbDataTransferParamsYesAs a USB data transfer interface, it is required for a client to initiate a transfer request.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported.
14400001Access right denied. Call requestRight to get the USBDevicePipe access right first.
14400007Resource busy.
14400008No such device (it may have been disconnected).
14400009Insufficient memory.
14400012Transmission I/O error.

Example

NOTE

The following sample code shows the basic process for calling the usbSubmitTransfer API and it needs to be executed in a specific method. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.

// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
  return;
}
let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
// Obtain the endpoint address.
let endpoint = device.configs[0].interfaces[0]?.endpoints.find((value) => {
  return value.direction === 0 && value.type === 2
})
// Obtain the first ID of the device.
let ret: number = usbManager.claimInterface(devicepipe, device.configs[0].interfaces[0], true);

let transferParams: usbManager.UsbDataTransferParams = {
  devPipe: devicepipe,
  flags: usbManager.UsbTransferFlags.USB_TRANSFER_SHORT_NOT_OK,
  endpoint: 1,
  type: usbManager.UsbEndpointTransferType.TRANSFER_TYPE_BULK,
  timeout: 2000,
  length: 10, 
  callback: () => {},
  userData: new Uint8Array(10),
  buffer: new Uint8Array(10),
  isoPacketCount: 0,
};
try {
  transferParams.endpoint=endpoint?.address as number;
  transferParams.callback=(err, callBackData: usbManager.SubmitTransferCallback)=>{
    console.info('callBackData =' +JSON.stringify(callBackData));
  }
  usbManager.usbSubmitTransfer(transferParams); 
  console.info('USB transfer request submitted.');
} catch (error) {
  console.error('USB transfer failed:', error);
}

usbManager.usbCancelTransfer18+

usbCancelTransfer(transfer: UsbDataTransferParams): void

Cancels an asynchronous USB data transfer request.

  1. Call usbManager.getDevices to obtain the USB device list and endpoints.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain the returned devicepipe.
  4. Obtain the usbManager.claimInterface API.
  5. Call the usbManager.usbCancelTransfer API.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
transferUsbDataTransferParamsYesOnly USBDevicePipe and endpoint are required for canceling the transfer.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
801Capability not supported.
14400001Access right denied. Call requestRight to get the USBDevicePipe access right first.
14400008No such device (it may have been disconnected).
14400010Other USB error. Possible causes:
1.Unrecognized discard error code.
14400011The transfer is not in progress, or is already complete or cancelled.

Return value

TypeDescription
<void>None.

Example

NOTE

The following sample code shows the basic process for calling the usbCancelTransfer API and it needs to be executed in a specific method. In actual calling, you must comply with the device-related protocols to ensure correct data transfer and device compatibility.

// Call usbManager.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usbManager.connectDevice. Then, call usbManager.connectDevice to connect the USB device.
// Call usbManager.claimInterface to claim a USB interface. After that, call usbManager.bulkTransfer to start bulk transfer.
let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
  return;
}
let device: usbManager.USBDevice = devicesList[0];
usbManager.requestRight(device.name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(device);
// Obtain the endpoint address.
let endpoint = device.configs[0].interfaces[0]?.endpoints.find((value) => {
  return value.direction === 0 && value.type === 2
})
// Obtain the first ID of the device.
let ret: number = usbManager.claimInterface(devicepipe, device.configs[0].interfaces[0], true);
let transferParams: usbManager.UsbDataTransferParams = {
  devPipe: devicepipe,
  flags: usbManager.UsbTransferFlags.USB_TRANSFER_SHORT_NOT_OK,
  endpoint: 1,
  type: usbManager.UsbEndpointTransferType.TRANSFER_TYPE_BULK,
  timeout: 2000,
  length: 10, 
  callback: () => {},
  userData: new Uint8Array(10),
  buffer: new Uint8Array(10),
  isoPacketCount: 0,
};
try {
  transferParams.endpoint=endpoint?.address as number;
  transferParams.callback=(err, callBackData: usbManager.SubmitTransferCallback)=>{
    console.info('callBackData =' +JSON.stringify(callBackData));
  }
  usbManager.usbSubmitTransfer(transferParams);
  usbManager.usbCancelTransfer(transferParams);
  console.info('USB transfer request submitted.');
} catch (error) {
  console.error('USB transfer failed:', error);
}

usbManager.closePipe

closePipe(pipe: USBDevicePipe): number

Closes a USB device pipe.

  1. Call usbManager.getDevices to obtain the USB device list.
  2. Call usbManager.requestRight to request the device access permission.
  3. Call usbManager.connectDevice to obtain devicepipe as an input parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
pipeUSBDevicePipeYesUSB device pipe, which is used to determine the message control channel. You need to call connectDevice to obtain its value.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.

Return value

TypeDescription
numberReturns 0 if the USB device pipe is closed successfully; returns an error code otherwise. The error codes are as follows:
- 63: The data exceeds the expected maximum volume.
- 88080393: An error occurs when the API data packet is read.
- 88080482: An invalid value or parameter occurs during the service.
- 88080484: No permission.
- 88080493: An error occurs when the service data packet is read.
- 88080497: An error occurs when the internal logic of the service is executed.
- -1: The underlying interface fails to be called.

Example

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
if (devicesList.length == 0) {
  console.log(`device list is empty`);
}

usbManager.requestRight(devicesList[0].name);
let devicepipe: usbManager.USBDevicePipe = usbManager.connectDevice(devicesList[0]);
let ret: number = usbManager.closePipe(devicepipe);
console.log(`closePipe = ${ret}`);

usbManager.hasAccessoryRight14+

hasAccessoryRight(accessory: USBAccessory): boolean

Checks whether the application has the permission to access the USB accessory.

You need to call usbManager.getAccessoryList to obtain the accessory list and use USBAccessory as a parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
accessoryUSBAccessoryYesUSB accessory.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400004Service exception. Possible causes: 1. No accessory is plugged in.
14400005Database operation exception.
14401001The target USBAccessory not matched.

Return value

TypeDescription
booleanThe value true indicates that the application has the permission to access the USB accessory; false indicates the opposite.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  let flag = usbManager.hasAccessoryRight(accList[0])
  hilog.info(0, 'testTag ui', `hasAccessoryRight success, ret:${flag}`)
} catch (error) {
  hilog.info(0, 'testTag ui', `hasAccessoryRight error ${error.code}, message is ${error.message}`)
}

usbManager.requestAccessoryRight14+

requestAccessoryRight(accessory: USBAccessory): Promise<boolean>

Requests the permission to access a USB accessory for a specified application.

You need to call usbManager.getAccessoryList to obtain the accessory list and use USBAccessory as a parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
accessoryUSBAccessoryYesUSB accessory.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400004Service exception. Possible causes: 1. No accessory is plugged in.
14400005Database operation exception.
14401001The target USBAccessory not matched.

Return value

TypeDescription
Promise<boolean>Promise used to return the application result. The value true indicates that the device access permissions are granted; false indicates the opposite.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  let flag = usbManager.requestAccessoryRight(accList[0])
  hilog.info(0, 'testTag ui', `requestAccessoryRight success, ret:${flag}`)
} catch (error) {
  hilog.info(0, 'testTag ui', `requestAccessoryRight error ${error.code}, message is ${error.message}`)
}

usbManager.cancelAccessoryRight14+

cancelAccessoryRight(accessory: USBAccessory): void

Cancels the permission of the current application to access USB accessories.

You need to call usbManager.getAccessoryList to obtain the accessory list and use USBAccessory as a parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
accessoryUSBAccessoryYesUSB accessory.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400004Service exception. Possible causes: 1. No accessory is plugged in.
14400005Database operation exception.
14401001The target USBAccessory not matched.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  let flag = usbManager.requestAccessoryRight(accList[0])
  usbManager.cancelAccessoryRight(accList[0])
  hilog.info(0, 'testTag ui', `cancelAccessoryRight success`)
} catch (error) {
  hilog.info(0, 'testTag ui', `cancelAccessoryRight error ${error.code}, message is ${error.message}`)
}

usbManager.getAccessoryList14+

getAccessoryList(): Array<Readonly<USBAccessory>>

Obtains the list of USB accessories connected to the host.

System capability: SystemCapability.USB.USBManager

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
801Capability not supported.
14400004Service exception. Possible causes: 1. No accessory is plugged in.

Return value

TypeDescription
Array<Readonly<USBAccessory>>List of USB accessories (read-only). Currently, only one USB accessory is contained in the list.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  hilog.info(0, 'testTag ui', `getAccessoryList success, accList: ${JSON.stringify(accList)}`)
} catch (error) {
  hilog.info(0, 'testTag ui', `getAccessoryList error ${error.code}, message is ${error.message}`)
}

usbManager.openAccessory14+

openAccessory(accessory: USBAccessory): USBAccessoryHandle

Obtains the accessory handle and opens the accessory file descriptor.

You need to call usbManager.getAccessoryList to obtain the accessory list and use USBAccessory as a parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
accessoryUSBAccessoryYesUSB accessory.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400001Permission denied. Call requestAccessoryRight to get the right first.
14400004Service exception. Possible causes: 1. No accessory is plugged in.
14401001The target USBAccessory not matched.
14401002Failed to open the native accessory node.
14401003Cannot reopen the accessory.

Return value

TypeDescription
USBAccessoryHandleUSB accessory handle.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  let flag = usbManager.requestAccessoryRight(accList[0])
  let handle = usbManager.openAccessory(accList[0])
  hilog.info(0, 'testTag ui', `openAccessory success`)
} catch (error) {
  hilog.info(0, 'testTag ui', `openAccessory error ${error.code}, message is ${error.message}`)
}

usbManager.closeAccessory14+

closeAccessory(accessoryHandle: USBAccessoryHandle): void

Closes the accessory file descriptor.

You need to call usbManager.openAccessory to obtain the accessory list and use USBAccessoryHandle as a parameter.

System capability: SystemCapability.USB.USBManager

Parameters

NameTypeMandatoryDescription
accessoryHandleUSBAccessoryHandleYesUSB accessory handle, obtained through openAccessory.

Error codes

For details about the error codes, see USB Service Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
14400004Service exception. Possible causes: 1. No accessory is plugged in.

Example

import { hilog } from '@kit.PerformanceAnalysisKit';
try {
  let accList: usbManager.USBAccessory[] = usbManager.getAccessoryList()
  let flag = usbManager.requestAccessoryRight(accList[0])
  let handle = usbManager.openAccessory(accList[0])
  usbManager.closeAccessory(handle)
  hilog.info(0, 'testTag ui', `closeAccessory success`)
} catch (error) {
  hilog.info(0, 'testTag ui', `closeAccessory error ${error.code}, message is ${error.message}`)
}

USBEndpoint

Represents the USB endpoint from which data is sent or received. You can obtain the USB endpoint through USBInterface.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
addressnumberYesEndpoint address.
attributesnumberYesEndpoint attributes.
intervalnumberYesEndpoint interval.
maxPacketSizenumberYesMaximum size of data packets on the endpoint.
directionUSBRequestDirectionYesEndpoint direction.
numbernumberYesEndpoint number.
typenumberYesEndpoint type.
interfaceIdnumberYesUnique ID of the interface to which the endpoint belongs.

USBInterface

Represents a USB interface. One USBConfiguration object can contain multiple USBInterface instances, each providing a specific function.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
idnumberYesUnique ID of the USB interface.
protocolnumberYesInterface protocol.
clazznumberYesDevice type.
subClassnumberYesDevice subclass.
alternateSettingnumberYesSettings for alternating between descriptors of the same USB interface.
namestringYesInterface name.
endpointsArray<USBEndpoint>YesEndpoints that belong to the USB interface.

USBConfiguration

Represents the USB configuration. One USBDevice can contain multiple USBConfig instances.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
idnumberYesUnique ID of the USB configuration.
attributesnumberYesConfiguration attributes.
maxPowernumberYesMaximum power consumption, in mA.
namestringYesConfiguration name, which can be left empty.
isRemoteWakeupbooleanYesSupport for remote wakeup.
isSelfPoweredbooleanYesSupport for independent power supplies.
interfacesArray <USBInterface>YesSupported interface attributes.

USBDevice

Represents the USB device information.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
busNumnumberYesBus address.
devAddressnumberYesDevice address.
serialstringYesSequence number.
namestringYesDevice name.
manufacturerNamestringYesDevice manufacturer.
productNamestringYesProduct name.
versionstringYesVersion number.
vendorIdnumberYesVendor ID.
productIdnumberYesProduct ID.
clazznumberYesDevice class.
subClassnumberYesDevice subclass.
protocolnumberYesDevice protocol code.
configsArray<USBConfiguration>YesDevice configuration descriptor information.

USBDevicePipe

Represents a USB device pipe, which is used to determine a USB device.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
busNumnumberYesBus address.
devAddressnumberYesDevice address.

USBControlParams(deprecated)

Represents control transfer parameters.

NOTE

This API is supported since API version 9 and deprecated since API version 18. You are advised to use USBDeviceRequestParams instead.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
requestnumberYesRequest type.
targetUSBRequestTargetTypeYesRequest target type.
reqTypeUSBControlRequestTypeYesControl request type.
valuenumberYesRequest parameter.
indexnumberYesIndex of the request parameter.
dataUint8ArrayYesBuffer for writing or reading data.

USBDeviceRequestParams12+

Represents control transfer parameters.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
bmRequestTypenumberYesControl request type.
bRequestnumberYesRequest type.
wValuenumberYesRequest parameter.
wIndexnumberYesIndex of the request parameter.
wLengthnumberYesLength of the requested data.
dataUint8ArrayYesBuffer for writing or reading data.

USBRequestTargetType

Enumerates request target types.

System capability: SystemCapability.USB.USBManager

NameValueDescription
USB_REQUEST_TARGET_DEVICE0Device.
USB_REQUEST_TARGET_INTERFACE1Interface.
USB_REQUEST_TARGET_ENDPOINT2Endpoint.
USB_REQUEST_TARGET_OTHER3Other.

USBControlRequestType

Enumerates control request types.

System capability: SystemCapability.USB.USBManager

NameValueDescription
USB_REQUEST_TYPE_STANDARD0Standard.
USB_REQUEST_TYPE_CLASS1Class.
USB_REQUEST_TYPE_VENDOR2Vendor.

USBRequestDirection

Enumerates request directions.

System capability: SystemCapability.USB.USBManager

NameValueDescription
USB_REQUEST_DIR_TO_DEVICE0Request for writing data from the host to the device.
USB_REQUEST_DIR_FROM_DEVICE0x80Request for reading data from the device to the host.

USBAccessory14+

Describes the USB accessory information.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
manufacturerstringYesManufacturer of an accessory.
productstringYesProduct type of an accessory.
descriptionstringYesDescription of an accessory.
versionstringYesVersion of an accessory.
serialNumberstringYesSN of an accessory.

USBAccessoryHandle14+

Describes the USB accessory handle.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
accessoryFdnumberYesAccessory file descriptor. A valid accessoryFd is a positive integer.

UsbDataTransferParams18+

As a USB data transfer interface, it is required for a client to initiate a transfer request.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
devPipeUSBDevicePipeYesUSB device pipe, which is used to determine the bus number and device address. You need to call connectDevice to obtain its value.
flagsUsbTransferFlagsYesUSB transfer flag.
endpointnumberYesEndpoint address, which is a positive integer.
typeUsbEndpointTransferTypeYesTransfer type.
timeoutnumberYesTimeout duration, in ms.
lengthnumberYesLength of the data buffer, in bytes. The value must be a non-negative number (expected length).
callbackAsyncCallback<SubmitTransferCallback>YesInformation returned by the callback.
userDataUint8ArrayYesUser data.
bufferUint8ArrayYesBuffer, which is used to store data for read or write requests.
isoPacketCountnumberYesNumber of data packets during real-time transfer, used only for I/Os with real-time transfer endpoints. The value must be a non-negative number.

UsbTransferFlags18+

Enumerates USB transfer flags.

System capability: SystemCapability.USB.USBManager

NameValueDescription
USB_TRANSFER_SHORT_NOT_OK0Reports short frames as errors.
USB_TRANSFER_FREE_BUFFER1Automatically releases the transfer buffer.
USB_TRANSFER_FREE_TRANSFER2Automatically transfers after the callback is complete.
USB_TRANSFER_ADD_ZERO_PACKET3Adds an additional data packet to the transfer.

UsbEndpointTransferType18+

Enumerates USB transfer types.

System capability: SystemCapability.USB.USBManager

NameValueDescription
TRANSFER_TYPE_ISOCHRONOUS0x1Real-time transfer.
TRANSFER_TYPE_BULK0x2Performs bulk transfer.
TRANSFER_TYPE_INTERRUPT0x3Interrupt transfer.

SubmitTransferCallback18+

Transfers USB data packets in an asynchronous manner.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
actualLengthnumberYesActual length of the read or written data, in bytes.
statusUsbTransferStatusYesStatus after reading or writing is complete.
isoPacketDescsArray<Readonly<UsbIsoPacketDescriptor>>YesPacket information transferred in real time.

UsbTransferStatus18+

Enumerates the statuses returned by libusb through callback after the actual processing is complete.

System capability: SystemCapability.USB.USBManager

NameValueDescription
TRANSFER_COMPLETED0Transfer completed.
TRANSFER_ERROR1Transfer failed.
TRANSFER_TIMED_OUT2Transfer timeout.
TRANSFER_CANCELED3Transfer canceled.
TRANSFER_STALL4Transfer stalled (at bulk/interrupt endpoint).
TRANSFER_NO_DEVICE5Device disconnected.
TRANSFER_OVERFLOW6Data overflow.

UsbIsoPacketDescriptor18+

Describes packet information returned in real time by the transfer callback.

System capability: SystemCapability.USB.USBManager

NameTypeMandatoryDescription
lengthnumberYesExpected length of the read or written data, in bytes.
actualLengthnumberYesActual length of the read or written data, in bytes.
statusUsbTransferStatusYesStatus returned by callback.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Basic Services Kit

harmony 鸿蒙DeviceInfo

harmony 鸿蒙InitSync

harmony 鸿蒙OH_Print

harmony 鸿蒙OsAccount

harmony 鸿蒙Pasteboard

harmony 鸿蒙Print_Margin

harmony 鸿蒙Print_PageSize

harmony 鸿蒙Print_PrintAttributes

harmony 鸿蒙Print_PrintDocCallback

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