发卡关卡的读卡流程完成
This commit is contained in:
41
demo/modbus2/main.go
Normal file
41
demo/modbus2/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"game-driver/logger"
|
||||
"game-driver/pkg/card_reader"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger.DefaultLogger()
|
||||
defer logger.Sync()
|
||||
|
||||
reader, err := card_reader.NewReader("rtu:///dev/ttyUSB0")
|
||||
if err != nil {
|
||||
zap.S().Panicln(err)
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
err = reader.Init()
|
||||
if err != nil {
|
||||
zap.S().Panicln(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go reader.OnCardInfo(ctx, func(info *card_reader.CardInfo) {
|
||||
zap.S().Infow("Card info", "Type", fmt.Sprintf("%#x", info.Type), "ID", info.ID)
|
||||
})
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
<-sig
|
||||
zap.S().Infoln("接收到关闭命令 - 正在关闭程序")
|
||||
cancel()
|
||||
zap.S().Infoln("关闭完成")
|
||||
}
|
||||
Reference in New Issue
Block a user