openharmony 鸿蒙 js-apis-serialManager

2025-06-12 浏览 (1)

@ohos.usbManager.serial (Serial Port Management)

This module provides the serial port management functions, including enabling and disabling the serial port of the device, writing and reading data, setting and obtaining the configuration parameters of the serial port, and managing permissions.

NOTE

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

Modules to Import

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

serialManager.getPortList

getPortList(): Readonly<serialport>[];

Obtains the serial port device list, including the device name and port number.

System capability: SystemCapability.USB.USBManager.Serial

Returns

TypeDescription
Readonly<SerialPort>[]Serial port information list.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port device list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

serialManager.hasSerialRight

hasSerialRight(portId: number): boolean;

Checks whether the application has the permission to access the serial port device. When an application is restarted after exiting, you need to request the permission from the user again.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

Returns

TypeDescription
booleanThe value true indicates that the permission is authorized, and false indicates the opposite.

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; 3. Parameter verification failed.
14400005Database operation exception.
31400001Serial port management exception.
31400003Device does not exist.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('portList: ', JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (serialManager.hasSerialRight(portId)) {
  console.info('The serial port is accessible');
} else {
  console.info('No permission to access the serial port');
}

serialManager.requestSerialRight

requestSerialRight(portId: number): Promise<boolean>

Requests the permission for the application to access the serial port device. After the application exits, the access permission on the serial port device is automatically removed. After the application is restarted, you need to request the permission again.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

Returns

TypeDescription
Promise<boolean>Promise used to return the result. The value true indicates that the permission is successfully requested, and false indicates the opposite.

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; 3. Parameter verification failed.
14400005Database operation exception.
31400001Serial port management exception.
31400003Device does not exist.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

serialManager.open

open(portId: number): void;

Opens a serial port device.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400002Access denied. Call requestSerialRight to request user authorization first.
31400003Device does not exist.
31400004The serial port device is occupied.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

serialManager.getAttribute

getAttribute(portId: number): Readonly<SerialAttribute>;

Obtains the configuration parameters of a specified serial port.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

Returns

TypeDescription
Readonly<SerialAttribute>Configuration parameters of the serial port.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Obtain the serial port configuration.
try {
  let attribute: serialManager.SerialAttribute = serialManager.getAttribute(portId);
  if (attribute === undefined) {
    console.error('getAttribute usbSerial error, attribute is undefined');
  } else {
    console.info('getAttribute usbSerial success, attribute: ' + JSON.stringify(attribute));
  }
} catch (error) {
  console.error('getAttribute usbSerial error, ' + JSON.stringify(error));
}

serialManager.setAttribute

setAttribute(portId: number, attribute: SerialAttribute): void;

Sets the parameters of the serial port. If this method is not called, the default configuration parameters are used (baud rate: 9600 bit/s; data bit: 8; parity bit: 0; stop bit: 1).

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.
attributeSerialAttributeYesConfiguration parameters of the serial port.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Set the serial port configuration.
try {
  let attribute: serialManager.SerialAttribute = {
    baudRate: serialManager.BaudRates.BAUDRATE_9600,
    dataBits: serialManager.DataBits.DATABIT_8,
    parity: serialManager.Parity.PARITY_NONE,
    stopBits: serialManager.StopBits.STOPBIT_1
  }
  serialManager.setAttribute(portId, attribute);
  console.info('setAttribute usbSerial success, attribute: ' + JSON.stringify(attribute));
} catch (error) {
  console.error('setAttribute usbSerial error, ' + JSON.stringify(error));
}

serialManager.read

read(portId: number, buffer: Uint8Array, timeout?: number): Promise<number>;

Reads data from the serial port device asynchronously.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.
bufferUint8ArrayYesBuffer for reading data.
timeoutnumberNoTimeout duration for reading data, in milliseconds.

Returns

TypeDescription
Promise<number>Promise used to return the length of the data read.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.
31400006Data transfer timed out.
31400007I/O exception.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Read data asynchronously.
let readBuffer: Uint8Array = new Uint8Array(64);
serialManager.read(portId, readBuffer, 2000).then((size: number) => {
  console.info('read usbSerial success, readBuffer: ' + readBuffer.toString());
}).catch((error: Error) => {
  console.error('read usbSerial error, ' + JSON.stringify(error));
})

serialManager.readSync

readSync(portId: number, buffer: Uint8Array, timeout?: number): number;

Reads data from the serial port device synchronously.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.
bufferUint8ArrayYesBuffer for reading data.
timeoutnumberNoTimeout duration for reading data, in milliseconds.

Returns

TypeDescription
numberLength of the data read.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.
31400006Data transfer timed out.
31400007I/O exception.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Read data synchronously.
let readSyncBuffer: Uint8Array = new Uint8Array(64);
try {
  serialManager.readSync(portId, readSyncBuffer, 2000);
  console.info('readSync usbSerial success, readSyncBuffer: ' + readSyncBuffer.toString());
} catch (error) {
  console.error('readSync usbSerial error, ' + JSON.stringify(error));
}

serialManager.write

write(portId: number, buffer: Uint8Array, timeout?: number): Promise<number>;

Writes data to the serial port device asynchronously.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.
bufferUint8ArrayYesBuffer for writing data.
timeoutnumberNoTimeout duration for writing data, in milliseconds.

Returns

TypeDescription
Promise<number>Promise used to return the length of the data written.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.
31400006Data transfer timed out.
31400007I/O exception.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Write data asynchronously.
let writeBuffer: Uint8Array = new Uint8Array(buffer.from('Hello World', 'utf-8').buffer)
serialManager.write(portId, writeBuffer, 2000).then((size: number) => {
  console.info('write usbSerial success, writeBuffer: ' + writeBuffer.toString());
}).catch((error: Error) => {
  console.error('write usbSerial error, ' + JSON.stringify(error));
})

serialManager.writeSync

writeSync(portId: number, buffer: Uint8Array, timeout?: number): number;

Writes data to the serial port device synchronously.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.
bufferUint8ArrayYesDestination buffer for writing data.
timeoutnumberNoTimeout duration for writing data, in milliseconds.

Returns

TypeDescription
numberLength of the data written.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.
31400006Data transfer timed out.
31400007I/O exception.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Write data synchronously.
let writeSyncBuffer: Uint8Array = new Uint8Array(buffer.from('Hello World', 'utf-8').buffer)
try {
  serialManager.writeSync(portId, writeSyncBuffer, 2000);
  console.info('writeSync usbSerial success, writeSyncBuffer: ' + writeSyncBuffer.toString());
} catch (error) {
  console.error('writeSync usbSerial error, ' + JSON.stringify(error));
}

serialManager.close

close(portId: number): void;

Closes the serial port device.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

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; 3. Parameter verification failed.
31400001Serial port management exception.
31400003Device does not exist.
31400005The serial port device is not opened. Call the open API first.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Open a serial port device.
try {
  serialManager.open(portId)
  console.info('open usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('open usbSerial error, ' + JSON.stringify(error));
}

// Close the serial port device.
try {
  serialManager.close(portId);
  console.info('close usbSerial success, portId: ' + portId);
} catch (error) {
  console.error('close usbSerial error, ' + JSON.stringify(error));
}

serialManager.cancelSerialRight

cancelSerialRight(portId: number): void;

Cancels the permission to access the serial port device when the application is running. This API is used to close the enabled serial port device.

System capability: SystemCapability.USB.USBManager.Serial

Parameters

NameTypeMandatoryDescription
portIdnumberYesPort number.

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; 3. Parameter verification failed.
14400005Database operation exception.
31400001Serial port management exception.
31400002Access denied. Call requestSerialRight to request user authorization first.
31400003Device does not exist.

Example

import { JSON } from '@kit.ArkTS';
import { serialManager } from '@kit.BasicServicesKit';

// Obtain the serial port list.
let portList: serialManager.SerialPort[] = serialManager.getPortList();
console.info('usbSerial portList: ' + JSON.stringify(portList));
if (portList === undefined||portList.length === 0) {
  console.info('usbSerial portList is empty');
  return;
}
let portId: number = portList[0].portId;

// Check whether the device can be accessed by the application.
if (!serialManager.hasSerialRight(portId)) {
  await serialManager.requestSerialRight(portId).then(result => {
    if (!result) {
      // If the application does not have the access permission and is not granted by the user, the application exits.
      console.info('user is not granted the operation  permission');
      return;
    } else {
      console.info('grant permission successfully');
    }
  });
}

// Cancel the granted permission.
try {
  serialManager.cancelSerialRight(portId);
  console.info('cancelSerialRight success, portId: ', portId);
} catch (error) {
  console.error('cancelSerialRight error, ', JSON.stringify(error));
}

SerialAttribute

Represents the configuration parameters of a serial port.

System capability: SystemCapability.USB.USBManager.Serial

NameTypeMandatoryDescription
baudratenumberYesBaud rate.
dataBitsnumberNoData bit.
paritynumberNoParity check.
stopBitsnumberNoStop bit.

SerialPort

Represents the parameters of a serial port.

System capability: SystemCapability.USB.USBManager.Serial

NameTypeMandatoryDescription
portIdnumberYesPort number.
deviceNamestringYesSerial port device name.

BaudRates

Enumerates the baud rates.

System capability: SystemCapability.USB.USBManager.Serial

NameValueDescription
BAUDRATE_5050The baud rate is 50 bit/s.
BAUDRATE_7575The baud rate is 75 bit/s.
BAUDRATE_110110The baud rate is 110 bit/s.
BAUDRATE_134134The baud rate is 134 bit/s.
BAUDRATE_150150The baud rate is 150 bit/s.
BAUDRATE_200200The baud rate is 200 bit/s.
BAUDRATE_300300The baud rate is 300 bit/s.
BAUDRATE_600600The baud rate is 600 bit/s.
BAUDRATE_12001200The baud rate is 1200 bit/s.
BAUDRATE_18001800The baud rate is 1800 bit/s.
BAUDRATE_24002400The baud rate is 2400 bit/s.
BAUDRATE_48004800The baud rate is 4800 bit/s.
BAUDRATE_96009600The baud rate is 9600 bit/s.
BAUDRATE_1920019200The baud rate is 19200 bit/s.
BAUDRATE_3840038400The baud rate is 38400 bit/s.
BAUDRATE_5760057600The baud rate is 57600 bit/s.
BAUDRATE_115200115200The baud rate is 115200 bit/s.
BAUDRATE_230400230400The baud rate is 230400 bit/s.
BAUDRATE_460800460800The baud rate is 460800 bit/s.
BAUDRATE_500000500000The baud rate is 500000 bit/s.
BAUDRATE_576000576000The baud rate is 576000 bit/s.
BAUDRATE_921600921600The baud rate is 921600 bit/s.
BAUDRATE_10000001000000The baud rate is 1000000 bit/s.
BAUDRATE_11520001152000The baud rate is 1152000 bit/s.
BAUDRATE_15000001500000The baud rate is 1500000 bit/s.
BAUDRATE_20000002000000The baud rate is 2000000 bit/s.
BAUDRATE_25000002500000The baud rate is 2500000 bit/s.
BAUDRATE_30000003000000The baud rate is 3000000 bit/s.
BAUDRATE_35000003500000The baud rate is 3500000 bit/s.
BAUDRATE_40000004000000The baud rate is 4000000 bit/s.

DataBits

Enumerates the number of data bits.

System capability: SystemCapability.USB.USBManager.Serial

NameValueDescription
DATABIT_88The number of data bits is 8.
DATABIT_77The number of data bits is 7.
DATABIT_66The number of data bits is 6.
DATABIT_55The number of data bits is 5.

Parity

Enumerates the parity check modes.

System capability: SystemCapability.USB.USBManager.Serial

NameValueDescription
PARITY_NONE0No parity.
PARITY_ODD1Odd parity.
PARITY_EVEN2Even parity.
PARITY_MARK3Mark parity, whose parity bit is fixed at 1.
PARITY_SPACE4Space parity, whose parity bit is fixed at 0.

StopBits

Enumerates of the number of stop bits.

System capability: SystemCapability.USB.USBManager.Serial

NameValueDescription
STOPBIT_10The number of stop bits is 1.
STOPBIT_1P51The number of stop bits is 1.5.
STOPBIT_22The number of stop bits is 2.

你可能感兴趣的鸿蒙文章

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/rh3nxd