BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
microcontexception.cpp
Go to the documentation of this file.
1 /*! \file
2  * \brief Exception thrown by the MCInterface class
3  * \author Benjamin Pritchard (ben@bennyp.org)
4  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
5  */
6 
7 
8 #include <iostream>
9 #include <string>
10 #include <stdexcept>
11 #include <exception>
12 
13 #include <QApplication>
14 #include <QMessageBox>
15 #include <QString>
16 #include <QtSerialPort/QSerialPort>
17 #include <QtSerialPort/QSerialPortInfo>
18 
19 #include "microcontexception.h"
20 #include "commands-text.h"
21 
22 using namespace std;
23 
25  int mcerror,
26  int mcerrorcmd,
27  int mcerrorid,
28  QSerialPort::SerialPortError sperror)
29  : runtime_error(desc.toStdString())
30 {
31  _mcerror = mcerror;
32  _mcerrorid = mcerrorid;
33  _mcerrorcmd = mcerrorcmd;
34  _sperror = sperror;
35 }
36 
38  int mcerror,
39  QSerialPort::SerialPortError sperror)
40  : runtime_error(desc.toStdString())
41 {
42  _mcerror = mcerror;
43  _mcerrorid = _mcerrorcmd = -1;
44  _sperror = sperror;
45 }
46 
48 {
49  return _mcerror;
50 }
51 
53 {
54  return _mcerrorid;
55 }
56 
58 {
59  return _mcerrorcmd;
60 }
61 
62 QSerialPort::SerialPortError MCInterfaceException::GetSPError(void) const
63 {
64  return _sperror;
65 }
66 
67 const char * MCInterfaceException::GetSPErrorText(void) const
68 {
69  switch (_sperror)
70  {
71  case QSerialPort::NoError:
72  return "No error";
73  case QSerialPort::DeviceNotFoundError:
74  return "No such device";
75  case QSerialPort::PermissionError:
76  return "Permission Denied: Possibly already opened by another process";
77  case QSerialPort::OpenError:
78  return "Device already opened";
79  case QSerialPort::ParityError:
80  return "Hardware detected a parity error";
81  case QSerialPort::FramingError:
82  return "Framing Error";
83  case QSerialPort::BreakConditionError:
84  return "Break Condition Error";
85  case QSerialPort::WriteError:
86  return "I/O Error occurred while writing the data";
87  case QSerialPort::ReadError:
88  return "I/O Error occurred while reading the data";
89  case QSerialPort::ResourceError:
90  return "I/O error: resource unavailable";
91  case QSerialPort::UnsupportedOperationError:
92  return "Unsupported operation error";
93  case QSerialPort::UnknownError:
94  return "Unsupported operation error";
95  default:
96  return "Unknown error";
97  }
98 }