public class MyCardProxy extends AppletProxy { // My APDU definitions. final static byte MyAPPLET_CLA = (byte)0x80; final static byte VERIFY_INS = (byte)0x20; final static byte GET_BALANCE_INS = (byte) 0x30; final static short GET_BALANCE_RESPONSE_SZ = 2; protected final static int OK = 0x9000; final static short SW_PINVERIFY_FAILED = (short)0x6900; /** * Reusable command APDU for getting an information * entry field. */ private CommandAPDU getBalanceAPDU = new CommandAPDU(14); ... /** Application identifier of the BusinessCard applet */ private static final ApplicationID MY_CARD_AID = new ApplicationID(new byte[] { (byte)0xD4, (byte)0x55, (byte)0x00, (byte)0x00, (byte)0x22, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xFF}); /** * Create a MyCardProxy instance. * * @param scheduler The Scheduler from which channels * have to be obtained. * @param card The SmartCard object to which this * service belongs. * @param blocking Currently not used. * * @throws opencard.core.service.CardServiceException * Thrown when instantiation fails. */ protected void initialize(CardServiceScheduler scheduler, SmartCard card, boolean blocking) throws CardServiceException { super.initialize(MY_CARD_AID, scheduler, card, blocking); try { // Allocate the card channel. This gives us // exclusive access to the card until we release the // channel. allocateCardChannel(); // Get the Card State. ... } finally { releaseCardChannel(); } } /** * Gets the balance. * @return The balance. */ public String getBalance() throws CardServiceInvalidCredentialException, CardServiceOperationFailedException, CardServiceInvalidParameterException, CardServiceUnexpectedResponseException, CardServiceException, CardTerminalException { try { allocateCardChannel(); // Set up the command APDU and send it to the card. getBalanceAPDU.setLength(0); getBalanceAPDU.append(MyAPPLET_CLA); // Class getBalanceAPDU.append(GET_BALANCE_INS); // Instr'n getBalanceAPDU.append((byte) 0x00); // P1 getBalanceAPDU.append((byte) 0x00); // P2 getBalanceAPDU.append((byte) 0x00); // Lc getBalanceAPDU.append((byte) 0x00); // Le // Send command APDU and check the response. ResponseAPDU response = sendCommandAPDU(getCardChannel(), MY_CARD_AID, getBalanceAPDU); switch (response.sw() & 0xFFFF) { case OK : return new String(response.data()); default : throw new CardServiceUnexpectedResponseException ("RC=" + response.sw()); } } finally { releaseCardChannel(); } } ... }