ComPort for Android USB

Delphi and C++ Builder serial communication library for USB connected devices for Android.
  • uses usb-serial-for-android library
  • supports FTDI FT232, FT2232, ...; Prolific PL2303; Silabs CP2102, CP2105, ...; Qinheng CH340; CDC/ACM (Arduino Uno) chips
  • no special root access privileges needed
  • available for Delphi/C++ Builder XE6 - 10.3
  • source code included in registered version
  • royalty free distribution in applications


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

  TOnDeviceAttached = procedure(Device: JUsbDevice) of object;
  TOnDeviceDetached = procedure(Device: JUsbDevice) of object;
  TOnError = procedure(Exception: JException) of object;
  TOnPermission = procedure(Device: JUsbDevice; Granted: Boolean) of object;
  TOnReceivedData = procedure(Data: TArray<Byte>) of object;

  EUsbSerialError = class(Exception);

  TUsbSerial = class
    constructor Create;

    function GetDevice(Driver: JUsbSerialDriver): JUsbDevice;
    function GetDevice(Port: JUsbSerialPort): JUsbDevice;

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

    procedure Connect(Port: JUsbSerialPort);
    procedure Disconnect;

    procedure Open;
    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 WriteAsync(Buffer: TJavaArray<Byte>);
    procedure WriteAsync(Buffer: TArray<Byte>);
    procedure WriteAsync(Data: Byte);

    function Purge: Boolean;
    function PurgeInput: Boolean;
    function PurgeOutput: Boolean;

    property BaudRate: Integer read write;
    property CD: Boolean read;
    property Connected: Boolean read;
    property CTS: Boolean read;
    property DataBits: TDataBits read write;
    property DSR: Boolean read;
    property DTR: Boolean read write;
    property Opened: Boolean read;
    property Parity: TParity read write;
    property RI: Boolean read;
    property RTS: Boolean read write;
    property StopBits: TStopBits read write;
    property UsbDevice: JUsbDevice read;
    property UsbDeviceConnection: JUsbDeviceConnection read;
    property UsbSerialDrivers: TArray<JUsbSerialDriver> read;
    property UsbSerialPorts[const Driver: JUsbSerialDriver]: TArray<JUsbSerialPort> read;
    property UsbSerialPort: JUsbSerialPort read;
    property UsbManager: JUsbManager read;

    property OnDeviceAttached: TOnDeviceAttached read write;
    property OnDeviceDetached: TOnDeviceDetached read write;
    property OnError: TOnError 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