qserialport.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /****************************************************************************
  2. **
  3. ** This file is part of the Qt Extended Opensource Package.
  4. **
  5. ** Copyright (C) 2009 Trolltech ASA.
  6. **
  7. ** Contact: Qt Extended Information (info@qtextended.org)
  8. **
  9. ** This file may be used under the terms of the GNU General Public License
  10. ** version 2.0 as published by the Free Software Foundation and appearing
  11. ** in the file LICENSE.GPL included in the packaging of this file.
  12. **
  13. ** Please review the following information to ensure GNU General Public
  14. ** Licensing requirements will be met:
  15. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html.
  16. **
  17. **
  18. ****************************************************************************/
  19. #ifndef QSERIALPORT_H
  20. #define QSERIALPORT_H
  21. #include "qserialiodevice.h"
  22. class QSerialPortPrivate;
  23. class QSerialPort : public QSerialIODevice
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit QSerialPort( const QString& device, int rate = 9600, bool trackStatus = false );
  28. ~QSerialPort();
  29. int fd() const;
  30. // Override QIODevice methods.
  31. bool open( OpenMode mode );
  32. void close();
  33. bool flush();
  34. bool waitForReadyRead(int msecs);
  35. qint64 bytesAvailable() const;
  36. // Get or set the CTS/RTS flow control mode.
  37. bool flowControl() const;
  38. void setFlowControl( bool value );
  39. bool keepOpen() const;
  40. void setKeepOpen( bool value );
  41. // Override QSerialIODevice methods.
  42. int rate() const;
  43. bool dtr() const;
  44. void setDtr( bool value );
  45. bool dsr() const;
  46. bool carrier() const;
  47. bool rts() const;
  48. void setRts( bool value );
  49. bool cts() const;
  50. void discard();
  51. bool isValid() const;
  52. QProcess *run( const QStringList& arguments, bool addPPPdOptions );
  53. // Create and open a serial device from a "device:rate" name.
  54. static QSerialPort *create( const QString& name, int defaultRate=9600,
  55. bool flowControl=false );
  56. protected:
  57. qint64 readData( char *data, qint64 maxlen );
  58. qint64 writeData( const char *data, qint64 len );
  59. private slots:
  60. void statusTimeout();
  61. void pppdStateChanged( QProcess::ProcessState state );
  62. void pppdDestroyed();
  63. private:
  64. QSerialPortPrivate *d;
  65. };
  66. #endif