Documentation
¶
Overview ¶
Package acr122u is a library for the ACR122U USB NFC Reader
Requirements ¶
ACR122U USB NFC Reader https://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader
Middleware to access a smart card using SCard API (PC/SC) https://pcsclite.apdu.fr
Under macOS pcsc-lite can be installed using homebrew: brew install pcsc-lite
The Go bindings to the PC/SC API https://github.com/ebfe/scard
Installation ¶
You can install the acr122u package using go get
go get -u github.com/kurrik/acr122u
Usage ¶
A minimal usage example
package main
import (
"fmt"
"github.com/kurrik/acr122u"
)
func main() {
ctx, err := acr122u.EstablishContext()
if err != nil {
panic(err)
}
ctx.ServeFunc(func(c acr122u.Card) {
fmt.Printf("%x\n", c.UID())
})
}
Index ¶
Constants ¶
const ( LogTrace = LogLevel(zerolog.TraceLevel) LogDebug = LogLevel(zerolog.DebugLevel) LogInfo = LogLevel(zerolog.InfoLevel) LogWarn = LogLevel(zerolog.WarnLevel) LogError = LogLevel(zerolog.ErrorLevel) LogFatal = LogLevel(zerolog.FatalLevel) LogPanic = LogLevel(zerolog.PanicLevel) )
Variables ¶
var ( // ErrOperationFailed is returned when the response code is 0x63 0x00 ErrOperationFailed = errors.New("operation failed") // ErrShutdown is returned when the library detects an interrupt signal ErrShutdown = errors.New("shutting down") // Called if the card payload wasn't deserializable to a card struct. ErrUnhandledCardData = errors.New("unknown card data") )
var ( JSONLogger io.Writer = os.Stderr ConsoleLogger = zerolog.ConsoleWriter{Out: os.Stderr} )
Functions ¶
This section is empty.
Types ¶
type Card ¶
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 ¶
type Context struct {
// contains filtered or unexported fields
}
Context for ACR122U readers
func EstablishContext ¶
EstablishContext creates a ACR122U context
func (*Context) ServeFunc ¶
func (actx *Context) ServeFunc(ctx context.Context, hf HandlerFunc) error
ServeFunc uses the provided HandlerFunc as a Handler
func (*Context) SetReaders ¶
SetReaders updates the list of readers, e.g. to filter to a specific reader
type Handler ¶
type Handler interface {
ServeCard(Card)
}
Handler is the interface that handles each card when present in the field.
type HandlerFunc ¶
type HandlerFunc func(Card)
HandlerFunc is the function signature for handling a card
func (HandlerFunc) ServeCard ¶
func (hf HandlerFunc) ServeCard(c Card)
ServeCard makes HandlerFunc implement the Handler interface
type Option ¶
type Option func(*Context)
Option is the function type used to configure the context
func WithProtocol ¶
WithProtocol accepts Undefined (0x0), T0 (0x1), T1 (0x2) or Any (T0|T1)
func WithShareMode ¶
WithShareMode accepts Exclusive (0x1) or Shared mode (0x2)
type Protocol ¶
type Protocol uint32
Protocol is the protocol type
var ( ProtocolUndefined Protocol = 0x0 ProtocolT0 Protocol = 0x1 ProtocolT1 Protocol = 0x2 ProtocolAny = ProtocolT0 | ProtocolT1 )
Protocols