ComPort for Android USB Serial

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

API

type
  JUsbSerialInterface_UsbBreakCallback = interface(IJavaInstance)
    procedure onBreakInterrupt;
  end;

  JUsbSerialInterface_UsbCTSCallback = interface(IJavaInstance)
    procedure onCTSChanged(State: Boolean);
  end;

  JUsbSerialInterface_UsbDSRCallback = interface(IJavaInstance)
    procedure onDSRChanged(State: Boolean);
  end;

  JUsbSerialInterface_UsbFrameCallback = interface(IJavaInstance)
    procedure onFramingError;
  end;

  JUsbSerialInterface_UsbOverrunCallback = interface(IJavaInstance)
    procedure onOverrunError;
  end;

  JUsbSerialInterface_UsbParityCallback = interface(IJavaInstance)
    procedure onParityError;
  end;

  JUsbSerialInterface_UsbReadCallback = interface(IJavaInstance)
    procedure onReceivedData(data: TJavaArray<Byte>);
  end;

  JUsbSerialInterfaceClass = interface(IJavaClass)
    property DATA_BITS_5: Integer;
    property DATA_BITS_6: Integer;
    property DATA_BITS_7: Integer;
    property DATA_BITS_8: Integer;
    property FLOW_CONTROL_DSR_DTR: Integer;
    property FLOW_CONTROL_OFF: Integer;
    property FLOW_CONTROL_RTS_CTS: Integer;
    property FLOW_CONTROL_XON_XOFF: Integer;
    property PARITY_EVEN: Integer;
    property PARITY_MARK: Integer;
    property PARITY_NONE: Integer;
    property PARITY_ODD: Integer;
    property PARITY_SPACE: Integer;
    property STOP_BITS_1: Integer;
    property STOP_BITS_15: Integer;
    property STOP_BITS_2: Integer;
  end;

  JUsbSerialInterface = interface(IJavaInstance)
    procedure close;
    procedure getBreak(breakCallback: JUsbSerialInterface_UsbBreakCallback);
    procedure getCTS(ctsCallback: JUsbSerialInterface_UsbCTSCallback);
    procedure getDSR(dsrCallback: JUsbSerialInterface_UsbDSRCallback);
    procedure getFrame(frameCallback: JUsbSerialInterface_UsbFrameCallback);
    procedure getOverrun(overrunCallback: JUsbSerialInterface_UsbOverrunCallback);
    procedure getParity(parityCallback: JUsbSerialInterface_UsbParityCallback);
    function open: Boolean;
    function &read(readCallback: JUsbSerialInterface_UsbReadCallback): Integer;
    procedure setBaudRate(baudRate: Integer);
    procedure setDataBits(dataBits: Integer);
    procedure setDTR(state: Boolean);
    procedure setFlowControl(flowControl: Integer);
    procedure setParity(parity: Integer);
    procedure setRTS(state: Boolean);
    procedure setStopBits(stopBits: Integer);
    procedure syncClose;
    function syncOpen: Boolean;
    function syncRead(buffer: TJavaArray<Byte>; timeout: Integer): Integer;
    function syncWrite(buffer: TJavaArray<Byte>; timeout: Integer): Integer;
    procedure &write(buffer: TJavaArray<Byte>);
  end;

Download and order

FAQ

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
device_filter.xmlres\xml\

Related links