添加串口打开数据开关,tcp接收数据暂时打印不发送给云端
This commit is contained in:
parent
433d480754
commit
8f2d2bac19
BIN
db/gateway.db
BIN
db/gateway.db
Binary file not shown.
|
@ -25,6 +25,7 @@ type Conf struct {
|
|||
WEBSOCKETURL []string `json:"websocketurl"`
|
||||
POST_TO_SERVER string `json:"post_to_server"`
|
||||
DEBUG bool `json:"debug"`
|
||||
OPENSERIAL bool `json:"openserial"`
|
||||
}
|
||||
|
||||
type Gateway_info struct {
|
||||
|
|
4
main.go
4
main.go
|
@ -26,7 +26,7 @@ func main() {
|
|||
log.Printf("listen fail, err: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
|
@ -34,7 +34,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
// go process(conn)
|
||||
go handleConn(conn)
|
||||
go handleConn(conn)
|
||||
}
|
||||
|
||||
// select {}
|
||||
|
|
|
@ -21,25 +21,30 @@ func serial_run() {
|
|||
port_arr = append(port_arr, ports_arr[i])
|
||||
}
|
||||
// 解析串口配置
|
||||
for _, i := range port_arr {
|
||||
var PARITY serial.Parity
|
||||
switch conf.SERIALPORTS_LIST[i].PARITY {
|
||||
case "N":
|
||||
PARITY = 'N'
|
||||
case "E":
|
||||
PARITY = 'E'
|
||||
if conf.OPENSERIAL{
|
||||
for _, i := range port_arr {
|
||||
var PARITY serial.Parity
|
||||
switch conf.SERIALPORTS_LIST[i].PARITY {
|
||||
case "N":
|
||||
PARITY = 'N'
|
||||
case "E":
|
||||
PARITY = 'E'
|
||||
}
|
||||
// 打开串口
|
||||
SERIAL_PORT[i], err = serial.OpenPort(&serial.Config{
|
||||
Name: conf.SERIALPORTS_LIST[i].COM,
|
||||
Baud: conf.SERIALPORTS_LIST[i].BAUDS,
|
||||
Parity: PARITY,
|
||||
ReadTimeout: time.Millisecond * time.Duration(conf.SERIALPORTS_LIST[i].READTIMEOUT),
|
||||
|
||||
// ReadTimeout: time.Second * time.Duration(conf.SERIALPORTS_LIST[i].READTIMEOUT),
|
||||
|
||||
})
|
||||
check(err)
|
||||
defer SERIAL_PORT[i].Close()
|
||||
}
|
||||
// 打开串口
|
||||
SERIAL_PORT[i], err = serial.OpenPort(&serial.Config{
|
||||
Name: conf.SERIALPORTS_LIST[i].COM,
|
||||
Baud: conf.SERIALPORTS_LIST[i].BAUDS,
|
||||
Parity: PARITY,
|
||||
ReadTimeout: time.Millisecond * time.Duration(conf.SERIALPORTS_LIST[i].READTIMEOUT),
|
||||
// ReadTimeout: time.Second * time.Duration(conf.SERIALPORTS_LIST[i].READTIMEOUT),
|
||||
})
|
||||
check(err)
|
||||
defer SERIAL_PORT[i].Close()
|
||||
}
|
||||
|
||||
if conf.DEBUG {
|
||||
log.Println(SERIAL_PORT)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue