acr122u: Index | Files

package acr122u

import ""

Package acr122u is a library for the ACR122U USB NFC Reader


ACR122U USB NFC Reader

Middleware to access a smart card using SCard API (PC/SC)

Under macOS pcsc-lite can be installed using homebrew: brew install pcsc-lite

The Go bindings to the PC/SC API


You can install the acr122u package using go get

go get -u


A minimal usage example

package main

import (


func main() {
	ctx, err := acr122u.EstablishContext()
	if err != nil {

	ctx.ServeFunc(func(c acr122u.Card) {
		fmt.Printf("%x\n", c.UID())


Package Files

acr122u.go card.go context.go errors.go handler.go logger.go status.go


var (
    // ErrOperationFailed is returned when the response code is 0x63 0x00
    ErrOperationFailed = Error{Message: "operation failed"}

type Card Uses

type Card interface {
    // Reader returns the name of the reader used
    Reader() string

    // Status returns the card status
    Status() (Status, error)

    // UID returns the UID for the card
    UID() []byte

Card represents a ACR122U card

type Context Uses

type Context struct {
    // contains filtered or unexported fields

Context for ACR122U readers

func EstablishContext Uses

func EstablishContext(options ...Option) (*Context, error)

EstablishContext creates a ACR122U context

func (*Context) Readers Uses

func (ctx *Context) Readers() []string

Readers returns a list of readers

func (*Context) Release Uses

func (ctx *Context) Release() error

Release should be called when the context is not needed anymore

func (*Context) Serve Uses

func (ctx *Context) Serve(h Handler) error

Serve cards being swiped using the provided Handler

func (*Context) ServeFunc Uses

func (ctx *Context) ServeFunc(hf HandlerFunc) error

ServeFunc uses the provided HandlerFunc as a Handler

type Error Uses

type Error struct {
    Message string

Error is tye error type returned by the acr122u package

func (Error) Error Uses

func (e Error) Error() string

Error returns the error message

type Handler Uses

type Handler interface {

Handler is the interface that handles each card when present in the field.

type HandlerFunc Uses

type HandlerFunc func(Card)

HandlerFunc is the function signature for handling a card

func (HandlerFunc) ServeCard Uses

func (hf HandlerFunc) ServeCard(c Card)

ServeCard makes HandlerFunc implement the Handler interface

type Logger Uses

type Logger interface {
    Printf(format string, v ...interface{})

Logger interface that is implemented by *log.Logger

type Option Uses

type Option func(*Context)

Option is the function type used to configure the context

func WithProtocol Uses

func WithProtocol(p Protocol) Option

WithProtocol accepts Undefined (0x0), T0 (0x1), T1 (0x2) or Any (T0|T1)

func WithShareMode Uses

func WithShareMode(sm ShareMode) Option

WithShareMode accepts Exclusive (0x1) or Shared mode (0x2)

type Protocol Uses

type Protocol uint32

Protocol is the protocol type

var (
    ProtocolUndefined Protocol = 0x0
    ProtocolT0        Protocol = 0x1
    ProtocolT1        Protocol = 0x2
    ProtocolAny                = ProtocolT0 | ProtocolT1


type ShareMode Uses

type ShareMode uint32

ShareMode is the share mode type

var (
    ShareExclusive ShareMode = 0x1
    ShareShared    ShareMode = 0x2

Share modes

type Status Uses

type Status struct {
    Reader         string
    State          uint32
    ActiveProtocol uint32
    Atr            []byte

Status contains the status of a card

Package acr122u imports 3 packages (graph). Updated 2019-02-19. Refresh now. Tools for package owners.