ComPort for Android Prolific

Delphi and C++ Builder serial communication library for Prolific devices for Android.
  • uses Prolific PL2303 library
  • no special root access privileges needed
  • available for Delphi/C++ Builder XE6 - 10.2
  • source code included in registered version
  • royalty free distribution in applications

API

JPL2303Driver_BaudRateClass = interface(JObjectClass)
  {Methods}
  function valueOf(Param0: JString): JPL2303Driver_BaudRate;
  function values: TJavaObjectArray<JPL2303Driver_BaudRate>;
  {Properties}
  property B0: JPL2303Driver_BaudRate read write;
  property B115200: JPL2303Driver_BaudRate read write;
  property B1200: JPL2303Driver_BaudRate read write;
  property B12000000: JPL2303Driver_BaudRate read write;
  property B1228800: JPL2303Driver_BaudRate read write;
  property B14400: JPL2303Driver_BaudRate read write;
  property B150: JPL2303Driver_BaudRate read write;
  property B1800: JPL2303Driver_BaudRate read write;
  property B19200: JPL2303Driver_BaudRate read write;
  property B230400: JPL2303Driver_BaudRate read write;
  property B2400: JPL2303Driver_BaudRate read write;
  property B2457600: JPL2303Driver_BaudRate read write;
  property B300: JPL2303Driver_BaudRate read write;
  property B3000000: JPL2303Driver_BaudRate read write;
  property B38400: JPL2303Driver_BaudRate read write;
  property B460800: JPL2303Driver_BaudRate read write;
  property B4800: JPL2303Driver_BaudRate read write;
  property B57600: JPL2303Driver_BaudRate read write;
  property B600: JPL2303Driver_BaudRate read write;
  property B6000000: JPL2303Driver_BaudRate read write;
  property B614400: JPL2303Driver_BaudRate read write;
  property B75: JPL2303Driver_BaudRate read write;
  property B921600: JPL2303Driver_BaudRate read write;
  property B9600: JPL2303Driver_BaudRate read write;
end;

JPL2303Driver_DataBitsClass = interface(JObjectClass)
  {Methods}
  function valueOf(Param0: JString): JPL2303Driver_DataBits;
  function values: TJavaObjectArray<JPL2303Driver_DataBits>;
  {Properties}
  property D5: JPL2303Driver_DataBits read write;
  property D6: JPL2303Driver_DataBits read write;
  property D7: JPL2303Driver_DataBits read write;
  property D8: JPL2303Driver_DataBits read write;
end;

JPL2303Driver_FlowControlClass = interface(JObjectClass)
  {Methods}
  function valueOf(Param0: JString): JPL2303Driver_FlowControl;
  function values: TJavaObjectArray<JPL2303Driver_FlowControl>;
  {Properties}
  property DTRDSR: JPL2303Driver_FlowControl read write;
  property OFF: JPL2303Driver_FlowControl read write;
  property RFRCTS: JPL2303Driver_FlowControl read write;
  property RTSCTS: JPL2303Driver_FlowControl read write;
  property RTSCTSDTRDSR: JPL2303Driver_FlowControl read write;
  property XONXOFF: JPL2303Driver_FlowControl read write;
end;

JPL2303Driver_ParityClass = interface(JObjectClass)
  {Methods}
  function valueOf(Param0: JString): JPL2303Driver_Parity;
  function values: TJavaObjectArray<JPL2303Driver_Parity>;
  {Properties}
  property EVEN: JPL2303Driver_Parity read write;
  property NONE: JPL2303Driver_Parity read write;
  property ODD: JPL2303Driver_Parity read write;
end;

JPL2303Driver_StopBitsClass = interface(JObjectClass)
  {Methods}
  function valueOf(Param0: JString): JPL2303Driver_StopBits;
  function values: TJavaObjectArray<JPL2303Driver_StopBits>;
  {Properties}
  property S1: JPL2303Driver_StopBits read write;
  property S2: JPL2303Driver_StopBits read write;
end;

JPL2303DriverClass = interface(JObjectClass)
  {Methods}
  function init(manager: JUsbManager; mContext: JContext; sAppName: JString): JPL2303Driver;
  function init(manager: JUsbManager; mContext: JContext; sAppName: JString; bWithQueue: Boolean): JPL2303Driver;
  {Properties}
  property BAUD0: Integer read;
  property BAUD115200: Integer read;
  property BAUD1200: Integer read;
  property BAUD12000000: Integer read;
  property BAUD1228800: Integer read;
  property BAUD14400: Integer read;
  property BAUD150: Integer read;
  property BAUD1800: Integer read;
  property BAUD19200: Integer read;
  property BAUD230400: Integer read;
  property BAUD2400: Integer read;
  property BAUD2457600: Integer read;
  property BAUD300: Integer read;
  property BAUD3000000: Integer read;
  property BAUD38400: Integer read;
  property BAUD460800: Integer read
  property BAUD4800: Integer read
  property BAUD57600: Integer read;
  property BAUD600: Integer read;
  property BAUD6000000: Integer read;
  property BAUD614400: Integer read;
  property BAUD75: Integer read;
  property BAUD921600: Integer read;
  property BAUD9600: Integer read;
  property PL2303HXD_CTS_ON: Integer read;
  property PL2303HXD_DCD_ON: Integer read;
  property PL2303HXD_DSR_ON: Integer read;
  property PL2303HXD_RI_ON: Integer read;
  property PL_MAX_INTERFACE_NUM: Integer read;
  property READBUF_SIZE: Integer read;
  property ReadQueueLock: JObject read write;
  property sDevice: JUsbDevice read write;
  property WRITEBUF_SIZE: Integer read;
end;

JPL2303Driver = interface(JObject)
  {Methods}
  procedure &end;
  function enumerate: Boolean;
  function InitByBaudRate(R: JPL2303Driver_BaudRate): Boolean;
  function InitByBaudRate(R: JPL2303Driver_BaudRate; TimeoutConstant: Integer): Boolean;
  function InitByDefualtValue: Boolean;
  function InitByPortSetting(R: JPL2303Driver_BaudRate; D: JPL2303Driver_DataBits; S: JPL2303Driver_StopBits;
      P: JPL2303Driver_Parity; F: JPL2303Driver_FlowControl): Boolean;
  function isConnected: Boolean;
  function PL2303Device_GetCommTimeouts(TimeoutConstant: Integer): Boolean;
  function PL2303Device_GetSerialNumber: JString;
  function PL2303Device_IsHasPermission: Boolean;
  function PL2303Device_IsSupportChip: Boolean;
  function PL2303Device_SetCommTimeouts(TimeoutConstant: Integer): Boolean;
  function PL2303HXD_Enable_GPIO(GPIO_Num: Integer; Enable: Boolean): Integer;
  function PL2303HXD_GetCommModemStatus: TJavaArray<Integer>;
  function PL2303HXD_Get_GPIO_Value(GPIO_Num: Integer): TJavaArray<Integer>;
  function PL2303HXD_Set_GPIO_Value(GPIO_Num: Integer; val: Integer): Integer;
  procedure PL2303LibGetVersion(byVersion: TJavaArray<Byte>);
  function PL2303TB_Enable_GPIO(GPIO_Num: Integer; Enable: Boolean): Integer;
  function PL2303TB_Get_GPIO_Value(GPIO_Num: Integer): TJavaArray<Integer>;
  function PL2303TB_Set_GPIO_Value(GPIO_Num: Integer; val: Integer): Integer;
  function PL2303TB_Set_PWM(PWM_IO_Num: Integer; Frequency_value: Byte; Duty_value: Byte): Integer;
  function PL2303USBFeatureSupported: Boolean;
  function &read(buf: TJavaArray<Byte>): Integer;
  function setDTR(state: Boolean): Integer;
  function setRTS(state: Boolean): Integer;
  function setup(R: JPL2303Driver_BaudRate; D: JPL2303Driver_DataBits; S: JPL2303Driver_StopBits;
     P: JPL2303Driver_Parity; F: JPL2303Driver_FlowControl): Integer;
  function &write(buf: TJavaArray<Byte>): Integer;
  function &write(buf: TJavaArray<Byte>; wlength: Integer): Integer;
  {Properties}
  property PLDETACHED_VALUE: Integer read;
  property PLUART_DETACHED: JString read;
  property PLUART_MESSAGE: JString read;
end;
							

Download and order

FAQ

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

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

<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
							

Related links