规范串口通讯
This commit is contained in:
26
config.yml
26
config.yml
@@ -1,6 +1,6 @@
|
|||||||
location: wushan
|
location: wushan
|
||||||
point: 5
|
point: 4
|
||||||
relay: /dev/ttyUSB0
|
relay: /dev/ttyUSB1
|
||||||
maxTimeout: 60 # 单位 s,必须大于 0
|
maxTimeout: 60 # 单位 s,必须大于 0
|
||||||
log:
|
log:
|
||||||
level: debug
|
level: debug
|
||||||
@@ -19,14 +19,14 @@ aliyun:
|
|||||||
timeout: 10 # 单位 s
|
timeout: 10 # 单位 s
|
||||||
voice: zhifeng_emo
|
voice: zhifeng_emo
|
||||||
game:
|
game:
|
||||||
addr: /dev/ttyUSB0 # 点位 5 的串口地址
|
# addr: /dev/ttyUSB0 # 点位 5 的串口地址
|
||||||
# pushGroups: # 点位 4 的发卡器配置
|
pushGroups: # 点位 4 的发卡器配置
|
||||||
# - name: gpiochip0
|
- name: gpiochip0
|
||||||
# outOK: 6
|
outOK: 12
|
||||||
# lower: 13
|
lower: 1
|
||||||
# error: 19
|
error: 7
|
||||||
# empty: 26
|
empty: 8
|
||||||
# push: 11
|
push: 0
|
||||||
# reset: 22
|
reset: 5
|
||||||
# pull: 27
|
pull: 6
|
||||||
# readAddr: /dev/ttyUSB0 # 点位 4 的读卡器配置
|
readAddr: /dev/ttyUSB0 # 点位 4 的读卡器配置
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -19,8 +20,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
r.On(0)
|
for i := 0; i < 4; i++ {
|
||||||
defer r.Off(0)
|
func(num int) {
|
||||||
|
r.On(num)
|
||||||
|
defer r.Off(num)
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}(i)
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.OnAll()
|
||||||
|
defer r.OffAll()
|
||||||
|
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func PushCard(ctx context.Context) leaf.HandlerFunc {
|
|||||||
devices := make([]*card_pusher.Device, 0)
|
devices := make([]*card_pusher.Device, 0)
|
||||||
for i, group := range g.PushGroups {
|
for i, group := range g.PushGroups {
|
||||||
// 对读卡器初始化配置
|
// 对读卡器初始化配置
|
||||||
reader.SetSlave(uint8(i + 1))
|
reader.SetSlave(byte(i + 1))
|
||||||
err = reader.Init()
|
err = reader.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Panicln("读卡器初始配置失败", err)
|
zap.S().Panicln("读卡器初始配置失败", err)
|
||||||
@@ -114,7 +114,7 @@ func PushCard(ctx context.Context) leaf.HandlerFunc {
|
|||||||
if body.num != 0 {
|
if body.num != 0 {
|
||||||
// 若卡片就位,读取卡片信息
|
// 若卡片就位,读取卡片信息
|
||||||
if devices[body.num-1].GetOutOk() == 1 {
|
if devices[body.num-1].GetOutOk() == 1 {
|
||||||
reader.SetSlave(uint8(body.num))
|
reader.SetSlave(byte(body.num))
|
||||||
if info := reader.GetCardInfo(); info != nil {
|
if info := reader.GetCardInfo(); info != nil {
|
||||||
body.CardId = info.ID
|
body.CardId = info.ID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ import (
|
|||||||
|
|
||||||
type Reader interface {
|
type Reader interface {
|
||||||
io.Closer
|
io.Closer
|
||||||
SetSlave(uint8)
|
// SetSlave 设置读卡器的 UnitID
|
||||||
|
SetSlave(byte)
|
||||||
// WriteUnitId 写入读卡器的 UnitID
|
// WriteUnitId 写入读卡器的 UnitID
|
||||||
WriteUnitId(uint16) error
|
WriteUnitId(uint16) error
|
||||||
// Init 初始化读卡器配置
|
// Init 初始化读卡器配置
|
||||||
|
|||||||
@@ -7,10 +7,15 @@ import (
|
|||||||
|
|
||||||
type Relay interface {
|
type Relay interface {
|
||||||
io.Closer
|
io.Closer
|
||||||
SetSlave(slaveID byte)
|
// SetSlave 设置继电器的 UnitID
|
||||||
On(num int) error
|
SetSlave(byte)
|
||||||
Off(num int) error
|
// On 打开继电器
|
||||||
|
On(int) error
|
||||||
|
// Off 关闭继电器
|
||||||
|
Off(int) error
|
||||||
|
// OnAll 打开所有继电器
|
||||||
OnAll() error
|
OnAll() error
|
||||||
|
// OffAll 关闭所有继电器
|
||||||
OffAll() error
|
OffAll() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user