amlib.hw

## Class HardwareInterface

- java.lang.Object
- - amlib.hw.HardwareInterface

-     public class HardwareInterface
      extends java.lang.Object

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HardwareInterface(HWType Type, android.content.Context ctx)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `Close()` To close hardware interface
    `HWType` | `getHWType()` To get the Hardware type
    `int` | `getMaxRxPkLength()` To get maximum data length for each Rx packet.
    `int` | `getMaxTxPkLength()` To get maximum data length for each Tx packet.
    `java.lang.Object` | `getmDevObj()` To get the casted hardware interface instance (UsbDevice for instance)which has been stored
    `boolean` | `getSerialNumber(byte[] pBuff, byte[] Len)` Get Serial Number of Reader internally.
    `boolean` | `Init(android.hardware.usb.UsbManager Manager, android.hardware.usb.UsbDevice Device)` To initial the hardware for communication
    `boolean` | `initNFC(android.hardware.usb.UsbManager Manager, android.hardware.usb.UsbDevice Device)` To initial the hardware for communication if you are using the NFC function.
    `boolean` | `IsDevSet()` Simply return flag to check is this class is ready
    `int` | `Rx(byte[] pBuff, int[] Len)` To receive data from hardware interface
    `void` | `setAppContext(android.content.Context ctx)`
    `int` | `Tx(byte[] pBuff, int Len)` To transfer data to hardware interface
    `boolean` | `usbCtrl(byte[] pBuf, int requestType, int request, int value, int index, int[] pLength)` To get an specific Usb descriptor
    `boolean` | `usbResetDevice()` To send a reset request to USB device.

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

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

- - ### Constructor Detail

    - #### HardwareInterface

          public HardwareInterface(HWType Type,
                                   android.content.Context ctx)

      Constructor
      Parameters:
        `Type` - Type of hardware, eUSB is the only option currently.
        `ctx` - Context of application.
      See Also:
        `HWType`

  - ### Method Detail

    - #### Init

          public boolean Init(android.hardware.usb.UsbManager Manager,
                              android.hardware.usb.UsbDevice Device)
                       throws amlib.hw.ReaderHwException

      To initial the hardware for communication
      Parameters:
        `Manager` - UsbManager
        `Device` - UsbDevice which smart card belong to
      Returns:
        true for successful.
      Throws:
        `amlib.hw.ReaderHwException`
      See Also:
        `UsbManager`, `UsbDevice`

    - #### initNFC

          public boolean initNFC(android.hardware.usb.UsbManager Manager,
                                 android.hardware.usb.UsbDevice Device)
                          throws amlib.hw.ReaderHwException

      To initial the hardware for communication if you are using the NFC function.
      Parameters:
        `Manager` - UsbManager
        `Device` - UsbDevice which smart card belong to
      Returns:
        true for successful.
      Throws:
        `amlib.hw.ReaderHwException`
      See Also:
        `UsbManager`, `UsbDevice`

    - #### Close

          public boolean Close()

      To close hardware interface
      Returns:
        true for successful.

    - #### Tx

          public int Tx(byte[] pBuff,
                        int Len)

      To transfer data to hardware interface
      Parameters:
        `pBuff` - data to transfer, the length of pBuffer is specified in parameter 'Len'
        `Len` - length of data to transfer
      Returns:
        READER_SUCCESSFUL or other error code

    - #### Rx

          public int Rx(byte[] pBuff,
                        int[] Len)

      To receive data from hardware interface
      Parameters:
        `pBuff` - data to receive. Be aware that providing a buffer with enough size.
        `Len` - length of received data
      Returns:
        READER_SUCCESSFUL or other error code

    - #### getSerialNumber

          public boolean getSerialNumber(byte[] pBuff,
                                         byte[] Len)

      Get Serial Number of Reader internally.
      Parameters:
        `pBuff` - byte array to get serial number
        `Len` - length of received data
      Returns:
        true for success.

    - #### usbCtrl

          public boolean usbCtrl(byte[] pBuf,
                                 int requestType,
                                 int request,
                                 int value,
                                 int index,
                                 int[] pLength)

      To get an specific Usb descriptor
      Parameters:
        `pBuf` - byte array to receive descriptor. Be aware that providing a buffer with enough size
        `requestType` - request type for this transaction.
        `request` - request ID for this transaction.
        `value` - value field for this transaction.
        `index` - index field for this transaction.
        `pLength` - one element array to indicate transfer length.
      Returns:
        true for success.

    - #### usbResetDevice

          public boolean usbResetDevice()
                                 throws amlib.hw.ReaderHwException

      To send a reset request to USB device.
      Returns:
        true for successful.
      Throws:
        `amlib.hw.ReaderHwException`

    - #### getmDevObj

          public java.lang.Object getmDevObj()

      To get the casted hardware interface instance (UsbDevice for instance)which has been stored
      Returns:
        Object
      See Also:
        `Object`

    - #### setAppContext

          public void setAppContext(android.content.Context ctx)

    - #### IsDevSet

          public boolean IsDevSet()

      Simply return flag to check is this class is ready
      Returns:
        true if device is set.

    - #### getHWType

          public HWType getHWType()

      To get the Hardware type
      Returns:
        HWType
      See Also:
        `HWType`

    - #### getMaxTxPkLength

          public int getMaxTxPkLength()

      To get maximum data length for each Tx packet.
      Returns:
        length of maximum data length for each Tx packet.

    - #### getMaxRxPkLength

          public int getMaxRxPkLength()

      To get maximum data length for each Rx packet.
      Returns:
        length of maximum data length for each Rx packet.