| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,54 @@ |
| 1 |
+/* |
|
| 2 |
+ * Author: Pawel Jablonski |
|
| 3 |
+ * E-mail: pj@xirx.net |
|
| 4 |
+ * WWW: xirx.net |
|
| 5 |
+ * GIT: git.xirx.net |
|
| 6 |
+ * |
|
| 7 |
+ * License: You can use this code however you like |
|
| 8 |
+ * but leave information about the original author. |
|
| 9 |
+ * Code is free for non-commercial and commercial use. |
|
| 10 |
+ */ |
|
| 11 |
+ |
|
| 12 |
+#ifndef RS232_H |
|
| 13 |
+#define RS232_H |
|
| 14 |
+ |
|
| 15 |
+#include <QObject> |
|
| 16 |
+#include <QString> |
|
| 17 |
+#include <QList> |
|
| 18 |
+ |
|
| 19 |
+//! This class contains RS232 functions |
|
| 20 |
+class RS232 : public QObject |
|
| 21 |
+{
|
|
| 22 |
+ Q_OBJECT |
|
| 23 |
+ |
|
| 24 |
+ public: |
|
| 25 |
+ static const int BUFFER_RX_SIZE = 64; //!< Receive buffer size |
|
| 26 |
+ static const int BUFFER_TX_SIZE = 64; //!< Transmit buffer size |
|
| 27 |
+ |
|
| 28 |
+ static const int SEND_MASK = 0x7f; //!< Mask to make a basic ASCII char set |
|
| 29 |
+ |
|
| 30 |
+ static const int MAX_CODE = 0x7f; //!< Maximum allowed ASCII char |
|
| 31 |
+ static const int MIN_CODE = 0x20; //!< Minimum allowed ASCII char |
|
| 32 |
+ |
|
| 33 |
+ RS232(QObject *parent = nullptr); |
|
| 34 |
+ |
|
| 35 |
+ void reset(); |
|
| 36 |
+ |
|
| 37 |
+ void rx(const QString &text); |
|
| 38 |
+ |
|
| 39 |
+ void send(unsigned char c); |
|
| 40 |
+ unsigned char receive(); |
|
| 41 |
+ |
|
| 42 |
+ unsigned char getSendBufferFree(); |
|
| 43 |
+ |
|
| 44 |
+ private: |
|
| 45 |
+ QList<unsigned char> rxBuffer; //!< Receive buffer |
|
| 46 |
+ |
|
| 47 |
+ signals: |
|
| 48 |
+ void updateTxSignal(unsigned char c); |
|
| 49 |
+ void updateRxSignal(unsigned char c); |
|
| 50 |
+ |
|
| 51 |
+ void dataReadySignal(bool ready); |
|
| 52 |
+}; |
|
| 53 |
+ |
|
| 54 |
+#endif |