C++ (Qt)/* License...*/ #ifndef SERIALPORT_H#define SERIALPORT_H #include <QtCore/QIODevice> class SerialPortPrivate; class QSERIALDEVICE_EXPORT SerialPort : public QIODevice{ Q_OBJECT Q_PROPERTY(Rate rate READ rate WRITE setRate) Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits) Q_PROPERTY(Parity parity READ parity WRITE setParity) Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits) Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl) Q_PROPERTY(DataErrorPolicy dataErrorPolicy READ dataErrorPolicy WRITE setDataErrorPolicy) Q_PROPERTY(bool dtr READ dtr WRITE setDtr) Q_PROPERTY(bool rts READ rts WRITE setRts) Q_PROPERTY(SerialError error READ error RESET unsetError) Q_ENUMS( Directions Rate DataBits Parity StopBits FlowControl Lines DataErrorPolicy SerialError ) public: enum Direction { Input = 1, Output = 2 }; Q_DECLARE_FLAGS(Directions, Direction) enum Rate { Rate1200 = 1200, Rate2400 = 2400, Rate4800 = 4800, Rate9600 = 9600, Rate19200 = 19200, Rate38400 = 38400, Rate57600 = 57600, Rate115200 = 115200, UnknownRate = -1 }; enum DataBits { Data5 = 5, Data6 = 6, Data7 = 7, Data8 = 8, UnknownDataBits = -1 }; enum Parity { NoParity = 0, EvenParity = 2, OddParity = 3, SpaceParity = 4, MarkParity = 5, UnknownParity = -1 }; enum StopBits { OneStop = 1, OneAndHalfStop = 3, TwoStop = 2, UnknownStopBits = -1 }; enum FlowControl { NoFlowControl, HardwareControl, SoftwareControl, UnknownFlowControl = -1 }; enum Line { Le = 0x01, Dtr = 0x02, Rts = 0x04, St = 0x08, Sr = 0x10, Cts = 0x20, Dcd = 0x40, Ri = 0x80, Dsr = Le }; Q_DECLARE_FLAGS(Lines, Line) enum DataErrorPolicy { SkipPolicy, PassZeroPolicy, IgnorePolicy, StopReceivingPolicy }; enum SerialError { NoError, NoSuchDeviceError, PermissionDeniedError, DeviceAlreadyOpenedError, DeviceIsNotOpenedError, ParityError, IoError }; explicit SerialPort(QObject *parent = 0); explicit SerialPort(const QString &name, QObject *parent = 0); explicit SerialPort(const SerialPortInfo &info, QObject *parent = 0); virtual ~SerialPort(); void setName(const QString &name); // << Имена только: "COM1", "ttyS0" !!! QString name() const; // << Имена только: "COM1", "ttyS0" !!! void setPort(const SerialPortInfo &info); virtual bool open(OpenMode mode); virtual void close(); bool setRate(qint32 rate, Directions dir = Input | Output); qint32 rate(Directions dir = Input | Output) const; bool setDataBits(DataBits dataBits); DataBits dataBits() const; bool setParity(Parity parity); Parity parity() const; bool setStopBits(StopBits stopBits); StopBits stopBits() const; bool setFlowControl(FlowControl flow); FlowControl flowControl() const; void setDataInterval(int usecs = 0); int dataInterval() const; void setReadTimeout(int msecs = 0); int readTimeout() const; bool dtr() const; bool rts() const; Lines lines() const; bool flush(); virtual bool reset(); void setDataErrorPolicy(DataErrorPolicy policy = IgnorePolicy); DataErrorPolicy dataErrorPolicy() const; SerialError error() const; void unsetError(); virtual bool isSequential() const; virtual qint64 bytesAvailable() const; virtual qint64 bytesToWrite() const; virtual bool waitForReadyRead(int msecs); virtual bool waitForBytesWritten(int msecs); public Q_SLOTS: bool setDtr(bool set); bool setRts(bool set); bool sendBreak(int duration = 0); bool setBreak(bool set = true); bool clearBreak(bool clear = true); protected: virtual qint64 readData(char *data, qint64 maxSize); virtual qint64 writeData(const char *data, qint64 maxSize); private: SerialPortPrivate * const d_ptr; Q_DECLARE_PRIVATE(SerialPort) Q_DISABLE_COPY(SerialPort)}; inline bool SerialPort::clearBreak(bool clear){ return setBreak(!clear); } Q_DECLARE_OPERATORS_FOR_FLAGS(SerialPort::Directions)Q_DECLARE_OPERATORS_FOR_FLAGS(SerialPort::Lines) #endif // SERIALPORT_H
C++ (Qt)/* License...*/ #ifndef SERIALPORTINFO_H#define SERIALPORTINFO_H class SerialPort;class SerialPortInfoPrivate; class QSERIALDEVICE_EXPORT SerialPortInfo{public: SerialPortInfo(); //produces NULL info SerialPortInfo(const SerialPortInfo &other); //copy constructor explicit SerialPortInfo(const SerialPort &port); SerialPortInfo& operator=(const SerialPortInfo &other); void swap(SerialPortInfo &other); QString name() const; // << Имена только: "COM1", "ttyS0" !!! QString systemLocation() const; // << Системный путь только: "\\\\\\\\.\\\\COM24", "/dev/ttyS45" !!! QString description() const; // << Описание: "Последовательный порт", "Prolific USB-to-Serial Comm Port", "Motorola Phone (E1 iTunes)" QString manufacturer() const; // << Производитель: "(Стандартные порты)", "Prolific Technology Inc." bool isNull() const; bool isBusy() const; QList<int> standardRates() const; static QList<SerialPortInfo> availablePorts();private: Q_DECLARE_PRIVATE(SerialPortInfo) SerialPortInfoPrivate * const d_ptr;}; #endif // SERIALPORTINFO_H
C++ (Qt)/* License...*/ #ifndef SERIALPORT_H#define SERIALPORT_H #include <QtCore/QIODevice> class SerialPortPrivate; class QSERIALPORT_EXPORT SerialPort : public QIODevice{ Q_OBJECT Q_PROPERTY(Rate rate READ rate WRITE setRate) Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits) Q_PROPERTY(Parity parity READ parity WRITE setParity) Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits) Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl) Q_PROPERTY(DataErrorPolicy dataErrorPolicy READ dataErrorPolicy WRITE setDataErrorPolicy) Q_PROPERTY(bool dtr READ dtr WRITE setDtr) Q_PROPERTY(bool rts READ rts WRITE setRts) Q_PROPERTY(SerialError error READ error RESET unsetError) Q_ENUMS( Directions Rate DataBits Parity StopBits FlowControl Lines DataErrorPolicy SerialError ) public: enum Direction { Input = 1, Output = 2 }; Q_DECLARE_FLAGS(Directions, Direction) enum Rate { Rate1200 = 1200, Rate2400 = 2400, Rate4800 = 4800, Rate9600 = 9600, Rate19200 = 19200, Rate38400 = 38400, Rate57600 = 57600, Rate115200 = 115200, UnknownRate = -1 }; enum DataBits { Data5 = 5, Data6 = 6, Data7 = 7, Data8 = 8, UnknownDataBits = -1 }; enum Parity { NoParity = 0, EvenParity = 2, OddParity = 3, SpaceParity = 4, MarkParity = 5, UnknownParity = -1 }; enum StopBits { OneStop = 1, OneAndHalfStop = 3, TwoStop = 2, UnknownStopBits = -1 }; enum FlowControl { NoFlowControl, HardwareControl, SoftwareControl, UnknownFlowControl = -1 }; enum Line { Le = 0x01, Dtr = 0x02, Rts = 0x04, St = 0x08, Sr = 0x10, Cts = 0x20, Dcd = 0x40, Ri = 0x80, Dsr = Le }; Q_DECLARE_FLAGS(Lines, Line) enum DataErrorPolicy { SkipPolicy, PassZeroPolicy, IgnorePolicy, StopReceivingPolicy }; enum SerialError { NoError, NoSuchDeviceError, PermissionDeniedError, DeviceAlreadyOpenedError, DeviceIsNotOpenedError, ParityError, IoError }; explicit SerialPort(QObject *parent = 0); explicit SerialPort(const QString &name, QObject *parent = 0); explicit SerialPort(const SerialPortInfo &info, QObject *parent = 0); virtual ~SerialPort(); void setPortName(const QString &name); // << Имена только: "COM1", "ttyS0" !!! QString portName() const; // << Имена только: "COM1", "ttyS0" !!! void setPort(const SerialPortInfo &info); virtual bool open(OpenMode mode); virtual void close(); bool setRate(qint32 rate, Directions dir = Input | Output); qint32 rate(Directions dir = Input | Output) const; bool setDataBits(DataBits dataBits); DataBits dataBits() const; bool setParity(Parity parity); Parity parity() const; bool setStopBits(StopBits stopBits); StopBits stopBits() const; bool setFlowControl(FlowControl flow); FlowControl flowControl() const; void setDataInterval(int usecs); int dataInterval() const; void setReadTimeout(int msecs); int readTimeout() const; bool dtr() const; bool rts() const; Lines lines() const; bool flush(); virtual bool reset(); void setDataErrorPolicy(DataErrorPolicy policy = IgnorePolicy); DataErrorPolicy dataErrorPolicy() const; SerialError error() const; void unsetError(); virtual bool isSequential() const; virtual qint64 bytesAvailable() const; virtual qint64 bytesToWrite() const; virtual bool waitForReadyRead(int msecs); virtual bool waitForBytesWritten(int msecs); public Q_SLOTS: bool setDtr(bool set); bool setRts(bool set); bool sendBreak(int duration = 0); bool setBreak(bool set = true); bool clearBreak(bool clear = true); protected: virtual qint64 readData(char *data, qint64 maxSize); virtual qint64 writeData(const char *data, qint64 maxSize); private: SerialPortPrivate * const d_ptr; Q_DECLARE_PRIVATE(SerialPort) Q_DISABLE_COPY(SerialPort)}; inline bool SerialPort::clearBreak(bool clear){ return setBreak(!clear); } Q_DECLARE_OPERATORS_FOR_FLAGS(SerialPort::Directions)Q_DECLARE_OPERATORS_FOR_FLAGS(SerialPort::Lines) #endif // SERIALPORT_H
C++ (Qt)/* License...*/ #ifndef SERIALPORTINFO_H#define SERIALPORTINFO_H class SerialPort;class SerialPortInfoPrivate; class QSERIALPORT_EXPORT SerialPortInfo{public: SerialPortInfo(); //produces NULL info SerialPortInfo(const SerialPortInfo &other); //copy constructor explicit SerialPortInfo(const SerialPort &port); virtual ~SerialPortInfo(); SerialPortInfo& operator=(const SerialPortInfo &other); void swap(SerialPortInfo &other); QString portName() const; // << Имена только: "COM1", "ttyS0" !!! QString systemLocation() const; // << Системный путь только: "\\\\\\\\.\\\\COM24", "/dev/ttyS45" !!! QString description() const; // << Описание: "Последовательный порт", "Prolific USB-to-Serial Comm Port", "Motorola Phone (E1 iTunes)" QString manufacturer() const; // << Производитель: "(Стандартные порты)", "Prolific Technology Inc." bool isNull() const; bool isBusy() const; bool isExists() const; // << Если порт фактически существует QList<int> standardRates() const; static QList<SerialPortInfo> availablePorts();private: Q_DECLARE_PRIVATE(SerialPortInfo) SerialPortInfoPrivate * const d_ptr;}; #endif // SERIALPORTINFO_H
C++ (Qt)class LineNotifier: public QTimer{ Q_OBJECT .... ....Q_SIGNALS: void linesState(Lines l, int fd); public Q_SLOTS: .... void addDescriptor(int fd); void removeDescriptor(int fd); private: QList<int> descriptorsList;};