ComPort for Android USB Serial

Delphi and C++ Builder serial communication library for USB connected devices for Android.
  • uses UsbSerial library
  • supports CP210x, CP2130, CDC, FTDI, PL2303 and CH34x devices
  • no special root access privileges needed
  • available for Delphi/C++ Builder XE6 - 10.4
  • source code included in registered version
  • royalty free distribution in applications


  TDataBits = (db5, db6, db7, db8);
  TStopBits = (sb1, sb15, sb2);
  TParity = (paNone, paOdd, paEven, paMark, paSpace);
  TFlowControl = (fcOff, fcRtsCts, fcDsrDtr, fcXonXoff);

  TOnBreakInterrupt = procedure of object;
  TOnCtsChanged = procedure(State: Boolean) of object;
  TOnDeviceAttached = procedure(Device: JUsbDevice) of object;
  TOnDeviceDetached = procedure(Device: JUsbDevice) of object;
  TOnDsrChanged = procedure(State: Boolean) of object;
  TOnFramingError = procedure of object;
  TOnOverrunError = procedure of object;
  TOnParityError = procedure of object;
  TOnPermission = procedure(Device: JUsbDevice; Granted: Boolean) of object;
  TOnReceivedData = procedure(Data: TJavaArray<Byte>) of object;

  EUsbSerialError = class(Exception);

  TUsbSerial = class
    constructor Create;

    function IsSupported(UsbDevice: JUsbDevice): Boolean;
    function HasPermission(UsbDevice: JUsbDevice): Boolean;
    procedure RequestPermission(UsbDevice: JUsbDevice);

    procedure Connect(UsbDevice: JUsbDevice);
    procedure Disconnect;

    procedure Open(Synchronous: Boolean = False);
    procedure Close;

    function Read(Buffer: TJavaArray<Byte>; Timeout: Integer = 0): Integer;
    function Read(Buffer: TArray<Byte>; Timeout: Integer = 0): Integer;
    function Read(var Data: Byte; Timeout: Integer = 0): Integer;

    function Write(Buffer: TJavaArray<Byte>; Timeout: Integer = 0): Integer;
    function Write(Buffer: TArray<Byte>; Timeout: Integer = 0): Integer;
    function Write(Data: Byte; Timeout: Integer = 0): Integer;

    procedure ClearBreak;
    procedure SetBreak;

    procedure ClearDtr;
    procedure SetDtr;

    procedure ClearRts;
    procedure SetRts;

    property BaudRate: Integer read write;
    property Connected: Boolean read;
    property DataBits: TDataBits read write;
    property FlowControl: TFlowControl read write;
    property Opened: Boolean read;
    property Parity: TParity read write;
    property StopBits: TStopBits read write;
    property Synchronous: Boolean read;
    property UsbDevice: JUsbDevice read;
    property UsbDeviceConnection: JUsbDeviceConnection read;
    property UsbDevices: TArray<JUsbDevice> read;
    property UsbManager: JUsbManager read;
    property UsbSerialInterface: JUsbSerialInterface read;

    property OnBreakInterrupt: TOnBreakInterrupt read write;
    property OnCtsChanged: TOnCtsChanged read write;
    property OnDeviceAttached: TOnDeviceAttached read write;
    property OnDeviceDetached: TOnDeviceDetached read write;
    property OnDsrChanged: TOnDsrChanged read write;
    property OnFramingError: TOnFramingError read write;
    property OnOverrunError: TOnOverrunError read write;
    property OnParityError: TOnParityError read write;
    property OnPermission: TOnPermission read write;
    property OnReceivedData: TOnReceivedData read write;

function ToByteArray(JavaArray: TJavaArray<Byte>): TArray<Byte>;

Download and order


What files should be deployed to Android device?
Add these files in Delphi Deployment window:
Local NameRemote Path  Note
usbserial.dexassets\internal\  Delphi 10 and higher: add classes.jar to Libraries list in Project Manager instead

Add these lines to AndroidManifest.template.xml file:
  <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />

<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
How can I determine chip used in USB/RS232 adapter?
Use HWiNFO on PC and USB Library for Android demo example on Android.

Related links