ACS Reader Integration with Python

How do you use an ACS reader from Python? Install pyscard (pip install pyscard), the Python wrapper for PC/SC. smartcard.System.readers() lists the readers, reader.createConnection() and connect() open the card, getATR() returns the ATR, and transmit([0xFF, 0xCA, 0x00, 0x00, 0x00]) returns the card UID with the status words 90 00. Reader-only commands, such as the ACS firmware version escape command, go through connection.control(). To react to cards as they are tapped, use CardMonitor; to react to readers being plugged in, use ReaderMonitor. On Windows pyscard calls the same Smart Card service as the C# PC/SC series, so the commands and status words are identical.

This guide covers installing pyscard on Windows and Linux, two complete read-only scripts for ACS readers such as the ACR1252U, ACR1552U and ACR122U (one that reads the ATR, UID and firmware version, and one that watches for readers and cards), and the escape command control code, which differs between Windows and Linux.

Not yet tested on a reader. The two scripts were checked line by line against the pyscard 2.3.2 documentation on 1 Dec 2026. BSD then ran read_card.py with Python 3.13 and pyscard 2.3.2 on a PC with no ACS reader attached: it listed the PC's only reader and reported that no contactless reader was found. Both scripts compile; neither has been run with an ACS reader and card yet. The replies shown below come from the ACS manuals, not from BSD's readers. This note will change once the hardware tests listed at the end are done.

pyscard is an open-source (LGPL) project maintained by Ludovic Rousseau, who also maintains pcsc-lite. On 1 Dec 2026 the current release on PyPI was pyscard 2.3.2 (27 Oct 2026), which needs Python 3.9 or later. It is a wrapper, not a driver: install the ACS reader driver first, and check that the reader works in a tool such as ACS QuickView before you debug Python.

Windows 10 and 11

  1. Install Python 3.10 or later from python.org. On a PC without Python, typing python in a terminal may only open the Microsoft Store: that is a Windows app alias, not an installed Python. The py launcher from the python.org installer avoids the confusion.
  2. Install pyscard: py -m pip install pyscard. PyPI publishes ready-built Windows wheels (32-bit, 64-bit and ARM64) for CPython 3.10 to 3.15, so no compiler is needed.
  3. Check it: py -c "from smartcard.System import readers; print(readers())" prints the reader names. If the list is empty, the problem is the reader, driver or Smart Card service, not pyscard (check the PC/SC reader status).

Linux

  1. Install and start pcsc-lite (the pcscd service) and a reader driver: the free CCID driver or ACS's own Linux driver from the reader's ACS download page. PC/SC on Linux and macOS explains the pieces.
  2. Use your distribution's package if it has one. Debian, for example, packages it as python3-pyscard (2.2.2 in Debian 13 "trixie", 2.3.2 in testing on 1 Dec 2026).
  3. Or install from PyPI: pip install pyscard, preferably inside a virtual environment. PyPI has no ready-built Linux wheels, so pip builds pyscard from source. pyscard's install notes say that needs gcc, swig and pcsc-lite; on most distributions that usually also means the pcsc-lite development package and the Python development headers.

BSD's test PCs run Windows 10 and 11. The Linux steps follow the pyscard documentation and have not been tried by BSD.

pyscard has a low-level module, smartcard.scard, that mirrors the PC/SC C functions one for one, and a higher-level API on top of it. The scripts here use the higher-level API. The right-hand column is the PC/SC function that does the same job, so you can follow the WinSCard call sequence.

JobpyscardPC/SC function with the same job
List readerssmartcard.System.readers() returns a list of reader objects; str(reader) is the reader nameSCardListReaders
Wait for a cardCardRequest(timeout=30, readers=[name]).waitforcard() (timeout in seconds; CardRequestTimeoutException when it runs out)SCardGetStatusChange
Connectreader.createConnection(), then connection.connect() (shared mode by default)SCardConnect
ATRconnection.getATR(), a list of integersSCardStatus / reader state
Send an APDUdata, sw1, sw2 = connection.transmit(apdu)SCardTransmit
Send a reader commandconnection.control(code, command)SCardControl
Disconnectconnection.disconnect()SCardDisconnect
Card and reader eventsCardMonitor with a CardObserver; ReaderMonitor with a ReaderObserverSCardGetStatusChange in a loop
Show bytessmartcard.util.toHexString(data) gives "3B 8F 80 ..."; toBytes("FF CA 00 00 00") goes the other way(helper)

Commands and replies are plain Python lists of integers from 0 to 255, so [0xFF, 0xCA, 0x00, 0x00, 0x00] is the Get Data command. pyscard's connect() also accepts a protocol bit mask and a share mode (SCARD_SHARE_SHARED by default, SCARD_SHARE_EXCLUSIVE or SCARD_SHARE_DIRECT). The defaults are right for ACS contactless readers.

Language: Python 3.10 or later with pyscard 2.x. Prerequisites: pyscard installed as above; an ACS reader with its driver; a test card such as MIFARE Classic 1K, NTAG or DESFire for the UID. Run: py read_card.py for the first reader with PICC in its name, or py read_card.py ACR1552 to choose by part of the name (on Linux, python3 instead of py).

The script 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. Contact cards in an ACR39U have no UID, so for them it prints the ATR only (why contact cards have no UID).

read_card.py

# Day 48: read the ATR, the card UID and the reader firmware version from an ACS reader
# with pyscard (Python 3.10 or later, pyscard 2.x). Read-only.
# Run by BSD with Python 3.13 and pyscard 2.3.2 on a PC without an ACS reader; not yet tested on a reader.
#
# Run: python read_card.py            (first reader whose name contains "PICC")
#      python read_card.py ACR1552    (first reader whose name contains "ACR1552")

import sys

from smartcard.CardRequest import CardRequest
from smartcard.Exceptions import (CardConnectionException,
                                  CardRequestTimeoutException,
                                  ListReadersException, NoCardException)
from smartcard.scard import SCARD_CTL_CODE
from smartcard.System import readers
from smartcard.util import toASCIIString, toHexString

GET_UID = [0xFF, 0xCA, 0x00, 0x00, 0x00]               # PC/SC Get Data (UID)
ESCAPE_GET_FIRMWARE = [0xE0, 0x00, 0x00, 0x18, 0x00]   # ACR1252U / ACR1552U escape command
ACR122U_GET_FIRMWARE = [0xFF, 0x00, 0x48, 0x00, 0x00]  # ACR122U pseudo-APDU
CARD_WAIT_SECONDS = 30


def read_uid(connection, name):
    if "PICC" not in name.upper():
        # Contact cards (for example in an ACR39U) have no UID: the ATR identifies them.
        print("Not a PICC (contactless) reader: Get Data not sent.")
        return
    data, sw1, sw2 = connection.transmit(GET_UID)
    if (sw1, sw2) == (0x90, 0x00):
        print("UID:", toHexString(data), " (SW 90 00)")
    else:
        # 63 00 = the command failed; 6A 81 = not supported for this card or mode.
        print("Get Data refused: SW %02X %02X" % (sw1, sw2))


def read_firmware(connection, name):
    upper = name.upper()
    if "ACR122" in upper:
        # The ACR122U answers with version text only. pyscard still splits off the
        # last two bytes as sw1 and sw2, so put them back.
        data, sw1, sw2 = connection.transmit(ACR122U_GET_FIRMWARE)
        raw = data + [sw1, sw2]
        print("Firmware reply:", toHexString(raw), ' = "%s"' % toASCIIString(raw))
    elif "ACR1252" in upper or "ACR1552" in upper:
        code = SCARD_CTL_CODE(3500)  # the value for the platform pyscard runs on
        print("Escape control code: 0x%X" % code)
        reply = connection.control(code, ESCAPE_GET_FIRMWARE)
        print("Firmware reply:", toHexString(reply))
        # Documented layout: E1 00 00 00, one length byte, then the version text.
        if len(reply) >= 5 and reply[0] == 0xE1:
            text = reply[5:5 + reply[4]]
            print("Firmware:", toASCIIString(text))
    else:
        print("No firmware command for this reader in this sample.")


def main():
    wanted = sys.argv[1] if len(sys.argv) > 1 else "PICC"
    try:
        all_readers = readers()
    except ListReadersException as e:
        print("Could not list readers:", e)
        return 1

    chosen = None
    for r in all_readers:
        print("Reader:", r)
        if chosen is None and wanted.upper() in str(r).upper():
            chosen = r
    if chosen is None:
        print('No reader whose name contains "%s".' % wanted)
        return 1
    name = str(chosen)
    print("Using:", name)

    print("Place a card on the reader (waiting up to %d s)..." % CARD_WAIT_SECONDS)
    request = CardRequest(timeout=CARD_WAIT_SECONDS, readers=[name])
    try:
        service = request.waitforcard()
    except CardRequestTimeoutException:
        print("No card arrived in time.")
        return 2

    connection = service.connection
    try:
        connection.connect()  # shared mode, T=0 or T=1
        print("ATR:", toHexString(connection.getATR()))
        read_uid(connection, name)
        read_firmware(connection, name)
    except (NoCardException, CardConnectionException) as e:
        print("Card error:", e)
        return 3
    finally:
        connection.disconnect()
    return 0


if __name__ == "__main__":
    sys.exit(main())

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.

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)...
ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
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

The exit code is 0 when the card was read, 1 when no reader matched, 2 when no card arrived in 30 seconds and 3 for a card or connection error. Decoding the contactless ATR explains the ATR bytes, and status words explains 90 00, 63 00 and 6A 81.

For attendance, access or canteen-style programs you want an event each time a card is tapped, not a script that runs once. pyscard's CardMonitor does the waiting for you: you subclass CardObserver, write an update(self, observable, handlers) method, and pyscard calls it with the cards added and removed. Each card object has an atr and a reader, and card.createConnection() opens it. ReaderMonitor and ReaderObserver work the same way for readers being plugged in and removed.

monitor_cards.py

# Day 48: print readers as they are plugged in or removed, and the ATR and UID of every
# card placed on a contactless (PICC) reader, using pyscard's ReaderMonitor and CardMonitor.
# Read-only. Compiled by BSD (Python 3.13, pyscard 2.3.2); not yet tested on a reader. Stop with Ctrl+C.

import time

from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.Exceptions import CardConnectionException, NoCardException
from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver
from smartcard.util import toHexString

GET_UID = [0xFF, 0xCA, 0x00, 0x00, 0x00]


class PrintReaders(ReaderObserver):
    def update(self, observable, handlers):
        added, removed = handlers
        for r in added:
            print("Reader added:", r)
        for r in removed:
            print("Reader removed:", r)


class PrintCards(CardObserver):
    def update(self, observable, handlers):
        added, removed = handlers
        for card in added:
            print("Card on %s, ATR %s" % (card.reader, toHexString(card.atr)))
            if "PICC" in str(card.reader).upper():
                self.read_uid(card)
        for card in removed:
            print("Card removed from", card.reader)

    @staticmethod
    def read_uid(card):
        connection = card.createConnection()
        try:
            connection.connect()
            data, sw1, sw2 = connection.transmit(GET_UID)
            if (sw1, sw2) == (0x90, 0x00):
                print("  UID:", toHexString(data))
            else:
                print("  Get Data refused: SW %02X %02X" % (sw1, sw2))
        except (NoCardException, CardConnectionException) as e:
            print("  Could not read the UID:", e)
        finally:
            connection.disconnect()


def main():
    reader_monitor = ReaderMonitor()
    card_monitor = CardMonitor()
    reader_observer = PrintReaders()
    card_observer = PrintCards()
    reader_monitor.addObserver(reader_observer)
    card_monitor.addObserver(card_observer)
    print("Watching readers and cards. Press Ctrl+C to stop.")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        # Without this the monitor threads keep polling and the program does not exit.
        card_monitor.deleteObserver(card_observer)
        reader_monitor.deleteObserver(reader_observer)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Two things matter here:

  • Delete your observers. The monitoring thread keeps running as long as the monitor has observers, and pyscard warns that a program that does not call deleteObserver runs for ever. The finally block does that when you press Ctrl+C.
  • update() runs on the monitor's thread, not your main thread. Keep it short; in a GUI program, hand the UID to the GUI thread instead of updating windows from update().

The same one-read-per-tap idea, with the reasons behind it, is described in the C# UID read loop.

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 pyscard that is connection.control(code, command), which returns the reply bytes. The reply layout and each reader's command are on checking the ACS reader firmware version.

The control code is a different number on each platform:

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

pyscard's low-level module provides SCARD_CTL_CODE(code), documented as returning the value of a control code, so the script calls SCARD_CTL_CODE(3500) instead of hard-coding a number, and prints the result. On Windows that line should read 0x3136B0; confirming it is one of BSD's hardware checks. The driver must also pass escape commands on: on Windows that normally means the ACS driver, and on Linux the free CCID driver only allows them when an option is set (details).

  • Without a card. pyscard documents SCARD_SHARE_DIRECT as direct control of the reader, even without a card, for use before control commands: connection.connect(mode=SCARD_SHARE_DIRECT). ACS's own ACR1252U example uses direct mode for this command. The script on this page keeps to a normal connection with a card on the reader, like the Script Tool method; BSD has not tried direct mode from Python.
  • 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. pyscard still splits off the last two bytes as sw1 and sw2, so the script joins them back before printing.

Other escape commands can change reader settings, such as the LED and buzzer. Keep test scripts to Get Firmware Version until you have read the manual for every other command.

What you seeLikely causeWhat to do
Typing python opens the Microsoft StorePython is not installed; Windows shows its app aliasInstall Python from python.org and use py.
ModuleNotFoundError: No module named 'smartcard'pyscard installed for a different Python, or not at allRun py -m pip install pyscard with the same Python that runs the script.
pip fails while building pyscard on LinuxNo Linux wheel, so pip compiles it, and swig, gcc or the pcsc-lite headers are missingInstall them, or use the distribution package (python3-pyscard on Debian).
"No reader whose name contains "PICC""The reader name differs, the reader is not detected, or only a contact reader is connectedLook at the names the script prints; check that Windows detects the reader.
ListReadersExceptionThe Smart Card service (or pcscd) is not running, or no reader is plugged inStart the service; see service status.
CardConnectionException on connect()Another program holds the card in exclusive mode, or the card left the fieldClose QuickView, the Script Tool or the other program; hold the card still. See share modes.
Get Data refused: SW 6A 81Get Data not supported for this card or mode, or the SAM entry was chosenUse the PICC entry; see UID troubleshooting.
control() fails on an ACR1252U or ACR1552UA driver that does not pass escape commands, or the wrong control codeUse the ACS driver; check the printed code; see the firmware guide's troubleshooting.
The monitor script will not exitAn observer was not deletedCall deleteObserver for every observer, in a finally block.

BSD has not yet run these scripts. These read-only tests are planned on BSD's own readers and test cards on Windows, and this page will be updated with the real output:

  1. Install pyscard with py -m pip install pyscard on Windows 11 and list the readers.
  2. ACR1252U with a MIFARE Classic 1K card: the ATR, the UID, the printed control code (expected 0x3136B0) and the firmware text.
  3. ACR1552U with an NTAG or DESFire card, and ACR122U on Windows 10: the same results, with the ACR122U firmware text from FF 00 48 00 00.
  4. ACR39U with an SLE memory card: the ATR only, with no Get Data sent.
  5. monitor_cards.py: plug and unplug a reader, tap several cards, then press Ctrl+C and confirm the script exits.

Linux installs and runs are not on BSD's test list yet.

The pyscard 2.3.2 documentation, PyPI page, install notes and the Debian package list were checked on 1 Dec 2026 for every function, argument, exception and install step 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. Python is a trademark of the Python Software Foundation. MIFARE, MIFARE Classic, MIFARE DESFire and NTAG are trademarks of NXP B.V.

Integrating ACS readers with Python?

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