## amlib.ccid
Class Reader

    java.lang.Object
      amlib.ccid.Reader

Direct Known Subclasses:
  Reader4428, Reader4442

    public class Reader

extends java.lang.Object

Field Summary
`static byte` `CardModeASYNC`
`static byte` `CardModeSLE4428`
`static byte` `CardModeSLE4442`
`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
`Reader(HardwareInterface Dev)` Constructor
`Reader(HardwareInterface Dev, byte slot)` Constructor with given slot number

Method Summary
`int` `close()` To close communication with ICC.
`int` `connect()` To connect to ICC.
`void` `destroy()` To clean held member in Reader. class members will be reset to null
`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` `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

### CardModeSLE4428

    public static final byte CardModeSLE4428

See Also:
  Constant Field Values

### CardModeSLE4442

    public static final byte CardModeSLE4442

See Also:
  Constant Field Values

Constructor Detail

### Reader

    public Reader(HardwareInterface Dev)
           throws java.lang.IllegalArgumentException

  Constructor

  Parameters:
    `Dev` - HardwareInterface object which has been initialed
  Throws:
    `java.lang.IllegalArgumentException`
  See Also:
    `HardwareInterface`

### Reader

    public Reader(HardwareInterface Dev,
                  byte slot)
           throws java.lang.IllegalArgumentException

  Constructor with given slot number

  Parameters:
    `Dev` -
    `slot` -
  Throws:
    `java.lang.IllegalArgumentException`
  See Also:
    `HardwareInterface`

Method Detail

### setSlot

    public void setSlot(byte slot)

  To set the slot number of Reader

  Parameters:
    `slot` - slot number to manipulate.

### connect

    public int connect()

  To connect to ICC. Calls this method before communication with ICC.

  Returns:
    READER_SUCCESSFUL or other error code
  See Also:
    `Error`

### 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:
    `Error`

### close

    public int close()

  To close communication with ICC. After this method is used, uses connect() before resuming the communication.
  This method will power off the ICC

  Returns:
    READER_SUCCESSFUL or other error code
  See Also:
    `Error`

### destroy

    public void destroy()

  To clean held member in Reader. class members will be reset to null

### 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:
    `Error`

### 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:
    `Error`

### 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:
    `Error`

### 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:
    `Error`

### 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:
    `Error`

### 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:
    `Error`