ACS Reader Integration with Java

How do you use an ACS reader from Java? Use javax.smartcardio, the smart card API that ships with the JDK (module java.smartcardio), so there is nothing to download. TerminalFactory.getDefault() gives you the PC/SC readers, terminals().list() lists them, waitForCardPresent() waits for a card, connect("*") opens it, getATR() identifies it, and transmit() sends commands such as FF CA 00 00 00 for the card UID. Reader-only commands, such as the ACS firmware version escape command, go through transmitControlCommand(). On Windows the JDK calls the same winscard.dll as a C# program, so everything you know from the C# PC/SC series still applies.

This guide gives a complete, read-only Java program for ACS readers such as the ACR1252U, ACR1552U and ACR122U: it lists readers, waits for a card, prints the ATR and the UID, and reads the reader's firmware version. It then covers the two things that trip Java developers up most: the escape command control code, which is a different number on Windows and Linux, and the Linux library setting.

Compiled by BSD; not yet tested on a reader. BSD compiled the program on 1 Dec 2026 with JDK 17.0.10 and javac -Xlint:all (with and without --release 11): 0 warnings, 0 errors. It was run on a Windows 11 PC without an ACS reader, where it listed the one virtual reader it found and stopped with "No reader whose name contains "PICC"". Runs with ACS readers and cards are still to be done; the replies shown below come from the ACS manuals, not from BSD's readers.

javax.smartcardio is the Java Smart Card I/O API from JSR 268, part of the JDK since Java 6. Oracle describes the JDK's provider for it, SunPCSC, as a bridge to the operating system's PC/SC stack: on Windows it always calls winscard.dll, and on Linux it loads libpcsclite.so. That means a Java program sits in the same place as any other PC/SC application in the PC/SC layer model: above the Smart Card service (or pcscd on Linux), the reader driver and the reader. Install the ACS driver first, as for any other program (installing ACS drivers on Windows).

The API has a handful of classes. The right-hand column is the PC/SC function that does the same job, so you can match Java code against the WinSCard call sequence. Oracle's documentation describes only the Java behaviour, not which PC/SC call the provider makes internally.

Jobjavax.smartcardioPC/SC function with the same job
Open the PC/SC layerTerminalFactory.getDefault()SCardEstablishContext
List readersfactory.terminals().list() returns List<CardTerminal>; getName() gives each reader nameSCardListReaders
Wait for a cardCardTerminal.waitForCardPresent(ms), or CardTerminals.waitForChange() for several readersSCardGetStatusChange
ConnectCardTerminal.connect("*") returns a CardSCardConnect
ATRCard.getATR(), then getBytes() or getHistoricalBytes()SCardStatus / reader state
Send an APDUcard.getBasicChannel().transmit(new CommandAPDU(...)) returns a ResponseAPDU (getData(), getSW())SCardTransmit
Send a reader commandCard.transmitControlCommand(code, bytes)SCardControl
Keep other threads outCard.beginExclusive() / endExclusive()SCardBeginTransaction / SCardEndTransaction
DisconnectCard.disconnect(false) (false = do not reset the card)SCardDisconnect with SCARD_LEAVE_CARD

ACS's own SDK kits for the ACR1252U and ACR1552U include Java sample code among their PC/SC samples. The program on this page is BSD's own, written against Oracle's documentation, and needs no ACS library.

  1. Get the factory. TerminalFactory.getDefault() always returns a factory, but Oracle notes that it may offer no terminals. Print factory.getType(): PC/SC means the PC/SC stack was found. If PC/SC is missing or not configured, Oracle says getDefault() returns a built-in implementation that supports no terminals. On Linux that is usually the library path problem described under pitfalls.
  2. List the readers and pick one by name. terminals().list() returns every reader, including a laptop's built-in reader or a Windows Hello virtual smart card. Pick the ACS reader by a part of its name, never by position: the contactless interface of a dual reader has PICC in its name, and its SAM slot is a separate entry. The naming rules are on detecting an ACS reader and apply to Java unchanged.
  3. Wait for a card. waitForCardPresent(30000) returns true as soon as a card is present (straight away if one is already there) and false when the 30 seconds run out. A timeout of 0 waits for ever; a negative value throws IllegalArgumentException. For a tap-to-read loop, follow it with waitForCardAbsent() so the same card is not read twice, the same idea as the C# read loop.
  4. Connect with "*". Oracle documents the protocol argument as "T=0", "T=1" or "T=CL", or "*" for any available protocol. Use "*": ACS contactless readers present the card through PC/SC, and the protocol in use is the one card.getProtocol() then reports. If no card is present you get CardNotPresentException.
  5. Read the ATR. card.getATR().getBytes() is the full ATR. For contactless cards the ACS reader builds a PC/SC "pseudo-ATR" whose bytes name the card type, for example 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A for MIFARE Classic 1K in the ACS manuals. Decoding the contactless ATR shows how to read it.
  6. Ask for the UID. Send FF CA 00 00 00 on the basic channel. The reply is the UID followed by 90 00; 63 00 means the command failed (often the card moved), and 6A 81 means it is not supported for that card or mode. Only send it to a PICC reader: contact cards in an ACR39U have no UID, and their ATR is what identifies them (why contact cards have no UID).
  7. Disconnect. card.disconnect(false) leaves the card powered as it is. Do it in a finally block so a failed command never leaves the connection open.

The APDU rules behind steps 5 and 6 (class byte FF commands answered by the reader, status words, Le) are explained in how to send APDU commands.

Language: Java 11 or later, one source file, no external libraries. Prerequisites: a JDK (BSD used JDK 17); an ACS reader with the ACS driver installed; on Windows the Smart Card service running (how to check it); a test card such as MIFARE Classic 1K, NTAG or DESFire for the UID. On Linux, pcscd must be running and the JDK must find libpcsclite (see pitfalls).

The program is read-only. It sends Get Data (FF CA 00 00 00) to a PICC reader and the documented Get Firmware Version command for the ACR1252U, ACR1552U or ACR122U, and nothing else. It reads no card memory, loads no keys and changes no reader setting.

AcsReaderJava.java

// Day 47: read the ATR, the card UID and the reader firmware version from an ACS reader
// with javax.smartcardio (Java 11 or later; module java.smartcardio). Read-only.
// Compiled by BSD; not yet tested on a reader.
//
// Build: javac -Xlint:all -d out AcsReaderJava.java
// Run:   java -cp out AcsReaderJava            (first reader whose name contains "PICC")
//        java -cp out AcsReaderJava ACR1552    (first reader whose name contains "ACR1552")

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.smartcardio.ATR;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.TerminalFactory;

public final class AcsReaderJava {

    // PC/SC Get Data: ask the reader for the UID of the contactless card.
    private static final byte[] GET_UID = {(byte) 0xFF, (byte) 0xCA, 0x00, 0x00, 0x00};
    // ACR1252U / ACR1552U escape command: Get Firmware Version (sent with SCardControl).
    private static final byte[] ESCAPE_GET_FIRMWARE = {(byte) 0xE0, 0x00, 0x00, 0x18, 0x00};
    // ACR122U pseudo-APDU: Get Firmware Version (sent like a card command).
    private static final byte[] ACR122U_GET_FIRMWARE = {(byte) 0xFF, 0x00, 0x48, 0x00, 0x00};

    private static final long CARD_WAIT_MS = 30_000;

    private AcsReaderJava() {
    }

    public static void main(String[] args) {
        String filter = args.length > 0 ? args[0] : "PICC";
        System.exit(run(filter));
    }

    private static int run(String filter) {
        TerminalFactory factory = TerminalFactory.getDefault();
        System.out.println("TerminalFactory type: " + factory.getType());

        List<CardTerminal> terminals;
        try {
            terminals = factory.terminals().list();
        } catch (CardException e) {
            // On Windows this is also what you see when no reader is plugged in.
            System.out.println("Could not list readers: " + describe(e));
            return 1;
        }

        CardTerminal chosen = null;
        for (CardTerminal t : terminals) {
            System.out.println("Reader: " + t.getName());
            if (chosen == null && t.getName().toUpperCase(Locale.ROOT).contains(filter.toUpperCase(Locale.ROOT))) {
                chosen = t;
            }
        }
        if (chosen == null) {
            System.out.println("No reader whose name contains \"" + filter + "\".");
            return 1;
        }
        String name = chosen.getName();
        System.out.println("Using: " + name);

        try {
            System.out.println("Place a card on the reader (waiting up to " + CARD_WAIT_MS / 1000 + " s)...");
            if (!chosen.waitForCardPresent(CARD_WAIT_MS)) {
                System.out.println("No card arrived in time.");
                return 2;
            }

            Card card = chosen.connect("*");
            try {
                System.out.println("Protocol: " + card.getProtocol());
                ATR atr = card.getATR();
                System.out.println("ATR: " + hex(atr.getBytes()));
                System.out.println("Historical bytes: " + hex(atr.getHistoricalBytes()));

                card.beginExclusive();
                try {
                    readUid(card, name);
                    readFirmware(card, name);
                } finally {
                    card.endExclusive();
                }
            } finally {
                card.disconnect(false); // false = leave the card as it is
            }
            return 0;
        } catch (CardException e) {
            System.out.println("Card error: " + describe(e));
            return 3;
        }
    }

    private static void readUid(Card card, String name) throws CardException {
        if (!name.toUpperCase(Locale.ROOT).contains("PICC")) {
            // Contact cards (for example in an ACR39U) have no UID: the ATR above is what identifies them.
            System.out.println("Not a PICC (contactless) reader: Get Data not sent.");
            return;
        }
        CardChannel channel = card.getBasicChannel();
        ResponseAPDU r = channel.transmit(new CommandAPDU(GET_UID));
        if (r.getSW() == 0x9000) {
            System.out.println("UID: " + hex(r.getData()) + "  (SW 90 00)");
        } else {
            // 63 00 = the command failed; 6A 81 = not supported for this card or mode.
            System.out.printf("Get Data refused: SW %04X%n", r.getSW());
        }
    }

    private static void readFirmware(Card card, String name) throws CardException {
        String upper = name.toUpperCase(Locale.ROOT);
        if (upper.contains("ACR122")) {
            // The ACR122U answers with version text only, no status word, so use the raw bytes.
            ResponseAPDU r = card.getBasicChannel().transmit(new CommandAPDU(ACR122U_GET_FIRMWARE));
            byte[] raw = r.getBytes();
            System.out.println("Firmware reply: " + hex(raw) + "  = \"" + ascii(raw) + "\"");
        } else if (upper.contains("ACR1252") || upper.contains("ACR1552")) {
            int code = escapeControlCode();
            System.out.printf("Escape control code: 0x%X%n", code);
            byte[] reply = card.transmitControlCommand(code, ESCAPE_GET_FIRMWARE);
            System.out.println("Firmware reply: " + hex(reply));
            // Documented layout: E1 00 00 00, one length byte, then the version text.
            if (reply.length >= 5 && (reply[0] & 0xFF) == 0xE1) {
                int len = Math.min(reply[4] & 0xFF, reply.length - 5);
                System.out.println("Firmware: " + ascii(Arrays.copyOfRange(reply, 5, 5 + len)));
            }
        } else {
            System.out.println("No firmware command for this reader in this sample.");
        }
    }

    // SCARD_CTL_CODE(3500): ACS writes the Windows value as 0x310000 + 3500 * 4.
    // pcsc-lite (Linux, macOS) defines SCARD_CTL_CODE(code) as 0x42000000 + code.
    // Whether the escape command reaches the reader also depends on the driver.
    private static int escapeControlCode() {
        String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
        return os.startsWith("windows") ? 0x310000 + 3500 * 4 : 0x42000000 + 3500;
    }

    private static String describe(CardException e) {
        Throwable cause = e.getCause();
        return cause == null ? e.getMessage() : e.getMessage() + " (" + cause.getMessage() + ")";
    }

    private static String hex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            if (sb.length() > 0) {
                sb.append(' ');
            }
            sb.append(String.format("%02X", b & 0xFF));
        }
        return sb.toString();
    }

    private static String ascii(byte[] data) {
        return new String(data, StandardCharsets.US_ASCII);
    }
}

Build and run

javac -Xlint:all -d out AcsReaderJava.java
java -cp out AcsReaderJava              (first reader with "PICC" in its name)
java -cp out AcsReaderJava ACR1552      (first reader with "ACR1552" in its name)
java -cp out AcsReaderJava ACR39        (contact reader: prints the ATR only)

With Java 11 or later you can also skip javac and run the source file directly: java AcsReaderJava.java. If your project uses Java modules, add requires java.smartcardio; to module-info.java.

What the output should look like

An illustration, not a captured result: it uses the ACS manual's example ATR for MIFARE Classic 1K and its example ACR1252U firmware reply. Your UID, firmware version and possibly the reader name will differ.

TerminalFactory type: PC/SC
Reader: ACS ACR1252 1S CL Reader PICC 0
Reader: ACS ACR1252 1S CL Reader SAM 0
Using: ACS ACR1252 1S CL Reader PICC 0
Place a card on the reader (waiting up to 30 s)...
Protocol: T=1
ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
Historical bytes: 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00
UID: (your card's UID)  (SW 90 00)
Escape control code: 0x3136B0
Firmware reply: E1 00 00 00 0F 41 43 52 31 32 35 32 55 5F 56 31 30 30 2E 31
Firmware: ACR1252U_V100.1
Exit codeMeaning
0Card read; UID and firmware lines printed where the reader supports them
1Readers could not be listed, or no reader matched the name filter
2No card arrived within 30 seconds
3A CardException while connecting or sending (the message and its cause are printed)

Some ACS reader commands are not card commands at all. ACS documents Get Firmware Version on the ACR1252U and ACR1552U as an escape command, E0 00 00 18 00, sent with SCardControl and control code SCARD_CTL_CODE(3500). In Java that is Card.transmitControlCommand(int controlCode, byte[] command), which Oracle describes as transmitting a control command to the terminal device. The reply layout (E1 00 00 00, a length byte, then the version text) and each reader's command are on checking the ACS reader firmware version.

The catch is the number. Java passes your int straight on, and SCARD_CTL_CODE is a macro that each platform defines differently:

PlatformHow SCARD_CTL_CODE(3500) is definedValue
Windows (ACS driver)ACS's manuals write it as 0x310000 + 3500 * 40x3136B0
Linux and macOS (pcsc-lite)pcsc-lite's reader.h defines SCARD_CTL_CODE(code) as 0x42000000 + code0x42000DAC

The sample picks the value from the os.name system property. A hard-coded Windows number will not work on Linux, and the reverse. The number is only half of it: the driver must also pass escape commands on. On Windows that normally means the ACS driver rather than Microsoft's generic CCID driver. On Linux, the free CCID driver only allows vendor escape commands when an option is set in its configuration, as explained in PC/SC on Linux and macOS; with ACS's own Linux driver, follow ACS's documentation. BSD has not tested escape commands on Linux.

Two more points from the documentation:

  • A card must be connected. Oracle documents connect() only for T=0, T=1, T=CL and *, so the public API has no documented way to open the reader without a card (PC/SC's direct mode). The sample therefore sends the escape command while a card is on the reader, which is also how the ACS Script Tool method does it. To read the firmware with no card, use one of the no-code methods.
  • The ACR122U is different. Its Get Firmware Version, FF 00 48 00 00, is a pseudo-APDU sent with transmit(), and ACS shows the reply as 10 bytes of text with no status word. ResponseAPDU always treats the last two bytes as SW1 SW2, so the sample prints getBytes(), the whole reply, instead of getData().

Escape commands can also change reader settings, such as the LED and buzzer. Keep test code to the read-only Get Firmware Version until you have read the manual for every other command.

Linux: sun.security.smartcardio.library

According to Oracle's provider documentation, on Linux SunPCSC looks for libpcsclite.so in /usr/$LIBISA and /usr/local/$LIBISA ($LIBISA is lib64 on 64-bit Linux). Many distributions install the library somewhere else, so the JDK does not find it, getDefault() falls back to an implementation with no terminals, and your program sees no readers even though pcscd works. Oracle documents the fix: set the system property sun.security.smartcardio.library to the full file name of the library.

# find where your distribution put the library
ldconfig -p | grep libpcsclite
# then pass the full path that line shows
java -Dsun.security.smartcardio.library=/full/path/to/libpcsclite.so.1 -cp out AcsReaderJava

On Windows there is nothing to set: Oracle says SunPCSC always calls winscard.dll and no Java-level configuration is necessary or possible. BSD has not run the sample on Linux.

Exclusive access

  • Inside your program. beginExclusive() means only the calling thread may talk to the card until it calls endExclusive(); other threads get a CardException. Oracle tells applications to release it reliably with try ... finally, as the sample does. Calling beginExclusive() twice also throws.
  • Between programs. If QuickView, the Script Tool, a browser extension or a second copy of your program holds the card, connect() or transmit() fails with a CardException. Print its cause too: it can carry the underlying PC/SC error. Close the other program and try again. Share modes explains who may use a reader at the same time.
  • One connection per protocol. Oracle documents that connect() returns the same Card object if you connect again with the same protocol, and throws CardException if a connection with a different protocol already exists. Connect once, and disconnect before you change protocol.

Other things to know

  • With no reader at all, list() may throw a CardException rather than return an empty list. Handle both, as the sample does.
  • CardTerminals remembers card state between waitForChange() calls; Oracle recommends separate objects if independent threads wait for changes.
  • A Java program is still a PC/SC program: when the reader or service is the problem, check the PC/SC reader status before you change the code.
What you seeLikely causeWhat to do
TerminalFactory type: None, or no readers on LinuxThe JDK did not find libpcsclite, or pcscd is not runningSet sun.security.smartcardio.library as shown above and start pcscd.
"Could not list readers" on WindowsNo reader plugged in, or the Smart Card service is stoppedCheck the reader in Windows and the Smart Card service.
"No reader whose name contains "PICC""The reader name differs, or only a contact reader is connectedRun once to see the names printed, then pass part of the right one as the argument.
"Card error" with a sharing violation in the causeAnother program holds the cardClose QuickView, the Script Tool or the other program.
Get Data refused: SW 6A81Get Data not supported for this card or mode, or the SAM entry was chosenUse the PICC entry; see UID troubleshooting.
Get Data refused: SW 6300The command failed, usually because the card movedHold the card flat on the reader and run again.
transmitControlCommand throws on an ACR1252U or ACR1552UWrong control code for the platform, or a driver that does not pass escape commandsCheck the printed code (Windows 0x3136B0); use the ACS driver; see the firmware guide's troubleshooting.
ACR122U firmware text looks cut shortThe reply was read with getData(), which drops the last two bytesUse getBytes() for this reply, as the sample does.
IllegalStateException after a disconnectThe Card object was used after disconnect()Connect again for the next card; do not keep old Card objects.

BSD compiled this program but has not yet run it with an ACS reader. These read-only tests are planned on BSD's own readers and test cards, and this page will be updated with the real output:

  1. ACR1252U with a MIFARE Classic 1K card on Windows 11: the ATR, the UID and the firmware text through transmitControlCommand with code 0x3136B0.
  2. ACR1552U with an NTAG or DESFire card on Windows 11: the same three results.
  3. ACR122U on Windows 10: the firmware text from FF 00 48 00 00 with a card on the reader.
  4. ACR39U with an SLE memory card: the ATR only, with no Get Data sent.
  5. QuickView connected at the same time: the exception message and cause.

Linux runs, including the library property and the pcsc-lite control code, are not on BSD's test list yet.

Oracle's Java SE API documentation and JDK security guide were checked on 1 Dec 2026 for every class, method, argument and exception named on this page. ACS commands, replies and the control code formula come from the ACS manuals cited on the firmware version guide (ACR1252U API v1.17, ACR1552U reference manual v1.09, ACR122U API v2.04) and the example ATR from the ACS manuals cited on the ATR guide. The pcsc-lite control code definition was checked for the PC/SC architecture guide.

BSD Infotech is an independent ACS supplier and integrator, not the manufacturer. ACS, the ACS logo and ACS product names belong to Advanced Card Systems Ltd. Java and Oracle are trademarks of Oracle and/or its affiliates. MIFARE, MIFARE Classic, MIFARE DESFire, NTAG are trademarks of NXP B.V.

Integrating ACS readers with Java?

Tell us the reader, the cards and the system they must work with. We build and integrate smart card software for ACS readers.