]> git.basschouten.com Git - openhab-addons.git/blob
c18669630d59e993dfb200aa8cb3b1e4af37ce69
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.transport.modbus.exception;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.io.transport.modbus.endpoint.ModbusSlaveEndpoint;
18
19 /**
20  * Exception for connection issues
21  *
22  * @author Sami Salonen - Initial contribution
23  *
24  */
25 @NonNullByDefault
26 public class ModbusConnectionException extends ModbusTransportException {
27
28     private static final long serialVersionUID = -6171226761518661925L;
29     private ModbusSlaveEndpoint endpoint;
30
31     /**
32      *
33      * @param endpoint endpoint associated with this exception
34      */
35     public ModbusConnectionException(ModbusSlaveEndpoint endpoint) {
36         this.endpoint = endpoint;
37     }
38
39     /**
40      * Get endpoint associated with this connection error
41      *
42      * @return endpoint with the error
43      */
44     public ModbusSlaveEndpoint getEndpoint() {
45         return endpoint;
46     }
47
48     @Override
49     public @Nullable String getMessage() {
50         return String.format("Error connecting to endpoint %s", endpoint);
51     }
52
53     @Override
54     public String toString() {
55         return String.format("ModbusConnectionException(Error connecting to endpoint=%s)", endpoint);
56     }
57 }