| | |
| | | package modbusx |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "github.com/goburrow/modbus" |
| | | "sync" |
| | | "time" |
| | | ) |
| | | |
| | | type ConnectionManager struct { |
| | | connections map[string]modbus.Client |
| | | mu sync.Mutex |
| | | } |
| | | |
| | | var handler *modbus.TCPClientHandler |
| | | |
| | | func newPlcConnectionManager() *ConnectionManager { |
| | | return &ConnectionManager{ |
| | |
| | | return |
| | | } |
| | | connectionManager.RemoveConnection(ipAddr) |
| | | if handler != nil { |
| | | handler.Close() |
| | | } |
| | | } |
| | | |
| | | func newGetModbusConnection(ipAddr string) modbus.Client { |
| | | return modbus.TCPClient(ipAddr) |
| | | handler = modbus.NewTCPClientHandler(ipAddr) |
| | | handler.Timeout = 10 * time.Second |
| | | handler.SlaveId = byte(conf.Conf.PLC.SlaveId) |
| | | return modbus.NewClient(handler) |
| | | } |