harmony 鸿蒙usb_serial_ddk_api.h

  • 2025-06-12
  • 浏览 (5)

usb_serial_ddk_api.h

Overview

Declares the USB Serial DDK APIs used by the host to access the serial port device.

Library: libusb_serial.z.so

File to include: <serial/usb_serial_ddk_api.h>

System capability: SystemCapability.Driver.SERIAL.Extension

Since: 18

Related module: USB Serial DDK

Summary

Function

Name Description
int32_t OH_UsbSerial_Init (void) Initializes the USB Serial DDK.
int32_t OH_UsbSerial_Release (void) Releases the USB Serial DDK.
int32_t OH_UsbSerial_Open (uint64_t deviceId, uint8_t interfaceIndex, UsbSerial_DeviceHandle **dev) Enables the USB serial port device based on the specified deviceId and interfaceIndex.
int32_t OH_UsbSerial_Close (UsbSerial_DeviceHandle *dev) Disables the USB serial port device.
int32_t OH_UsbSerial_Read (UsbSerial_DeviceHandle *dev, uint8_t *buff, uint32_t bufferSize, uint32_t *bytesRead) Reads data from the USB serial port device to the buffer.
int32_t OH_UsbSerial_Write (UsbSerial_DeviceHandle *dev, uint8_t *buff, uint32_t bufferSize, uint32_t *bytesWritten) Writes the data in the buffer to the USB serial port device.
int32_t OH_UsbSerial_SetBaudRate (UsbSerial_DeviceHandle *dev, uint32_t baudRate) Sets the baud rate for a USB serial port device. If the parameters of the USB serial port device are set to the default values (the data bit is 8, the stop bit is 1, and parity is disabled for data transfer), you only need to call this API to set the baud rate.
int32_t OH_UsbSerial_SetParams (UsbSerial_DeviceHandle *dev, UsbSerial_Params *params) Sets the parameters of the USB serial port device. If the parameters of the USB serial port device are not set to the default values (the data bit is 8, the stop bit is 1, and parity is disabled for data transfer), you only need to call this API to set the related parameters.
int32_t OH_UsbSerial_SetTimeout (UsbSerial_DeviceHandle *dev, int timeout) Sets the timeout interval (ms) for reading data reported by a USB serial port device. If this function is not called, the timeout value is 0 by default, indicating that data is returned immediately regardless of whether data is read. If you need to wait for a certain period of time or data must be read, call this API to set the timeout interval.
int32_t OH_UsbSerial_SetFlowControl (UsbSerial_DeviceHandle *dev, UsbSerial_FlowControl flowControl) Sets flow control parameters. Flow control is used to manage the data transfer rate during communication with the USB serial port device to ensure that the sender does not send data that exceeds the processing capability of the receiver.
If flow control is required, call this API to set flow control parameters. If this API is not called, flow control is not performed by default.
int32_t OH_UsbSerial_Flush (UsbSerial_DeviceHandle *dev) Clears the input and output buffers after the write operation is complete. If a large amount of data is to be transmitted to the USB serial port device, the data may be buffered in the kernel for transmission. If the application closes the file descriptor or exits before the data is completely sent out, some data may be lost. You can call this API to ensure that all data is sent before subsequent operations are performed.
int32_t OH_UsbSerial_FlushInput (UsbSerial_DeviceHandle *dev) Refreshes the input buffer. The data in the buffer is cleared immediately. During the communication with the USB serial port device, especially in the debugging phase, disordered data packets or other exceptions may occur.
You can call this API to clear these exceptions to restore the communication.
int32_t OH_UsbSerial_FlushOutput (UsbSerial_DeviceHandle *dev) Refreshes the output buffer. The data in the buffer is cleared immediately. During the communication with the USB serial port device, especially in the debugging phase, disordered data packets or other exceptions may occur.
You can call this API to clear these exceptions to restore the communication.

你可能感兴趣的鸿蒙文章

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

0  赞