## com.thingmagic
Class AndroidUsbReflection

    java.lang.Object
      com.thingmagic.AndroidUsbReflection

    public class AndroidUsbReflection

extends java.lang.Object

Provides access to Android USB classes via Java reflection. To simplify the build and reduce the size of our distribution by not making a hard link to Android.

Field Summary
`static int` `deviceClass`
`static java.util.Map` `deviceList`
`static java.lang.Object` `ftDev`

Constructor Summary
`AndroidUsbReflection(java.util.Map devices)`
`AndroidUsbReflection(java.lang.Object usbmanager, java.lang.Object ftdev, java.lang.Object usbdevice, int deviceClass)`

Method Summary
`static int` `bulkTransfer(java.lang.Object usbConnection, java.lang.Object endPoint, byte[] data, int length, int timeout)` Invokes the method `android.hardware.usb.UsbDeviceConnection#bulkTransfer`.
`static int` `bulkTransfer(java.lang.Object usbConnection, java.lang.Object endPoint, byte[] data, int offset, int length, int timeout)` Invokes the method `android.hardware.usb.UsbDeviceConnection#bulkTransfer`.
`static boolean` `claimInterface(java.lang.Object usbConnection, java.lang.Object usbInterface)` Invokes the method `android.hardware.usb.UsbDeviceConnection#claimInterface`.
`static void` `close()` Invokes the method `#close`.
`static void` `closeConnection(java.lang.Object usbConnection)` Invokes the method `android.hardware.usb.UsbDeviceConnection#close`.
`static int` `controlTransfer(java.lang.Object usbConnection, int FTDI_DEVICE_OUT_REQTYPE, int SIO_SET_BAUD_RATE_REQUEST, int value, int index, byte[] data, int length, int USB_WRITE_TIMEOUT_MILLIS)` Invokes the method `android.hardware.usb.UsbDeviceConnection#controlTransfer`.
`static int` `getDeviceClass()`
`static int` `getEndPointDirection(java.lang.Object usbEndpoint)` Invokes the method `android.hardware.usb.UsbEndpoint#getDirection`.
`static java.lang.Object` `getInterface(int index)` Invokes the method `android.hardware.usb.UsbDevice#getInterface`.
`static int` `getInterfaceCount()` Invokes the method `android.hardware.usb.UsbDevice#getInterfaceCount`.
`static java.lang.Object` `getReadEndPoint(java.lang.Object usbInterFace, int readPointAddr)` Invokes the method `android.hardware.usb.UsbInterface#getEndpoint`.
`static int` `getstatusQ()` Invokes the method `#getQueueStatus`.
`java.util.HashMap<java.lang.String,java.lang.Object>` `getUSBDeviceList()`
`static java.lang.Object` `getWriteEndPoint(java.lang.Object usbInterFace, int writeEndPointAddr)` Invokes the method `android.hardware.usb.UsbInterface#getEndpoint`.
`static boolean` `hasAccessPermission()` Invokes the method `android.hardware.usb.UsbManager#hasAccessPermission`.
`static boolean` `initialize(java.lang.Object usbConnection, java.lang.Object readEndPoint)` Invokes the method `android.hardware.usb.UsbRequest#initialize`.
`static boolean` `isBufferFull()` Invokes the method `#readBufferFull`.
`static boolean` `isOpen()` Invokes the method `#isOpen`.
`static java.lang.Object` `openDevice()` Invokes the method `android.hardware.usb.UsbManager#openDevice`.
`static int` `read(byte[] buf, int len, long timeout)` Invokes the method `#read`.
`static java.nio.ByteBuffer` `readBufferqueue(java.nio.ByteBuffer buffer, int length)` Invokes the method `android.hardware.usb.UsbRequest#queue`.
`static boolean` `requestPermission()`
`static java.lang.Object` `requestWait(java.lang.Object usbConnection)`
`static void` `reSet()` Invokes the method `#resetDevice`.
`static void` `reSet(java.lang.Object usbConnection)`
`static boolean` `setBaudRate(int baudRate)` Invokes the method `#getQueueStatus`.
`static java.lang.Object` `setClientData()`
`static int` `write(byte[] buf, int len)` Invokes the method `#write`.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### deviceList

    public static java.util.Map deviceList

### deviceClass

    public static int deviceClass

### ftDev

    public static java.lang.Object ftDev

Constructor Detail

### AndroidUsbReflection

    public AndroidUsbReflection(java.lang.Object usbmanager,
                                java.lang.Object ftdev,
                                java.lang.Object usbdevice,
                                int deviceClass)

### AndroidUsbReflection

    public AndroidUsbReflection(java.util.Map devices)

Method Detail

### getDeviceClass

    public static int getDeviceClass()

### getUSBDeviceList

    public java.util.HashMap<java.lang.String,java.lang.Object> getUSBDeviceList()
                                                                          throws java.lang.NoSuchFieldException

  Throws:
    `java.lang.NoSuchFieldException`

### getstatusQ

    public static int getstatusQ()

  Invokes the method `#getQueueStatus`.

  Returns:
    the number of bytes available to read from the driver Rx buffer.

### read

    public static int read(byte[] buf,
                           int len,
                           long timeout)
                    throws java.io.IOException

  Invokes the method `#read`.

  Throws:
    `java.io.IOException`

### write

    public static int write(byte[] buf,
                            int len)
                     throws java.io.IOException

  Invokes the method `#write`.

  Throws:
    `java.io.IOException`

### close

    public static void close()

  Invokes the method `#close`.

### reSet

    public static void reSet()

  Invokes the method `#resetDevice`.

### isOpen

    public static boolean isOpen()

  Invokes the method `#isOpen`.

  Returns:
    the open status of the device

### setBaudRate

    public static boolean setBaudRate(int baudRate)

  Invokes the method `#getQueueStatus`.

### isBufferFull

    public static boolean isBufferFull()

  Invokes the method `#readBufferFull`.

  Returns:
    true if Rx buffer is full.

### hasAccessPermission

    public static boolean hasAccessPermission()

  Invokes the method `android.hardware.usb.UsbManager#hasAccessPermission`.

  Parameters:
    `usbDevice` - a `android.hardware.usb.UsbDevice` object
  Returns:
    true if the caller has permission to access the device.

### requestPermission

    public static boolean requestPermission()

### reSet

    public static void reSet(java.lang.Object usbConnection)

### openDevice

    public static java.lang.Object openDevice()

  Invokes the method `android.hardware.usb.UsbManager#openDevice`.

  Parameters:
    `usbDevice` - a `android.hardware.usb.UsbDevice` object
  Returns:
    a `android.hardware.usb.UsbRequest` object, or null if failed to open

### getInterfaceCount

    public static int getInterfaceCount()

  Invokes the method `android.hardware.usb.UsbDevice#getInterfaceCount`.

  Returns:
    the number of UsbInterfaces this device contains.

### claimInterface

    public static boolean claimInterface(java.lang.Object usbConnection,
                                         java.lang.Object usbInterface)
                                  throws java.lang.IllegalArgumentException

  Invokes the method `android.hardware.usb.UsbDeviceConnection#claimInterface`.

  Parameters:
    `usbInterface` - a `android.hardware.usb.UsbInterface` object and boolean flag (true to disconnect kernel driver if necessary)
  Returns:
    true if the interface was successfully claimed
  Throws:
    `java.lang.IllegalArgumentException`

### getInterface

    public static java.lang.Object getInterface(int index)

  Invokes the method `android.hardware.usb.UsbDevice#getInterface`.

  Parameters:
    `index` - a integer
  Returns:
    usbInterface `android.hardware.usb.UsbInterface` a Object

### getReadEndPoint

    public static java.lang.Object getReadEndPoint(java.lang.Object usbInterFace,
                                                   int readPointAddr)
                                            throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbInterface#getEndpoint`.

  Parameters:
    `index` - a integer(0 for read endpoint)
  Returns:
    usbEndpoint `android.hardware.usb.UsbEndpoint` a Object
  Throws:
    `java.io.IOException`

### getEndPointDirection

    public static int getEndPointDirection(java.lang.Object usbEndpoint)
                                    throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbEndpoint#getDirection`.

  Returns:
    USB_DIR_OUT(Constant Value:0) if the direction is host to device, and USB_DIR_IN(Constant Value:128) if the direction is device to host.
  Throws:
    `java.io.IOException`

### getWriteEndPoint

    public static java.lang.Object getWriteEndPoint(java.lang.Object usbInterFace,
                                                    int writeEndPointAddr)
                                             throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbInterface#getEndpoint`.

  Parameters:
    `index` - a integer(1 for write endpoint)
  Returns:
    usbEndpoint `android.hardware.usb.UsbEndpoint` a Object
  Throws:
    `java.io.IOException`

### bulkTransfer

    public static int bulkTransfer(java.lang.Object usbConnection,
                                   java.lang.Object endPoint,
                                   byte[] data,
                                   int length,
                                   int timeout)
                            throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbDeviceConnection#bulkTransfer`.

  Parameters:
    `usbendPoint` - `android.hardware.usb.UsbEndpoint` a Object
    `buffer` - a byte[] for data to send or receive
    `length` - a integer,the length of the data to send or receive
    `timeout` - a integer
  Returns:
    length of data transferred (or zero) for success, or negative value for failure.
  Throws:
    `java.io.IOException`

### bulkTransfer

    public static int bulkTransfer(java.lang.Object usbConnection,
                                   java.lang.Object endPoint,
                                   byte[] data,
                                   int offset,
                                   int length,
                                   int timeout)
                            throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbDeviceConnection#bulkTransfer`.

  Parameters:
    `usbendPoint` - `android.hardware.usb.UsbEndpoint` a Object
    `buffer` - a byte[] for data to send or receive
    `offset` - a integer, the index of the first byte in the buffer to send or receive
    `length` - a integer,the length of the data to send or receive
    `timeout` - a integer
  Returns:
    length of data transferred (or zero) for success, or negative value for failure.
  Throws:
    `java.io.IOException`

### controlTransfer

    public static int controlTransfer(java.lang.Object usbConnection,
                                      int FTDI_DEVICE_OUT_REQTYPE,
                                      int SIO_SET_BAUD_RATE_REQUEST,
                                      int value,
                                      int index,
                                      byte[] data,
                                      int length,
                                      int USB_WRITE_TIMEOUT_MILLIS)
                               throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbDeviceConnection#controlTransfer`.

  Parameters:
    `requestType` - a integer, request type for this transaction
    `requestID` - a integer, request ID for this transaction
    `value` - a integer, value field for this transaction
    `buffer` - a byte[], buffer for data portion of transaction, or null if no data needs to be sent or received
    `timeout` - a integer
  Returns:
    length of data transferred (or zero) for success, or negative value for failure.
  Throws:
    `java.io.IOException`

### initialize

    public static boolean initialize(java.lang.Object usbConnection,
                                     java.lang.Object readEndPoint)

  Invokes the method `android.hardware.usb.UsbRequest#initialize`.

  Parameters:
    `usbConnection` - `android.hardware.usb.UsbDeviceConnection` a object
    `usbEndpoint` - a`android.hardware.usb.UsbEndpoint` object
  Returns:
    true if the request was successfully opened. Initializes the request so it can read or write data on the given endpoint.

### readBufferqueue

    public static java.nio.ByteBuffer readBufferqueue(java.nio.ByteBuffer buffer,
                                                      int length)
                                               throws java.io.IOException

  Invokes the method `android.hardware.usb.UsbRequest#queue`.

  Parameters:
    `buffer` - a ByteBuffer, containing the bytes to write, or location to store the results of a read
    `length` - a integer, number of bytes to read or write
  Returns:
    true if the queueing operation succeeded
  Throws:
    `java.io.IOException`

### requestWait

    public static java.lang.Object requestWait(java.lang.Object usbConnection)
                                        throws java.io.IOException

  Throws:
    `java.io.IOException`

### setClientData

    public static java.lang.Object setClientData()
                                          throws java.io.IOException

  Throws:
    `java.io.IOException`

### closeConnection

    public static void closeConnection(java.lang.Object usbConnection)

  Invokes the method `android.hardware.usb.UsbDeviceConnection#close`. Releases all system resources related to the device.