UniSet  2.6.0
ModbusRTUErrors.h
1 #ifndef ModbusRTUErrors_H_
2 #define ModbusRTUErrors_H_
3 // -------------------------------------------------------------------------
4 #include <string>
5 #include <iostream>
6 #include "Exceptions.h"
7 // -------------------------------------------------------------------------
8 namespace uniset
9 {
10  // -------------------------------------------------------------------------
11  namespace ModbusRTU
12  {
16  enum mbErrCode
17  {
18  erNoError = 0,
19  erUnExpectedPacketType = 1,
20  erBadDataAddress = 2,
21  erBadDataValue = 3,
22  erHardwareError = 4,
23  erAnknowledge = 5,
24  erSlaveBusy = 6,
25  erOperationFailed = 7,
26  erMemoryParityError = 8,
28  erInternalErrorCode = 10,
29  erInvalidFormat = 11,
30  erBadCheckSum = 12,
31  erBadReplyNodeAddress = 13,
32  erTimeOut = 14,
33  erPacketTooLong = 15,
34  erSessionClosed = 16
35  };
36 
37  // ---------------------------------------------------------------------
38  std::string mbErr2Str( mbErrCode e );
39  // ---------------------------------------------------------------------
40  class mbException:
41  public uniset::Exception
42  {
43  public:
44  mbException():
45  uniset::Exception("mbException"), err(ModbusRTU::erNoError) {}
46  mbException( ModbusRTU::mbErrCode err ):
47  uniset::Exception(mbErr2Str(err)), err(err) {}
48 
49 
50  ModbusRTU::mbErrCode err;
51 
52  friend std::ostream& operator<<(std::ostream& os, mbException& ex )
53  {
54  return os << "(" << ex.err << ") " << mbErr2Str(ex.err);
55  }
56  };
57  // ---------------------------------------------------------------------
58  } // end of namespace ModbusRTU
59  // -------------------------------------------------------------------------
60 } // end of namespace uniset
61 // -------------------------------------------------------------------------
62 #endif // ModbusRTUErrors_H_
63 // -------------------------------------------------------------------------
Definition: CallbackTimer.h:29
Definition: Exceptions.h:44
Definition: ModbusRTUErrors.h:40