C++ (Qt)#include "serialport.h"
C++ (Qt)#include "serialportinfo.h"
C++ (Qt)/* License...*/ #ifndef SERIALPORT_P_H#define SERIALPORT_P_H #include "serialport.h" #if defined (Q_OS_WIN)# include <qt_windows.h>#else# include <termios.h>//# include "../unix/ttylocker.h"#endif class SerialPortPrivate{public: SerialPortPrivate(); virtual ~SerialPortPrivate(); void setNativePort(const QString &port); QString nativePort() const; bool nativeOpen(QIODevice::OpenMode mode); void nativeClose(); bool nativeSetRate(qint32 rate, SerialPort::Directions dir); qint32 nativeRate(SerialPort::Directions dir) const; bool nativeSetDataBits(SerialPort::DataBits dataBits); SerialPort::DataBits nativeDataBits() const; bool nativeSetParity(SerialPort::Parity parity); SerialPort::Parity nativeParity() const; bool nativeSetStopBits(SerialPort::StopBits stopBits); SerialPort::StopBits nativeStopBits() const; bool nativeSetFlowControl(SerialPort::FlowControl flow); SerialPort::FlowControl nativeFlowControl() const; void nativeSetDataInterval(int usecs); int nativeDataInterval() const; void nativeSetReadTimeout(int msecs); int nativeReadTimeout() const; bool nativeDtr() const; bool nativeRts() const; SerialPort::Lines nativeLines() const; bool nativeFlush(); bool nativeReset(); void nativeSetDataErrorPolicy(SerialPort::DataErrorPolicy policy); SerialPort::DataErrorPolicy nativeDataErrorPolicy() const; SerialPort::PortError nativeError() const; void nativeUunsetError(); qint64 nativeBytesAvailable() const; qint64 nativeRead(char *data, qint64 len); qint64 nativeWrite(const char *data, qint64 len); int nativeSelect(int timeout, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite); private: //General (for any OS) private parameters QString mPort; qint32 mInRate; qint32 mOutRate; SerialPort::DataBits mDataBits; SerialPort::Parity mParity; SerialPort::StopBits mStopBits; SerialPort::FlowControl mFlow; int mDataInterval; int mReadTimeout; SerialPort::DataErrorPolicy mPolicy; SerialPort::PortError mError; //General (for any OS) private methods void initVariables(); void detectDefaultRate(); void detectDefaultDataBits(); void detectDefaultParity(); void detectDefaultStopBits(); void detectDefaultFlowControl(); void detectDefaultCurrentSettings(); bool prepareOtherOptions(); bool saveOldSettings(); bool restoreOldSettings(); //OS specific parameters and methods#ifdef Q_OS_WIN enum CommTimeouts { ReadIntervalTimeout, ReadTotalTimeoutMultiplier, ReadTotalTimeoutConstant, WriteTotalTimeoutMultiplier, WriteTotalTimeoutConstant }; DCB mDCB, mOldDCB; COMMTIMEOUTS mCommTimeouts, mOldCommTimeouts; OVERLAPPED mOvRead; OVERLAPPED mOvWrite; OVERLAPPED mOvSelect; bool createEvents(bool rx, bool tx); bool closeEvents() const; void recalcTotalReadTimeoutConstant(); void prepareCommTimeouts(CommTimeouts cto, DWORD msecs); bool updateDcb(); bool updateCommTimeouts();#else struct termios mTermios; struct termios mOldTermios; void prepareTimeouts(int msecs); bool updateTermious(); bool setStandartRate(AbstractSerial::BaudRateDirection, speed_t rate); bool setCustomRate(qint32 rate);#endif }; #endif // SERIALPORT_P_H
C++ (Qt)struct SerialPortInfoPrivate{ QString device; QString portName; QString manufacturer; virtual bool isValid() = 0;};