tw.com.prolific.driver.pl2303g

## Class PL2303GDriver<UsbConfiguration>

- java.lang.Object
- - tw.com.prolific.driver.pl2303g.PL2303GDriver<UsbConfiguration>

-     public class PL2303GDriver<UsbConfiguration>
      extends java.lang.Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `PL2303GDriver.BaudRate`
    `static class` | `PL2303GDriver.DataBits`
    `static class` | `PL2303GDriver.FlowControl`
    `static class` | `PL2303GDriver.Parity`
    `static class` | `PL2303GDriver.StopBits`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BAUD0`
    `static int` | `BAUD115200`
    `static int` | `BAUD1200`
    `static int` | `BAUD12000000`
    `static int` | `BAUD1228800`
    `static int` | `BAUD14400`
    `static int` | `BAUD150`
    `static int` | `BAUD1800`
    `static int` | `BAUD19200`
    `static int` | `BAUD230400`
    `static int` | `BAUD2400`
    `static int` | `BAUD2457600`
    `static int` | `BAUD300`
    `static int` | `BAUD3000000`
    `static int` | `BAUD38400`
    `static int` | `BAUD460800`
    `static int` | `BAUD4800`
    `static int` | `BAUD57600`
    `static int` | `BAUD600`
    `static int` | `BAUD6000000`
    `static int` | `BAUD614400`
    `static int` | `BAUD75`
    `static int` | `BAUD921600`
    `static int` | `BAUD9600`
    `static int` | `PL_MAX_INTERFACE_NUM`
    `static int` | `PL2303G_CTS_ON`
    `static int` | `PL2303G_DCD_ON`
    `static int` | `PL2303G_DSR_ON`
    `static int` | `PL2303G_RI_ON`
    `int` | `PLDETACHED_VALUE`
    `java.lang.String` | `PLUART_DETACHED`
    `java.lang.String` | `PLUART_MESSAGE`
    `static int` | `READBUF_SIZE`
    `static java.lang.Object` | `ReadQueueLock`
    `static UsbDevice` | `sDevice`
    `static int` | `WRITEBUF_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PL2303GDriver(UsbManager manager, Context mContext, java.lang.String sAppName)` Initialize a PL2303G driver, the software 4K Queue buffer is enable.
    `PL2303GDriver(UsbManager manager, Context mContext, java.lang.String sAppName, boolean bWithQueue)` Initialize a PL2303G driver

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `end()` Close an PL2303G USB Device
    `boolean` | `enumerate()` Found a PL2303G device , the default VID_PID is 067B_23A3
    `boolean` | `InitByBaudRate(PL2303GDriver.BaudRate R)` Open an PL2303G USB Device by BaudRate (The stop bit is 1, The parity bit is none, The Flow Control is none), the Timeout Constant of read and write is 100ms
    `boolean` | `InitByBaudRate(PL2303GDriver.BaudRate R, int TimeoutConstant)` Open an PL2303G USB Device by BaudRate (The stop bit is 1, The parity bit is none, The Flow Control is none)
    `boolean` | `InitByDefualtValue()` Open an PL2303G USB Device by Default (The baud rate is 9600 bps,The stop bit is 1, The parity bit is none, The Flow Control is none),the Timeout Constant of read and write is 100ms
    `boolean` | `InitByPortSetting(PL2303GDriver.BaudRate R, PL2303GDriver.DataBits D, PL2303GDriver.StopBits S, PL2303GDriver.Parity P, PL2303GDriver.FlowControl F)` Open an PL2303G USB Device by BaudRate, Data bit, stop bit, parity bit and Flow Control
    `boolean` | `isConnected()` Get the connection status of this PL2303G, ie, whether there is an active connection with PL2303G device.
    `boolean` | `PL2303Device_GetCommTimeouts(int TimeoutConstant)` The PL2303Device_GetCommTimeouts function retrieves the time-out parameters for all read and write operations on a specified communications device.
    `java.lang.String` | `PL2303Device_GetSerialNumber()` Get PL2303G serial number
    `boolean` | `PL2303Device_IsHasPermission()` Detecting whether this PL2303 devices has permission
    `boolean` | `PL2303Device_IsSupportChip()` Detecting whether this PL2303 supports this Android OS, only PL2303G is supported.
    `boolean` | `PL2303Device_SetCommTimeouts(int TimeoutConstant)` The PL2303Device_SetCommTimeouts function sets the time-out parameters for all read and write operations on a specified communications device.
    `int` | `PL2303G_Enable_GPIO_B(int GPIO_Num, boolean Enable)` PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to control the direction of these pin
    `int[]` | `PL2303G_Get_GPIO_Value_B(int GPIO_Num)` PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to get the status of these pin when the direction is input mode
    `int[]` | `PL2303G_GetCommModemStatus()` The PL2303G_GetCommModemStatus function retrieves modem control-register values.
    `int` | `PL2303G_GPIO_B_CNT_ENABLE(boolean Enable)` PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to Init GPIO_B
    `int` | `PL2303G_Set_GPIO_Value_B(int GPIO_Num, int val)` PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to control the status of these pin when the direction is output mode
    `void` | `PL2303LibGetVersion(byte[] byVersion)` get the version of this library
    `boolean` | `PL2303USBFeatureSupported()` Detecting whether this Android OS supports USB host API feature
    `int` | `read(byte[] buf)` Read Binary Data from PL2303G chip
    `boolean` | `Set_PL2303_BaudRate(PL2303GDriver.BaudRate R)` Open an PL2303G USB Device by BaudRate
    `boolean` | `Set_PL2303_DataBit(PL2303GDriver.DataBits D)` Open an PL2303G USB Device by DataBit
    `boolean` | `Set_PL2303_FlowControl(PL2303GDriver.FlowControl F)` Open an PL2303G USB Device by Flow Control mode
    `boolean` | `Set_PL2303_Parity(PL2303GDriver.Parity P)` Open an PL2303G USB Device by Parity
    `boolean` | `Set_PL2303_StopBit(PL2303GDriver.StopBits S)` Open an PL2303G USB Device by StopBit
    `int` | `setDTR(boolean state)` Switch PL2303G DTR on or off
    `int` | `setRTS(boolean state)` Switch PL2303G RTS on or off
    `int` | `setup(PL2303GDriver.BaudRate R, PL2303GDriver.DataBits D, PL2303GDriver.StopBits S, PL2303GDriver.Parity P, PL2303GDriver.FlowControl F)` Setup basic communication parameters on PL2303G chip
    `int` | `write(byte[] buf)` Writes 1byte Binary Data to PL2303G chip
    `int` | `write(byte[] buf, int wlength)` Writes n byte Binary Data to PL2303G chip

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BAUD0

          public static final int BAUD0

      See Also:
        Constant Field Values

    - #### BAUD75

          public static final int BAUD75

      See Also:
        Constant Field Values

    - #### BAUD150

          public static final int BAUD150

      See Also:
        Constant Field Values

    - #### BAUD300

          public static final int BAUD300

      See Also:
        Constant Field Values

    - #### BAUD600

          public static final int BAUD600

      See Also:
        Constant Field Values

    - #### BAUD1200

          public static final int BAUD1200

      See Also:
        Constant Field Values

    - #### BAUD1800

          public static final int BAUD1800

      See Also:
        Constant Field Values

    - #### BAUD2400

          public static final int BAUD2400

      See Also:
        Constant Field Values

    - #### BAUD4800

          public static final int BAUD4800

      See Also:
        Constant Field Values

    - #### BAUD9600

          public static final int BAUD9600

      See Also:
        Constant Field Values

    - #### BAUD14400

          public static final int BAUD14400

      See Also:
        Constant Field Values

    - #### BAUD19200

          public static final int BAUD19200

      See Also:
        Constant Field Values

    - #### BAUD38400

          public static final int BAUD38400

      See Also:
        Constant Field Values

    - #### BAUD57600

          public static final int BAUD57600

      See Also:
        Constant Field Values

    - #### BAUD115200

          public static final int BAUD115200

      See Also:
        Constant Field Values

    - #### BAUD230400

          public static final int BAUD230400

      See Also:
        Constant Field Values

    - #### BAUD460800

          public static final int BAUD460800

      See Also:
        Constant Field Values

    - #### BAUD614400

          public static final int BAUD614400

      See Also:
        Constant Field Values

    - #### BAUD921600

          public static final int BAUD921600

      See Also:
        Constant Field Values

    - #### BAUD1228800

          public static final int BAUD1228800

      See Also:
        Constant Field Values

    - #### BAUD2457600

          public static final int BAUD2457600

      See Also:
        Constant Field Values

    - #### BAUD3000000

          public static final int BAUD3000000

      See Also:
        Constant Field Values

    - #### BAUD6000000

          public static final int BAUD6000000

      See Also:
        Constant Field Values

    - #### BAUD12000000

          public static final int BAUD12000000

      See Also:
        Constant Field Values

    - #### PL2303G_DCD_ON

          public static final int PL2303G_DCD_ON

      See Also:
        Constant Field Values

    - #### PL2303G_DSR_ON

          public static final int PL2303G_DSR_ON

      See Also:
        Constant Field Values

    - #### PL2303G_RI_ON

          public static final int PL2303G_RI_ON

      See Also:
        Constant Field Values

    - #### PL2303G_CTS_ON

          public static final int PL2303G_CTS_ON

      See Also:
        Constant Field Values

    - #### PL_MAX_INTERFACE_NUM

          public static final int PL_MAX_INTERFACE_NUM

      See Also:
        Constant Field Values

    - #### READBUF_SIZE

          public static final int READBUF_SIZE

      See Also:
        Constant Field Values

    - #### WRITEBUF_SIZE

          public static final int WRITEBUF_SIZE

      See Also:
        Constant Field Values

    - #### ReadQueueLock

          public static java.lang.Object ReadQueueLock

    - #### PLUART_MESSAGE

          public final java.lang.String PLUART_MESSAGE

      See Also:
        Constant Field Values

    - #### PLUART_DETACHED

          public final java.lang.String PLUART_DETACHED

      See Also:
        Constant Field Values

    - #### PLDETACHED_VALUE

          public final int PLDETACHED_VALUE

      See Also:
        Constant Field Values

    - #### sDevice

          public static UsbDevice sDevice

  - ### Constructor Detail

    - #### PL2303GDriver

          public PL2303GDriver(UsbManager manager,
                       Context mContext,
                       java.lang.String sAppName)

      Initialize a PL2303G driver, the software 4K Queue buffer is enable.
      Parameters:
        `manager` - [in] Initialize a PL2303G driver.
        `mContext` - [in] Initialize a PL2303G driver.
        `sAppName` - [in] , ACTION_USB_PERMISSION string, for example: "tw.com.prolific.PL2303Ggpio.USB_PERMISSION" "com.prolific.PL2303Gsimpletest.USB_PERMISSION" "XXX.AAA.CCC.USB_PERMISSION"

    - #### PL2303GDriver

          public PL2303GDriver(UsbManager manager,
                       Context mContext,
                       java.lang.String sAppName,
                       boolean bWithQueue)

      Initialize a PL2303G driver
      Parameters:
        `manager` - [in] Initialize a PL2303G driver.
        `mContext` - [in] Initialize a PL2303G driver.
        `sAppName` - [in] ACTION_USB_PERMISSION string, for example: "tw.com.prolific.PL2303Ggpio.USB_PERMISSION" "com.prolific.PL2303Gsimpletest.USB_PERMISSION" "XXX.AAA.CCC.USB_PERMISSION"
        `bWithQueue` - , Specifies the software 4K Queue buffer is enable or disable

  - ### Method Detail

    - #### enumerate

          public boolean enumerate()

      Found a PL2303G device , the default VID_PID is 067B_23A3

    - #### InitByDefualtValue

          public boolean InitByDefualtValue()

      Open an PL2303G USB Device by Default (The baud rate is 9600 bps,The stop bit is 1, The parity bit is none, The Flow Control is none),the Timeout Constant of read and write is 100ms
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### InitByBaudRate

          public boolean InitByBaudRate(PL2303GDriver.BaudRate R)

      Open an PL2303G USB Device by BaudRate (The stop bit is 1, The parity bit is none, The Flow Control is none), the Timeout Constant of read and write is 100ms
      Parameters:
        `R` - [in] UART baud rate , the baud rate range of PL2303G are 75~12M bps.
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### Set_PL2303_BaudRate

          public boolean Set_PL2303_BaudRate(PL2303GDriver.BaudRate R)

      Open an PL2303G USB Device by BaudRate
      Parameters:
        `R` - [in] UART baud rate , the baud rate range of PL2303G are 75~12M bps.
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### Set_PL2303_DataBit

          public boolean Set_PL2303_DataBit(PL2303GDriver.DataBits D)

      Open an PL2303G USB Device by DataBit
      Parameters:
        `D` - [in] UART Data bit, PL2303G supports 5, 6, 7 or 8 data bits
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### Set_PL2303_StopBit

          public boolean Set_PL2303_StopBit(PL2303GDriver.StopBits S)

      Open an PL2303G USB Device by StopBit
      Parameters:
        `S` - [in] UART Stop bit, PL2303G supports 1, 1.5 or 2 data bits
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### Set_PL2303_Parity

          public boolean Set_PL2303_Parity(PL2303GDriver.Parity P)

      Open an PL2303G USB Device by Parity
      Parameters:
        `P` - [in] UART Parity, supports Odd, Even, Mark, Space, or None parity mode
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### Set_PL2303_FlowControl

          public boolean Set_PL2303_FlowControl(PL2303GDriver.FlowControl F)

      Open an PL2303G USB Device by Flow Control mode
      Parameters:
        `F` - [in] UART FlowControl, PL2303G supports None, software or hardware Flow Control mode
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### InitByBaudRate

          public boolean InitByBaudRate(PL2303GDriver.BaudRate R,
                               int TimeoutConstant)

      Open an PL2303G USB Device by BaudRate (The stop bit is 1, The parity bit is none, The Flow Control is none)
      Parameters:
        `R` - [in] UART baud rate , the baud rate range of PL2303G is 75~12M bps
        `TimeoutConstant` - [in] Timeout Constant of read and write, you also can use PL2303Device_SetCommTimeouts to set timeout
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### InitByPortSetting

          public boolean InitByPortSetting(PL2303GDriver.BaudRate R,
                                  PL2303GDriver.DataBits D,
                                  PL2303GDriver.StopBits S,
                                  PL2303GDriver.Parity P,
                                  PL2303GDriver.FlowControl F)

      Open an PL2303G USB Device by BaudRate, Data bit, stop bit, parity bit and Flow Control
      Parameters:
        `R` - [in] UART baud rate , the baud rate range of PL2303G is 75~12M bps
        `D` - [in] UART Data bit, PL2303G supports 5, 6, 7 or 8 data bits
        `P` - [in] UART Parity bit, PL2303G supports Odd, Even, Mark, Space, or None parity mode
        `F` - [in] UART Flow Control mode, PL2303G supports None, software or hardware Flow Control mode
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### end

          public void end()

      Close an PL2303G USB Device

    - #### isConnected

          public boolean isConnected()

      Get the connection status of this PL2303G, ie, whether there is an active connection with PL2303G device.
      Returns:
        true if connected false if not connected

    - #### read

          public int read(byte[] buf)

      Read Binary Data from PL2303G chip
      Parameters:
        `buf` - : read buffer
      Returns:
        buffer length

    - #### write

          public int write(byte[] buf)

      Writes 1byte Binary Data to PL2303G chip
      Parameters:
        `buf` - : write buffer
      Returns:
        written length

    - #### write

          public int write(byte[] buf,
                  int wlength)

      Writes n byte Binary Data to PL2303G chip
      Parameters:
        `buf` - : write buffer
        `wlength` - : write length
      Returns:
        written length

    - #### setup

          public int setup(PL2303GDriver.BaudRate R,
                  PL2303GDriver.DataBits D,
                  PL2303GDriver.StopBits S,
                  PL2303GDriver.Parity P,
                  PL2303GDriver.FlowControl F)
                    throws java.io.IOException

      Setup basic communication parameters on PL2303G chip
      Parameters:
        `R` - BaudRate
        `D` - DataBits
        `S` - StopBits
        `P` - Parity
        `F` - FlowControl
      Throws:
        `java.io.IOException` - if settings not supported or connection is closed

    - #### setDTR

          public int setDTR(boolean state)

      Switch PL2303G DTR on or off
      Parameters:
        `state` - true: SET DTR, false: CLEAR DTR

    - #### setRTS

          public int setRTS(boolean state)

      Switch PL2303G RTS on or off
      Parameters:
        `state` - true: SET RTS, false: CLEAR RTS

    - #### PL2303G_GPIO_B_CNT_ENABLE

          public int PL2303G_GPIO_B_CNT_ENABLE(boolean Enable)

      PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to Init GPIO_B
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### PL2303G_Enable_GPIO_B

          public int PL2303G_Enable_GPIO_B(int GPIO_Num,
                                  boolean Enable)

      PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to control the direction of these pin
      Parameters:
        `GPIO_Num` - [in] The GPIO number, the range is 0 ~ 7
        `Enable` - [in] True is Output mode, false is input mode.
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### PL2303G_Set_GPIO_Value_B

          public int PL2303G_Set_GPIO_Value_B(int GPIO_Num,
                                     int val)

      PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to control the status of these pin when the direction is output mode
      Parameters:
        `GPIO_Num` - [in] The GPIO number, the range is 0 ~ 7
        `val` - [in] ¡§1¡¨ is High level, 0 is low level.
      Returns:
        Zero indicates success. Nonzero indicates failure.

    - #### PL2303G_Get_GPIO_Value_B

          public int[] PL2303G_Get_GPIO_Value_B(int GPIO_Num)

      PL2303G has 8 software controllable ¡§General Purpose Input Output¡¨ control signal pin, you can use this API to get the status of these pin when the direction is input mode
      Parameters:
        `GPIO_Num` - [in] The GPIO number, the range is 0 ~ 7
      Returns:
        int[] [0]: Zero indicates success. Nonzero indicates failure. [1]: Return data for GPIO value.¡§1¡¨ is High level, 0 is low level.

    - #### PL2303G_GetCommModemStatus

          public int[] PL2303G_GetCommModemStatus()

      The PL2303G_GetCommModemStatus function retrieves modem control-register values.
      Returns:
        int[] [0]: Zero indicates success. Nonzero indicates failure. [1]: Return data for ModemStatus (DCD, RI, DSR, DCTS)

    - #### PL2303LibGetVersion

          public void PL2303LibGetVersion(byte[] byVersion)

      get the version of this library

    - #### PL2303USBFeatureSupported

          public boolean PL2303USBFeatureSupported()

      Detecting whether this Android OS supports USB host API feature
      Returns:
        Zero indicates the devices supports the USB HOST API feature. else false.

    - #### PL2303Device_GetSerialNumber

          public java.lang.String PL2303Device_GetSerialNumber()

      Get PL2303G serial number
      Returns:
        the device serial number

    - #### PL2303Device_IsHasPermission

          public boolean PL2303Device_IsHasPermission()

      Detecting whether this PL2303 devices has permission
      Returns:
        true indicates this PL2303 devices has permission to access usb device, else false.

    - #### PL2303Device_IsSupportChip

          public boolean PL2303Device_IsSupportChip()

      Detecting whether this PL2303 supports this Android OS, only PL2303G is supported. Returns true indicates this PL2303 chip is supported, else false.

    - #### PL2303Device_SetCommTimeouts

          public boolean PL2303Device_SetCommTimeouts(int TimeoutConstant)

      The PL2303Device_SetCommTimeouts function sets the time-out parameters for all read and write operations on a specified communications device.
      Parameters:
        `TimeoutConstant` - : Timeout Constant of read and write
      Returns:
        If the function succeeds, the return value is true. If the function fails, the return value is false.

    - #### PL2303Device_GetCommTimeouts

          public boolean PL2303Device_GetCommTimeouts(int TimeoutConstant)

      The PL2303Device_GetCommTimeouts function retrieves the time-out parameters for all read and write operations on a specified communications device.
      Parameters:
        `TimeoutConstant` - : Timeout Constant of read and write
      Returns:
        If the function succeeds, the return value is true. If the function fails, the return value is false.