|
| 1 | +/* |
| 2 | +Copyright (c) 2018-2020 Rossmann-Engineering |
| 3 | +Permission is hereby granted, free of charge, |
| 4 | +to any person obtaining a copy of this software |
| 5 | +and associated documentation files (the "Software"), |
| 6 | +to deal in the Software without restriction, |
| 7 | +including without limitation the rights to use, |
| 8 | +copy, modify, merge, publish, distribute, sublicense, |
| 9 | +and/or sell copies of the Software, and to permit |
| 10 | +persons to whom the Software is furnished to do so, |
| 11 | +subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission |
| 14 | +notice shall be included in all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 | +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 20 | +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 22 | +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | +*/ |
| 24 | +using System; |
| 25 | +using System.Runtime.Serialization; |
| 26 | + |
| 27 | +namespace EasyModbus.Exceptions |
| 28 | +{ |
| 29 | + /// <summary> |
| 30 | + /// Exception to be thrown if serial port is not opened |
| 31 | + /// </summary> |
| 32 | + public class SerialPortNotOpenedException : ModbusException |
| 33 | + { |
| 34 | + public SerialPortNotOpenedException() |
| 35 | + : base() |
| 36 | + { |
| 37 | + } |
| 38 | + |
| 39 | + public SerialPortNotOpenedException(string message) |
| 40 | + : base(message) |
| 41 | + { |
| 42 | + } |
| 43 | + |
| 44 | + public SerialPortNotOpenedException(string message, Exception innerException) |
| 45 | + : base(message, innerException) |
| 46 | + { |
| 47 | + } |
| 48 | + |
| 49 | + protected SerialPortNotOpenedException(SerializationInfo info, StreamingContext context) |
| 50 | + : base(info, context) |
| 51 | + { |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Exception to be thrown if Connection to Modbus device failed |
| 57 | + /// </summary> |
| 58 | + public class ConnectionException : ModbusException |
| 59 | + { |
| 60 | + public ConnectionException() |
| 61 | + : base() |
| 62 | + { |
| 63 | + } |
| 64 | + |
| 65 | + public ConnectionException(string message) |
| 66 | + : base(message) |
| 67 | + { |
| 68 | + } |
| 69 | + |
| 70 | + public ConnectionException(string message, Exception innerException) |
| 71 | + : base(message, innerException) |
| 72 | + { |
| 73 | + } |
| 74 | + |
| 75 | + protected ConnectionException(SerializationInfo info, StreamingContext context) |
| 76 | + : base(info, context) |
| 77 | + { |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Exception to be thrown if Modbus Server returns error code "Function code not supported" |
| 83 | + /// </summary> |
| 84 | + public class FunctionCodeNotSupportedException : ModbusException |
| 85 | + { |
| 86 | + public FunctionCodeNotSupportedException() |
| 87 | + : base() |
| 88 | + { |
| 89 | + } |
| 90 | + |
| 91 | + public FunctionCodeNotSupportedException(string message) |
| 92 | + : base(message) |
| 93 | + { |
| 94 | + } |
| 95 | + |
| 96 | + public FunctionCodeNotSupportedException(string message, Exception innerException) |
| 97 | + : base(message, innerException) |
| 98 | + { |
| 99 | + } |
| 100 | + |
| 101 | + protected FunctionCodeNotSupportedException(SerializationInfo info, StreamingContext context) |
| 102 | + : base(info, context) |
| 103 | + { |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /// <summary> |
| 108 | + /// Exception to be thrown if Modbus Server returns error code "quantity invalid" |
| 109 | + /// </summary> |
| 110 | + public class QuantityInvalidException : ModbusException |
| 111 | + { |
| 112 | + public QuantityInvalidException() |
| 113 | + : base() |
| 114 | + { |
| 115 | + } |
| 116 | + |
| 117 | + public QuantityInvalidException(string message) |
| 118 | + : base(message) |
| 119 | + { |
| 120 | + } |
| 121 | + |
| 122 | + public QuantityInvalidException(string message, Exception innerException) |
| 123 | + : base(message, innerException) |
| 124 | + { |
| 125 | + } |
| 126 | + |
| 127 | + protected QuantityInvalidException(SerializationInfo info, StreamingContext context) |
| 128 | + : base(info, context) |
| 129 | + { |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + /// <summary> |
| 134 | + /// Exception to be thrown if Modbus Server returns error code "starting adddress and quantity invalid" |
| 135 | + /// </summary> |
| 136 | + public class StartingAddressInvalidException : ModbusException |
| 137 | + { |
| 138 | + public StartingAddressInvalidException() |
| 139 | + : base() |
| 140 | + { |
| 141 | + } |
| 142 | + |
| 143 | + public StartingAddressInvalidException(string message) |
| 144 | + : base(message) |
| 145 | + { |
| 146 | + } |
| 147 | + |
| 148 | + public StartingAddressInvalidException(string message, Exception innerException) |
| 149 | + : base(message, innerException) |
| 150 | + { |
| 151 | + } |
| 152 | + |
| 153 | + protected StartingAddressInvalidException(SerializationInfo info, StreamingContext context) |
| 154 | + : base(info, context) |
| 155 | + { |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + /// <summary> |
| 160 | + /// Exception to be thrown if Modbus Server returns error code "Function Code not executed (0x04)" |
| 161 | + /// </summary> |
| 162 | + public class ModbusException : Exception |
| 163 | + { |
| 164 | + public ModbusException() |
| 165 | + : base() |
| 166 | + { |
| 167 | + } |
| 168 | + |
| 169 | + public ModbusException(string message) |
| 170 | + : base(message) |
| 171 | + { |
| 172 | + } |
| 173 | + |
| 174 | + public ModbusException(string message, Exception innerException) |
| 175 | + : base(message, innerException) |
| 176 | + { |
| 177 | + } |
| 178 | + |
| 179 | + protected ModbusException(SerializationInfo info, StreamingContext context) |
| 180 | + : base(info, context) |
| 181 | + { |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + /// <summary> |
| 186 | + /// Exception to be thrown if CRC Check failed |
| 187 | + /// </summary> |
| 188 | + public class CRCCheckFailedException : ModbusException |
| 189 | + { |
| 190 | + public CRCCheckFailedException() |
| 191 | + : base() |
| 192 | + { |
| 193 | + } |
| 194 | + |
| 195 | + public CRCCheckFailedException(string message) |
| 196 | + : base(message) |
| 197 | + { |
| 198 | + } |
| 199 | + |
| 200 | + public CRCCheckFailedException(string message, Exception innerException) |
| 201 | + : base(message, innerException) |
| 202 | + { |
| 203 | + } |
| 204 | + |
| 205 | + protected CRCCheckFailedException(SerializationInfo info, StreamingContext context) |
| 206 | + : base(info, context) |
| 207 | + { |
| 208 | + } |
| 209 | + } |
| 210 | + |
| 211 | +} |
0 commit comments