amlib.ccid

## Class Reader

- java.lang.Object
- - amlib.ccid.Reader

- Direct Known Subclasses:
    Reader4428, Reader4442, Reader6636, ReaderAT24C, ReaderAT45D041, ReaderAT88SC102, ReaderAT88SC153, ReaderAT88SC1608

      public class Reader
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static byte` | `CardModeASYNC`
    `static byte` | `CardModeAT45D041`
    `static byte` | `CardModeAT88SC102`
    `static byte` | `CardModeAT88SC153`
    `static byte` | `CardModeAT88SC1608`
    `static byte` | `CardModeI2C`
    `static byte` | `CardModeINPHONE`
    `static byte` | `CardModeSLE4428`
    `static byte` | `CardModeSLE4442`
    `static byte` | `CardModeSLE6636`
    `static int` | `CCID_POWEROFF`
    `static int` | `CCID_POWERON`
    `static byte` | `CCID_PROTOCOL_NA`
    `static byte` | `CCID_PROTOCOL_T0`
    `static byte` | `CCID_PROTOCOL_T1`
    `static byte` | `SLOT_STATUS_CARD_ABSENT`
    `static byte` | `SLOT_STATUS_CARD_ACTIVE`
    `static byte` | `SLOT_STATUS_CARD_INACTIVE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Reader(HardwareInterface Dev)` Constructor
    `Reader(HardwareInterface Dev, byte slot)` Constructor with given slot number

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `close()` To close communication with ICC.
    `int` | `escape(byte[] pTxBuf, int txLen, byte[] pRxBuf, int[] pRxLen)` Send Escape command to ICC
    `byte[]` | `getAtr()` Gets the ATR bytes in hex
    `java.lang.String` | `getAtrString()` Gets the ATR string.
    `int` | `getCardStatus(byte[] pStatus)` Gets Card Status
    `int` | `getCmdFailCode()` To get the CCID slot error and slot status registers of last CCID command
    `HardwareInterface` | `getCurrentDev()` To get the current HardwareInterface instance nested in class Reader
    `int` | `getProtocol(byte[] pProtocol)` To get the active protocol.
    `int` | `getSN(byte[] pSN, byte[] pSNLength)` To get Serial Number.
    `int` | `open()` To open the reader.
    `int` | `open(int slot)` Deprecated. Please use setSlot(slot) and then open()
    `int` | `setPower(int power)` To set Card Power
    `void` | `setSlot(byte slot)` To set the slot number of Reader
    `int` | `switchMode(byte mode)` To switch to different card mode
    `int` | `transmit(byte[] pTxBuf, int txLen, byte[] pRxBuf, int[] pRxLen)` Transmits APDU

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

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

- - ### Field Detail

    - #### CCID_POWERON

          public static final int CCID_POWERON

      See Also:
        Constant Field Values

    - #### CCID_POWEROFF

          public static final int CCID_POWEROFF

      See Also:
        Constant Field Values

    - #### SLOT_STATUS_CARD_ACTIVE

          public static final byte SLOT_STATUS_CARD_ACTIVE

      See Also:
        Constant Field Values

    - #### SLOT_STATUS_CARD_INACTIVE

          public static final byte SLOT_STATUS_CARD_INACTIVE

      See Also:
        Constant Field Values

    - #### SLOT_STATUS_CARD_ABSENT

          public static final byte SLOT_STATUS_CARD_ABSENT

      See Also:
        Constant Field Values

    - #### CCID_PROTOCOL_T0

          public static final byte CCID_PROTOCOL_T0

      See Also:
        Constant Field Values

    - #### CCID_PROTOCOL_T1

          public static final byte CCID_PROTOCOL_T1

      See Also:
        Constant Field Values

    - #### CCID_PROTOCOL_NA

          public static final byte CCID_PROTOCOL_NA

      See Also:
        Constant Field Values

    - #### CardModeASYNC

          public static final byte CardModeASYNC

      See Also:
        Constant Field Values

    - #### CardModeI2C

          public static final byte CardModeI2C

      See Also:
        Constant Field Values

    - #### CardModeSLE4428

          public static final byte CardModeSLE4428

      See Also:
        Constant Field Values

    - #### CardModeSLE4442

          public static final byte CardModeSLE4442

      See Also:
        Constant Field Values

    - #### CardModeAT88SC1608

          public static final byte CardModeAT88SC1608

      See Also:
        Constant Field Values

    - #### CardModeINPHONE

          public static final byte CardModeINPHONE

      See Also:
        Constant Field Values

    - #### CardModeAT45D041

          public static final byte CardModeAT45D041

      See Also:
        Constant Field Values

    - #### CardModeSLE6636

          public static final byte CardModeSLE6636

      See Also:
        Constant Field Values

    - #### CardModeAT88SC102

          public static final byte CardModeAT88SC102

      See Also:
        Constant Field Values

    - #### CardModeAT88SC153

          public static final byte CardModeAT88SC153

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Reader

          public Reader(HardwareInterface Dev)
                 throws ReaderException

      Constructor
      Parameters:
        `Dev` - HardwareInterface object which has been initialed
      Throws:
        `ReaderException`
      See Also:
        `HardwareInterface`

    - #### Reader

          public Reader(HardwareInterface Dev,
                        byte slot)
                 throws ReaderException

      Constructor with given slot number
      Parameters:
        `Dev` - HardwareInterface object which has been initialed
        `slot` - The slot number of this reader you want to communicate with.
      Throws:
        `ReaderException`
      See Also:
        `HardwareInterface`

  - ### Method Detail

    - #### close

          public int close()

      To close communication with ICC. After this method is used, uses open() before resuming the communication.
      This method will power off the ICC
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### escape

          public int escape(byte[] pTxBuf,
                            int txLen,
                            byte[] pRxBuf,
                            int[] pRxLen)

      Send Escape command to ICC
      Parameters:
        `pTxBuf` - The data block sent to the ICC. ( abData field in command PC_to_RDR_Escape 0x6b)
        `txLen` - The length of pTxBuf
        `pRxBuf` - The adData field in received packet. Refer to RDR_to_PC_Escape in ICC spec
        `pRxLen` - One byte array to specify received data length in pRxBuf
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### getAtr

          public byte[] getAtr()

      Gets the ATR bytes in hex
      Returns:
        ATR bytes array

    - #### getAtrString

          public java.lang.String getAtrString()

      Gets the ATR string.
      Returns:
        ATR String

    - #### getCardStatus

          public int getCardStatus(byte[] pStatus)

      Gets Card Status
      Parameters:
        `pStatus` - One byte array to get Card status.
        pStatus[0] could be SLOT_STATUS_CARD_ACTIVE, SLOT_STATUS_CARD_INACTIVE
        or SLOT_STATUS_CARD_ABSENT.
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### getCmdFailCode

          public int getCmdFailCode()

      To get the CCID slot error and slot status registers of last CCID command
      Returns:
        0x0000EESS where EE is bError and SS is bStatus. Refer to CCID spec. 6.2.6

    - #### getCurrentDev

          public HardwareInterface getCurrentDev()

      To get the current HardwareInterface instance nested in class Reader
      Returns:
        class HardwareInterface
      See Also:
        `HardwareInterface`

    - #### getProtocol

          public int getProtocol(byte[] pProtocol)

      To get the active protocol.
      Parameters:
        `pProtocol` - one byte array. Its value could be CCID_PROTOCOL_T0, CCID_PROTOCOL_T1 or CCID_PROTOCOL_NA
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### getSN

          public int getSN(byte[] pSN,
                           byte[] pSNLength)

      To get Serial Number.
      Parameters:
        `pSN` - bytes array to store serial number.
        `pSNLength` - one byte array to indicate length of serial number. when method returns, it denotes the actual length of serial number.
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### open

          public int open(int slot)

      Deprecated. Please use setSlot(slot) and then open()
      To open reader with given slot
      Parameters:
        `slot` - slot number to open
      Returns:
        READER_SUCCESSFUL or other error code

    - #### open

          public int open()

      To open the reader.
      Returns:
        READER_SUCCESSFUL or other error code

    - #### setPower

          public int setPower(int power)

      To set Card Power
      Parameters:
        `power` - CCID_POWERON or CCID_POWEROFF
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### setSlot

          public void setSlot(byte slot)

      To set the slot number of Reader
      Parameters:
        `slot` - slot number to manipulate.

    - #### switchMode

          public int switchMode(byte mode)

      To switch to different card mode
      Parameters:
        `mode` - mode to switch
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`

    - #### transmit

          public int transmit(byte[] pTxBuf,
                              int txLen,
                              byte[] pRxBuf,
                              int[] pRxLen)

      Transmits APDU
      Parameters:
        `pTxBuf` - The data block to sent to the ICC. ( abData field in command PC_to_RDR_XfrBlock 0x6F)
        `txLen` - The length of pTxBuf
        `pRxBuf` - The adData field in received packet. Refer to RDR_to_PC_DataBlock in ICC spec.
        `pRxLen` - One byte array to specify received data length in pRxBuf
      Returns:
        READER_SUCCESSFUL or other error code
      See Also:
        `SCError`