qpidctrl  0.7.1
qpidcommport.h
Go to the documentation of this file.
1 #ifndef QPIDCOMMPORT_H
2 #define QPIDCOMMPORT_H
3 
4 #include <QObject>
5 #include <QStringList>
6 #include <QPointer>
7 #include <QIODevice>
8 #include "qcepsettingssaver-ptr.h"
9 #include "qcepsettingssaver.h"
10 #include "qcepproperty.h"
11 #include "qpidcontroller-ptr.h"
12 #include "qextserialport.h"
13 
14 class QPidCommPort : public QObject
15 {
16  Q_OBJECT
17 public:
18  explicit QPidCommPort(QcepSettingsSaverPtr saver, QPidControllerPtr ctl);
19  virtual ~QPidCommPort();
20 
21  enum {
26  };
27 
28  virtual void writeSettings(QSettings *set, QString section);
29  virtual void readSettings(QSettings *set, QString section);
30 
31 signals:
32  void readyRead();
33 
34 public slots:
35  QStringList commPortTypes();
36  QStringList commPortBaudRates();
37  QStringList commPortDataBits();
38  QStringList commPortFlowControls();
39  QStringList commPortParitys();
40  QStringList commPortStopBits();
41 
42  BaudRateType baudRate(int idx);
43  DataBitsType dataBits(int idx);
44  FlowType flowControl(int idx);
45  StopBitsType stopBits(int idx);
46  ParityType parity(int idx);
47 
48  void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime());
49 
50 public:
51  QByteArray readAll();
52  QByteArray read(int sz);
53  QByteArray readLine(int maxlen=0);
54  bool isWritable();
55  void write(QByteArray msg);
56  int waitForBytesWritten(int tmout=0);
57  int waitForReadyRead(int tmout=0);
58  int bytesAvailable();
59  int canReadLine();
60  bool successfullyConnected();
61 
62 private:
63  bool openIfNeeded();
64  bool openLocalSerialPort();
65  bool openNetworkSocket();
66 
67 public:
68  Q_PROPERTY(int commPortType READ get_CommPortType WRITE set_CommPortType)
69  QCEP_INTEGER_PROPERTY(CommPortType)
70 
71  Q_PROPERTY(QString serialPortName READ get_SerialPortName WRITE set_SerialPortName)
72  QCEP_STRING_PROPERTY(SerialPortName)
73 
74  Q_PROPERTY(int serialPortBaud READ get_SerialPortBaud WRITE set_SerialPortBaud)
75  QCEP_INTEGER_PROPERTY(SerialPortBaud)
76 
77  Q_PROPERTY(int serialPortBits READ get_SerialPortBits WRITE set_SerialPortBits)
78  QCEP_INTEGER_PROPERTY(SerialPortBits)
79 
80  Q_PROPERTY(int serialPortParity READ get_SerialPortParity WRITE set_SerialPortParity)
81  QCEP_INTEGER_PROPERTY(SerialPortParity)
82 
83  Q_PROPERTY(int serialPortStopBits READ get_SerialPortStopBits WRITE set_SerialPortStopBits)
84  QCEP_INTEGER_PROPERTY(SerialPortStopBits)
85 
86  Q_PROPERTY(int serialPortFlowControl READ get_SerialPortFlowControl WRITE set_SerialPortFlowControl)
87  QCEP_INTEGER_PROPERTY(SerialPortFlowControl)
88 
89  Q_PROPERTY(QString socketHostAddress READ get_SocketHostAddress WRITE set_SocketHostAddress)
90  QCEP_STRING_PROPERTY(SocketHostAddress)
91 
92  Q_PROPERTY(int socketPortNumber READ get_SocketPortNumber WRITE set_SocketPortNumber)
93  QCEP_INTEGER_PROPERTY(SocketPortNumber)
94 
95  Q_PROPERTY(int socketTimeout READ get_SocketTimeout WRITE set_SocketTimeout)
96  QCEP_INTEGER_PROPERTY(SocketTimeout)
97 
98  Q_PROPERTY(QString epicsPVName READ get_EpicsPVName WRITE set_EpicsPVName)
99  QCEP_STRING_PROPERTY(EpicsPVName)
100 
101  Q_PROPERTY(int connected READ get_Connected WRITE set_Connected STORED false)
102  QCEP_INTEGER_PROPERTY(Connected)
103 
104  Q_PROPERTY(int successful READ get_Successful WRITE set_Successful STORED false)
105  QCEP_INTEGER_PROPERTY(Successful)
106 
107 private:
109  QPointer<QIODevice> m_IODevice;
110 };
111 
112 #endif // QPIDCOMMPORT_H
DataBitsType dataBits(int idx)
int socketPortNumber
Definition: qpidcommport.h:92
QStringList commPortTypes()
bool openLocalSerialPort()
QPointer< QIODevice > m_IODevice
Definition: qpidcommport.h:109
int bytesAvailable()
QStringList commPortDataBits()
QWeakPointer< QPidController > QPidControllerWPtr
QByteArray readLine(int maxlen=0)
BaudRateType baudRate(int idx)
QByteArray readAll()
QSharedPointer< QPidController > QPidControllerPtr
StopBitsType stopBits(int idx)
QString epicsPVName
Definition: qpidcommport.h:98
int waitForBytesWritten(int tmout=0)
int serialPortBaud
Definition: qpidcommport.h:74
int serialPortParity
Definition: qpidcommport.h:80
QByteArray read(int sz)
QPidControllerWPtr m_Controller
Definition: qpidcommport.h:108
virtual ~QPidCommPort()
void write(QByteArray msg)
QPidCommPort(QcepSettingsSaverPtr saver, QPidControllerPtr ctl)
Definition: qpidcommport.cpp:8
void readyRead()
bool openIfNeeded()
QString serialPortName
Definition: qpidcommport.h:71
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
int serialPortFlowControl
Definition: qpidcommport.h:86
int serialPortBits
Definition: qpidcommport.h:77
int serialPortStopBits
Definition: qpidcommport.h:83
QStringList commPortParitys()
virtual void writeSettings(QSettings *set, QString section)
virtual void readSettings(QSettings *set, QString section)
QStringList commPortStopBits()
bool successfullyConnected()
bool openNetworkSocket()
QString socketHostAddress
Definition: qpidcommport.h:89
int waitForReadyRead(int tmout=0)
QStringList commPortBaudRates()
FlowType flowControl(int idx)
ParityType parity(int idx)
QStringList commPortFlowControls()