| | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/model/common" |
| | | "apsClient/pkg/logx" |
| | | "github.com/goburrow/modbus" |
| | | "sync" |
| | | "time" |
| | |
| | | rtuHandler = modbus.NewRTUClientHandler(c.SerialName) |
| | | rtuHandler.BaudRate = c.BaudRate |
| | | rtuHandler.DataBits = c.DataBit |
| | | rtuHandler.Parity = c.Parity.String() |
| | | rtuHandler.Parity = c.Parity.ToString() |
| | | rtuHandler.StopBits = c.StopBit |
| | | rtuHandler.SlaveId = 1 |
| | | rtuHandler.Timeout = 5 * time.Second |
| | | |
| | | err := rtuHandler.Connect() |
| | | if err != nil { |
| | | logx.Errorf("getModbusRTUConnection Connect err:%v, config: %+v", err, c) |
| | | return nil |
| | | } |
| | | return modbus.NewClient(rtuHandler) |
| | | } |