sl500_api

package module
v0.0.0-...-cfacb10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

SL500 Card Reader API

The sl500_api package provides a Go-based interface for interacting with the SL500 card reader, allowing applications to communicate with the reader via serial connections. This package includes functions for initializing, configuring, and controlling the SL500, as well as reading and writing data on compatible RFID cards.

Features

  • Initialize and manage serial connections with SL500.
  • Control the reader's antenna, LED, and buzzer.
  • RFID card operations, including reading, writing, and authentication.
  • Compatibility with MIFARE and ISO15693 tags.

Installation

To include sl500_api in your project, use:

go get github.com/your_username/sl500_api

Usage

Initializing a Connection

To start, create a new connection to the SL500 card reader using the NewConnection function. Specify the serial port path, baud rate, logging option, and timeout.

package main

import (
    "fmt"
    "time"
    "github.com/ft-t/sl500-api"
)

func main() {
    // Initialize SL500 with the appropriate serial port path, baud rate, logging, and timeout
    reader, err := sl500_api.NewConnection("/dev/ttyUSB0", sl500_api.Baud.Baud9600, true, 3*time.Second)
    if err != nil {
        fmt.Println("Error initializing SL500:", err)
        return
    }
    defer reader.Close()
}
Basic Commands

Below are some primary commands for controlling the SL500:

  • Open and Close Connection

    err := reader.Open()      // Opens the serial connection
    err = reader.Close()      // Closes the connection
    
  • Antenna Control

    reader.RfAntennaSta(sl500_api.AntennaOn)    // Turn antenna on
    reader.RfAntennaSta(sl500_api.AntennaOff)   // Turn antenna off
    
  • RFID Card Commands

    reader.RfRequest(sl500_api.RequestAll)     // Scan for all cards
    reader.RfAnticoll()                        // Anti-collision function
    
  • MIFARE Operations

    blockNumber := byte(4)
    data, _ := reader.RfM1Read(blockNumber)    // Read data from block
    fmt.Printf("Data: %x\n", data)
    
    writeData := []byte{0x01, 0x02, 0x03, 0x04}
    reader.RfM1Write(blockNumber, writeData)   // Write data to block
    
Advanced Commands
Setting Device Type
reader.RfInitType(sl500_api.Type_A)
Enabling Beep and LED Light
reader.RfBeep(100)                        // Beep for 100 milliseconds
reader.RfLight(sl500_api.ColorGreen)      // Set LED to green

Error Handling

Each function returns an error object; check this for successful execution. Example:

if err := reader.RfAntennaSta(sl500_api.AntennaOn); err != nil {
    fmt.Println("Antenna error:", err)
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue for feedback or feature requests.

Documentation

Index

Constants

View Source
const (
	Type_A       = byte(0xA)
	Type_B       = byte(0xB)
	Type_ISO     = byte(0x1)
	AntennaOn    = byte(0x1)
	AntennaOff   = byte(0x0)
	ColorOff     = byte(0x0)
	ColorRed     = byte(0x1)
	ColorGreen   = byte(0x2)
	ColorYellow  = byte(0x3)
	RequestStd   = byte(0x26)
	RequestAll   = byte(0x52)
	AuthModeKeyA = byte(0x60)
	AuthModeKeyB = byte(0x61)
)

Variables

View Source
var Baud = baudRegistry()

Functions

This section is empty.

Types

type Sl500

type Sl500 struct {
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(path string, baud baud, logging bool, timeout time.Duration) (Sl500, error)

func (*Sl500) Close

func (s *Sl500) Close() error

func (*Sl500) ISO15693_Inventorys

func (s *Sl500) ISO15693_Inventorys() ([][]byte, error)

func (*Sl500) Open

func (s *Sl500) Open() error

func (*Sl500) RfAntennaSta

func (s *Sl500) RfAntennaSta(antennaState byte) ([]byte, error)

func (*Sl500) RfAnticoll

func (s *Sl500) RfAnticoll() ([]byte, error)

func (*Sl500) RfBeep

func (s *Sl500) RfBeep(durationMs byte) ([]byte, error)

func (*Sl500) RfGetDeviceNumber

func (s *Sl500) RfGetDeviceNumber() ([]byte, error)

func (*Sl500) RfGetModel

func (s *Sl500) RfGetModel() ([]byte, error)

func (*Sl500) RfHalt

func (s *Sl500) RfHalt() ([]byte, error)

func (*Sl500) RfInitCom

func (s *Sl500) RfInitCom(baud byte) ([]byte, error)

func (*Sl500) RfInitDeviceNumber

func (s *Sl500) RfInitDeviceNumber(deviceId []byte) ([]byte, error)

func (*Sl500) RfInitType

func (s *Sl500) RfInitType(workType byte) ([]byte, error)

func (*Sl500) RfLight

func (s *Sl500) RfLight(color byte) ([]byte, error)

func (*Sl500) RfM1Authentication2

func (s *Sl500) RfM1Authentication2(authMode byte, blockNumber byte, key []byte) ([]byte, error)

func (*Sl500) RfM1Decrement

func (s *Sl500) RfM1Decrement(blockNumber byte, decrementValue []byte) ([]byte, error)

func (*Sl500) RfM1Increment

func (s *Sl500) RfM1Increment(blockNumber byte, incrementValue []byte) ([]byte, error)

func (*Sl500) RfM1Initval

func (s *Sl500) RfM1Initval(blockNumber byte, initialValue []byte) ([]byte, error)

func (*Sl500) RfM1Read

func (s *Sl500) RfM1Read(blockNumber byte) ([]byte, error)

func (*Sl500) RfM1Readval

func (s *Sl500) RfM1Readval(blockNumber byte) ([]byte, error)

func (*Sl500) RfM1Restore

func (s *Sl500) RfM1Restore(blockNumber byte) ([]byte, error)

func (*Sl500) RfM1Transfer

func (s *Sl500) RfM1Transfer(blockNumber byte) ([]byte, error)

func (*Sl500) RfM1Write

func (s *Sl500) RfM1Write(blockNumber byte, data []byte) ([]byte, error)

func (*Sl500) RfRequest

func (s *Sl500) RfRequest(requestType byte) ([]byte, error)

func (*Sl500) RfSelect

func (s *Sl500) RfSelect(serialNumber []byte) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL