tw.com.prolific.driver.pl2303

## Class PL2303Driver

- java.lang.Object
- - tw.com.prolific.driver.pl2303.PL2303Driver

-     public class PL2303Driver
      extends java.lang.Object

- - ### Nested Class Summary

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

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BAUD0`
    `static int` | `BAUD115200`
    `static int` | `BAUD1200`
    `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` | `READBUF_SIZE`
    `static java.lang.Object` | `ReadQueueLock`
    `static UsbDevice` | `sDevice`
    `static int` | `WRITEBUF_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PL2303Driver(UsbManager manager, Context mContext, java.lang.String sAppName)` Initialize a PL2303HXD driver

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `end()` Close an PL2303HXD USB Device
    `boolean` | `enumerate()` Found a PL2303HXD device , the default VID_PID is 067B_2303
    `boolean` | `InitByBaudRate(PL2303Driver.BaudRate R)` Open an PL2303HXD USB Device by BaudRate
    `boolean` | `InitByDefualtValue()` Open an PL2303HXD USB Device
    `boolean` | `InitByPortSetting(PL2303Driver.BaudRate R, PL2303Driver.DataBits D, PL2303Driver.StopBits S, PL2303Driver.Parity P, PL2303Driver.FlowControl F)` Open an PL2303HXD USB Device by PortSetting
    `boolean` | `isConnected()` Get the connection status of this PL2303HXD, ie, whether there is an active connection with PL2303HXD device.
    `int` | `read(short[] buf)` Read Binary Data from PL2303HXD chip
    `int` | `setDTR(boolean state)` Switch PL2303HXD DTR on or off
    `void` | `SetReadTimeout(int iReadTimeOutConstant)` Set Read Time Out Constant, the default is 5000ms
    `int` | `setRTS(boolean state)` Switch PL2303HXD RTS on or off
    `int` | `setup(PL2303Driver.BaudRate R, PL2303Driver.DataBits D, PL2303Driver.StopBits S, PL2303Driver.Parity P, PL2303Driver.FlowControl F)` Setup basic communication parameters on PL2303HXD chip
    `void` | `SetWriteTimeout(int iWriteTimeOutConstant)` Set Write Time Out Constant, the default is 100ms
    `int` | `write(byte[] buf)` Writes 1byte Binary Data to PL2303HXD chip
    `int` | `write(byte[] buf, int wlength)` Writes n byte Binary Data to PL2303HXD 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

    - #### 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

    - #### sDevice

          public static UsbDevice sDevice

  - ### Constructor Detail

    - #### PL2303Driver

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

      Initialize a PL2303HXD driver
      Parameters:
        `manager` - Initialize a PL2303HXD driver.
        `mContext` - "this"
        `sAppName` - App name for USB permission, for example: "com.prolific.pl2303hxdsimpletest.USB_PERMISSION" or "testAP.USB_PERMISSION"

  - ### Method Detail

    - #### SetReadTimeout

          public void SetReadTimeout(int iReadTimeOutConstant)

      Set Read Time Out Constant, the default is 5000ms
      Parameters:
        `iReadTimeOutConstant` - in milliseconds

    - #### SetWriteTimeout

          public void SetWriteTimeout(int iWriteTimeOutConstant)

      Set Write Time Out Constant, the default is 100ms
      Parameters:
        `iWriteTimeOutConstant` - in milliseconds

    - #### enumerate

          public boolean enumerate()

      Found a PL2303HXD device , the default VID_PID is 067B_2303
      Returns:
        true if the PL2303HXD USB Device was found.

    - #### InitByDefualtValue

          public boolean InitByDefualtValue()

      Open an PL2303HXD USB Device
      Returns:
        true if the PL2303HXD USB Device was successfully opened

    - #### InitByBaudRate

          public boolean InitByBaudRate(PL2303Driver.BaudRate R)

      Open an PL2303HXD USB Device by BaudRate
      Parameters:
        `BaudRate` - Bard Rate setting value for UART.
      Returns:
        true if the PL2303HXD USB Device was successfully opened

    - #### InitByPortSetting

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

      Open an PL2303HXD USB Device by PortSetting
      Parameters:
        `Enum` - BaudRate
        `Enum` - DataBits
        `Enum` - StopBits
        `Enum` - Parity
        `Enum` - FlowControl

    - #### end

          public void end()

      Close an PL2303HXD USB Device

    - #### isConnected

          public boolean isConnected()

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

    - #### read

          public int read(short[] buf)

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

    - #### write

          public int write(byte[] buf)

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

    - #### write

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

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

    - #### setup

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

      Setup basic communication parameters on PL2303HXD chip
      Parameters:
        `Enum` - BaudRate
        `Enum` - DataBits
        `Enum` - StopBits
        `Enum` - Parity
        `Enum` - FlowControl
      Throws:
        `java.io.IOException` - if settings not supported or connection is closed

    - #### setDTR

          public int setDTR(boolean state)

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

    - #### setRTS

          public int setRTS(boolean state)

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