Discussion Board

Results 1 to 4 of 4

Threaded View

  1. #1
    Registered User
    Join Date
    Mar 2010

    Question (java) error: Reading external Card with NFC ACR122...


    I'm playing around with java, NFC ACR122 reader and the nokia 6131. I found an online sample code to read a MiFare card with java + the reader, so I don't use the nokia yet. Too bad it doesn't work for me! I used the "ReaderApplication" sample code from http://wiki.forum.nokia.com/index.ph..._Code_Examples

    package at.nfcresearch.wima.examples;
    import javax.smartcardio.*;
    import java.util.List;
    import java.util.ListIterator;
    public class Main {
        private static byte[] SELECT = {(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x09, (byte) 0x74, (byte) 0x69, (byte) 0x63, (byte) 0x6B, (byte) 0x65, (byte) 0x74, (byte) 0x69, (byte) 0x6E, (byte) 0x67, (byte) 0x00};
        private static byte[] INS_INC = {(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00};
        private static byte[] INS_DEC = {(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00};
        private static byte[] INS_READ = {(byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x01};
        private static CommandAPDU SELECT_APDU = new CommandAPDU(SELECT);
        private static CommandAPDU INC_APDU = new CommandAPDU(INS_INC);
        private static CommandAPDU DEC_APDU = new CommandAPDU(INS_DEC);
        private static CommandAPDU READ_APDU = new CommandAPDU(INS_READ);
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            TerminalFactory tf = TerminalFactory.getDefault();
            CardTerminals ct = tf.terminals();
            List<CardTerminal> l = null;
            Card card = null;
            try {
                l = ct.list();
            } catch (Exception e) {
                System.out.println("Error listing Terminals: " + e.toString());
            System.out.println("List of PC/SC Readers connected:");
            ListIterator i = l.listIterator();
            while (i.hasNext()) {
                System.out.println("Reader: " + ((CardTerminal) i.next()).getName());
            // IMPORTANT: change this to the PC/SC Name of your reader!!
            CardTerminal c = ct.getTerminal("ACS ACR122 0");
            System.out.println("Terminal fetched");
            try {
                while (c.isCardPresent()) {
                    try {
                    } catch (Exception e) {
                        System.out.print(("Error Sleep"));
                    try {
                        card = c.connect("T=0");
                        System.out.println("Terminal connected");
                    } catch (Exception e) {
                        System.out.println("Terminal NOT onnected: " + e.toString());
                    System.out.println("ATR: " + arrayToHex(((ATR) card.getATR()).getBytes()));
                    CardChannel ch = card.getBasicChannel();
                    byte[] x = null;
                    if (check9000(ch.transmit(SELECT_APDU))) {
                        System.out.println("SELECT OKAY");
                    } else {
                        System.out.println("SELECT NOT OKAY");
                    ResponseAPDU ra = ch.transmit(READ_APDU);
                    if (check9000(ra)) {
                        System.out.println("Value: " + ra.getBytes()[0]);
                    } else {
                        System.out.println("Error Reading Value");
                }// while
            }// try
            catch (CardException e) {
                System.out.println("Error isCardPresent()" + e.toString());
        public static boolean check9000(ResponseAPDU ra) {
            byte[] response = ra.getBytes();
            return (response[response.length - 2] == (byte) 0x90 && response[response.length - 1] == (byte) 0x00);
        public static String arrayToHex(byte[] data) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < data.length; i++) {
                String bs = Integer.toHexString(data[i] & 0xFF);
                if (bs.length() == 1) {
            return sb.toString();
    I've been trying for hours to get it to work now. Googled around, but found no solution for the following output when I build the file:

    List of PC/SC Readers connected:
    Reader: ACS ACR122 0
    Terminal fetched: ACS ACR122 0
    Terminal connected
    ATR: 3b00
    Error isCardPresent()javax.smartcardio.CardException: sun.security.smartcardio.PCSCException: Unknown error 0x6f7
    BUILD SUCCESSFUL (total time: 3 seconds)
    Looks like it finds the reader but the error (unknown error) doesn't tell me what the problem is...
    When I start commenting and replacing pieces of code, it looks like the error is triggered when the following code is executed:

    if (check9000(ch.transmit(SELECT_APDU))) {
          System.out.println("SELECT OKAY");
    } else {
          System.out.println("SELECT NOT OKAY");
    I think it has something to do with the transmit part...

    How do I fix this?


    Last edited by Astar; 2010-03-10 at 23:23.

Similar Threads

  1. Card Emulation - Nokia 6131 NFC
    By sharmashashi17 in forum Near Field Communication
    Replies: 2
    Last Post: 2009-10-23, 13:10
  2. series 40, "tag cannot be used" problem with OMNIKEY external reader and card
    By a_whitecloud in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2009-03-23, 10:23
  3. External Mifare keys changed after write data from Nokia 6131 NFC
    By guillem.puey in forum Near Field Communication
    Replies: 2
    Last Post: 2009-02-13, 13:10
  4. Read an external MiFare card - using MFStandardConnection
    By zinxed in forum Near Field Communication
    Replies: 0
    Last Post: 2007-08-10, 10:35
  5. Problem MMC+USB Connection
    By Fede81 in forum General Development Questions
    Replies: 3
    Last Post: 2006-07-19, 15:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts