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/peterhellberg/acr122u
Usage ¶
A minimal usage example
package main import ( "fmt" "github.com/peterhellberg/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 ¶
This section is empty.
Variables ¶
var ( // ErrOperationFailed is returned when the response code is 0x63 0x00 ErrOperationFailed = Error{Message: "operation failed"} )
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 (ctx *Context) ServeFunc(hf HandlerFunc) error
ServeFunc uses the provided HandlerFunc as a Handler
type Error ¶
type Error struct {
Message string
}
Error is tye error type returned by the acr122u package
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 Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger interface that is implemented by *log.Logger
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