[120] | 1 | /*********************************************************************
|
---|
| 2 | // created: 2013/07/10
|
---|
| 3 | // filename: PacpusSerialPort.h
|
---|
| 4 | //
|
---|
| 5 | // author: Julien Moras
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: This class defines a Qt 5.1 driver for serial port
|
---|
| 10 | *********************************************************************/
|
---|
| 11 | #ifndef _PacpusSerialPort_H_
|
---|
| 12 | #define _PacpusSerialPort_H_
|
---|
| 13 |
|
---|
| 14 | #include <QtSerialPort/QSerialPort>
|
---|
| 15 | #include <QtSerialPort/QSerialPortInfo>
|
---|
| 16 | #include <QThread>
|
---|
| 17 |
|
---|
| 18 | #include <Pacpus/kernel/ComponentBase.h>
|
---|
| 19 |
|
---|
| 20 | namespace pacpus {
|
---|
| 21 |
|
---|
| 22 | class PacpusSerialPort : public QObject, public ComponentBase
|
---|
| 23 | {
|
---|
| 24 | Q_OBJECT
|
---|
| 25 |
|
---|
| 26 | public:
|
---|
| 27 |
|
---|
| 28 | typedef enum { ASCII, BINARY } DataMode;
|
---|
| 29 |
|
---|
| 30 | PacpusSerialPort(QString name);
|
---|
| 31 | ~PacpusSerialPort();
|
---|
| 32 |
|
---|
| 33 | protected:
|
---|
| 34 | void startActivity(); /*!< to start the processing thread */
|
---|
| 35 | void stopActivity(); /*!< to stop the processing thread */
|
---|
| 36 | ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
| 37 |
|
---|
| 38 | void addInput();
|
---|
| 39 | void addOutput();
|
---|
| 40 | void processInputFrame(const QByteArray &);
|
---|
| 41 |
|
---|
| 42 | private Q_SLOTS :
|
---|
| 43 | void readData();
|
---|
| 44 |
|
---|
| 45 | private:
|
---|
| 46 |
|
---|
| 47 | QThread thread_;
|
---|
| 48 |
|
---|
| 49 | QSerialPort * serialPort;
|
---|
| 50 |
|
---|
| 51 | QString portName;
|
---|
| 52 | QSerialPort::Direction direction;
|
---|
| 53 | QSerialPort::BaudRate baudRate;
|
---|
| 54 | QSerialPort::DataBits dataBits;
|
---|
| 55 | QSerialPort::Parity parity;
|
---|
| 56 | QSerialPort::StopBits stopBits;
|
---|
| 57 | QSerialPort::FlowControl flowControl;
|
---|
| 58 | QSerialPort::DataErrorPolicy errorPolicy;
|
---|
| 59 | DataMode dataMode;
|
---|
| 60 |
|
---|
| 61 | QByteArray buffer;
|
---|
| 62 |
|
---|
| 63 | QString sepChar;
|
---|
[121] | 64 | QString startChar;
|
---|
| 65 | QString stopChar;
|
---|
[120] | 66 |
|
---|
[122] | 67 | int minPacketSize;
|
---|
[120] | 68 |
|
---|
[122] | 69 | bool log;
|
---|
| 70 |
|
---|
| 71 |
|
---|
[120] | 72 | };
|
---|
| 73 |
|
---|
| 74 | } // end namespace
|
---|
| 75 |
|
---|
| 76 | #endif
|
---|