https://github.com/ft-t/sl500-api
sl500 card reader api
https://github.com/ft-t/sl500-api
card-reader go golang golang-library sl500
Last synced: about 1 year ago
JSON representation
sl500 card reader api
- Host: GitHub
- URL: https://github.com/ft-t/sl500-api
- Owner: ft-t
- License: gpl-3.0
- Created: 2018-06-22T08:39:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T15:11:49.000Z (over 1 year ago)
- Last Synced: 2025-03-29T21:14:31.492Z (about 1 year ago)
- Topics: card-reader, go, golang, golang-library, sl500
- Language: Go
- Homepage:
- Size: 942 KB
- Stars: 1
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
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:
```bash
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.
```go
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**
```go
err := reader.Open() // Opens the serial connection
err = reader.Close() // Closes the connection
```
- **Antenna Control**
```go
reader.RfAntennaSta(sl500_api.AntennaOn) // Turn antenna on
reader.RfAntennaSta(sl500_api.AntennaOff) // Turn antenna off
```
- **RFID Card Commands**
```go
reader.RfRequest(sl500_api.RequestAll) // Scan for all cards
reader.RfAnticoll() // Anti-collision function
```
- **MIFARE Operations**
```go
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
```go
reader.RfInitType(sl500_api.Type_A)
```
#### Enabling Beep and LED Light
```go
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:
```go
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](LICENSE) file for details.
## Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue for feedback or feature requests.