添加串口打开数据开关,tcp接收数据暂时打印不发送给云端

This commit is contained in:
fish 2019-03-19 11:59:49 +08:00
parent 433d480754
commit 8f2d2bac19
5 changed files with 26 additions and 20 deletions

Binary file not shown.

View File

@ -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 {

View File

@ -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 {}

View File

@ -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)
}

View File

@ -35,7 +35,7 @@ func yunhorn_ys_l_v1(data_buf []byte){
log.Println(device)
}
send_data(1005, device)
// send_data(1005, device)
}