| | |
| | | if !ok { |
| | | return nil, false |
| | | } |
| | | connOK, err := cm.CheckConnect(conn, time.Second*1) |
| | | if err != nil { |
| | | logx.Errorf("ping plc err:%v", err.Error()) |
| | | return nil, false |
| | | } |
| | | if connOK { |
| | | return conn, ok |
| | | } |
| | | return nil, false |
| | | //if ok, _ := cm.CheckConnect(conn, time.Second); !ok { |
| | | // conn.Close() |
| | | //} |
| | | |
| | | return conn, true |
| | | } |
| | | |
| | | var connectionManager = newPlcConnectionManager() |
| | |
| | | defer cancel() |
| | | conn, err := newGetModbusConnection(ctx, ipAddr) |
| | | if err != nil { |
| | | logx.Errorf("new modbus connection err: %v", err.Error()) |
| | | return nil, err |
| | | } |
| | | connectionManager.AddConnection(ipAddr, conn) |