Line data Source code
1 : // header only version of modbuspp
2 : //
3 : //
4 : // Created by Fanzhe on 5/29/2017.
5 : //
6 : // MagAO-X:
7 : // Cloned from https://github.com/fanzhe98/modbuspp
8 : // On commit 73cabdc, Date: Sat Nov 24 23:16:51 2018 -0500
9 : //
10 : // License: GPLv3
11 : //
12 : // Header only version created by Jared Males
13 : // -- removed "using namespace std".
14 : //
15 : //
16 : //
17 : //
18 :
19 : #ifndef MODBUSPP_MODBUS_EXCEPTION_H
20 : #define MODBUSPP_MODBUS_EXCEPTION_H
21 :
22 : #include <exception>
23 :
24 :
25 : /// Modbus Exception Class
26 : /**
27 : * Modbus Exeception Super Class
28 : *
29 : * Throwed when a exception or errors happens in modbus protocol
30 : */
31 : class modbus_exception : public std::exception {
32 : public:
33 : std::string msg;
34 0 : virtual const char* what() const throw()
35 : {
36 0 : return "A Error In Modbus Happened!";
37 : }
38 : };
39 :
40 :
41 : /// Modbus Connect Exception
42 : /**
43 : * Connection Issue
44 : *
45 : * Throwed when a connection issues happens between modbus client and server
46 : */
47 : class modbus_connect_exception: public modbus_exception {
48 : public:
49 0 : virtual const char* what() const throw()
50 : {
51 0 : return "Having Modbus Connection Problem";
52 : }
53 : };
54 :
55 :
56 : /// Modbus Illgal Function Exception
57 : /**
58 : * Illegal Function
59 : *
60 : * Throwed when modbus server return error response function 0x01
61 : */
62 : class modbus_illegal_function_exception: public modbus_exception {
63 : public:
64 0 : virtual const char* what() const throw()
65 : {
66 0 : return "Illegal Function";
67 : }
68 : };
69 :
70 :
71 : /// Modbus Illegal Address Exception
72 : /**
73 : * Illegal Address
74 : *
75 : * Throwed when modbus server return error response function 0x02
76 : */
77 : class modbus_illegal_address_exception: public modbus_exception {
78 : public:
79 :
80 0 : modbus_illegal_address_exception()
81 0 : {
82 0 : msg = "test";
83 0 : }
84 :
85 0 : const char* what() const throw()
86 : {
87 0 : return "Illegal Address";
88 : }
89 : };
90 :
91 :
92 : /// Modbus Illegal Data Value Exception
93 : /**
94 : * Illegal Data Vlaue
95 : *
96 : * Throwed when modbus server return error response function 0x03
97 : */
98 : class modbus_illegal_data_value_exception: public modbus_exception {
99 : public:
100 0 : virtual const char* what() const throw()
101 : {
102 0 : return "Illegal Data Value";
103 : }
104 : };
105 :
106 :
107 : /// Modbus Server Failure Exception
108 : /**
109 : * Server Failure
110 : *
111 : * Throwed when modbus server return error response function 0x04
112 : */
113 : class modbus_server_failure_exception: public modbus_exception {
114 : public:
115 0 : virtual const char* what() const throw()
116 : {
117 0 : return "Server Failure";
118 : }
119 : };
120 :
121 :
122 : /// Modbus Acknowledge Exception
123 : /**
124 : * Acknowledge
125 : *
126 : * Throwed when modbus server return error response function 0x05
127 : */
128 : class modbus_acknowledge_exception: public modbus_exception {
129 : public:
130 0 : virtual const char* what() const throw()
131 : {
132 0 : return "Acknowledge";
133 : }
134 : };
135 :
136 :
137 : /// Modbus Server Busy Exception
138 : /**
139 : * Server Busy
140 : *
141 : * Throwed when modbus server return error response function 0x06
142 : */
143 : class modbus_server_busy_exception: public modbus_exception {
144 : public:
145 0 : virtual const char* what() const throw()
146 : {
147 0 : return "Server Busy";
148 : }
149 : };
150 :
151 : /// Modbus Gate Way Problem Exception
152 : /**
153 : * Gate Way Problem
154 : *
155 : * Throwed when modbus server return error response function 0x0A and 0x0B
156 : */
157 : class modbus_gateway_exception: public modbus_exception {
158 : public:
159 0 : virtual const char* what() const throw()
160 : {
161 0 : return "Gateway Problem";
162 : }
163 : };
164 :
165 : /// Modbus Buffer Exception
166 : /**
167 : * Buffer Exception
168 : *
169 : * Throwed when buffer is too small for the data to be storaged.
170 : */
171 : class modbus_buffer_exception: public modbus_exception {
172 : public:
173 : virtual const char* what() const throw()
174 : {
175 : return "Size of Buffer Is too Small!";
176 : }
177 : };
178 :
179 :
180 : /// Modbus Amount Exception
181 : /**
182 : * Amount Exception
183 : *
184 : * Throwed when the address or amount input is mismatching.
185 : */
186 : class modbus_amount_exception: public modbus_exception {
187 : public:
188 0 : virtual const char* what() const throw()
189 : {
190 0 : return "Too many Data!";
191 : }
192 : };
193 :
194 :
195 :
196 : #endif //MODBUSPP_MODBUS_EXCEPTION_H
|