|
|
@ -1,11 +1,11 @@ |
|
|
|
#ifndef _WIN_QEXTSERIALPORT_H_ |
|
|
|
#ifndef _WIN_QEXTSERIALPORT_H_ |
|
|
|
#define _WIN_QEXTSERIALPORT_H_ |
|
|
|
#define _WIN_QEXTSERIALPORT_H_ |
|
|
|
|
|
|
|
|
|
|
|
#include "qextserialbase.h" |
|
|
|
#include "qextserialbase.h" |
|
|
|
#include <windows.h> |
|
|
|
#include <windows.h> |
|
|
|
#include <QThread> |
|
|
|
#include <QThread> |
|
|
|
|
|
|
|
|
|
|
|
/* These baudrates work on windows, but are not part of the windows headers */ |
|
|
|
/* These baudrates work on windows, but are not part of the windows headers */ |
|
|
|
#ifndef CBR_230400 |
|
|
|
#ifndef CBR_230400 |
|
|
|
#define CBR_230400 230400 |
|
|
|
#define CBR_230400 230400 |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -13,135 +13,135 @@ |
|
|
|
#define CBR_460800 460800 |
|
|
|
#define CBR_460800 460800 |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#ifndef CBR_921600 |
|
|
|
#ifndef CBR_921600 |
|
|
|
#define CBR_921600 921600 |
|
|
|
#define CBR_921600 921600 |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/ |
|
|
|
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/ |
|
|
|
#ifdef _TTY_NOWARN_ |
|
|
|
#ifdef _TTY_NOWARN_ |
|
|
|
#define _TTY_NOWARN_PORT_ |
|
|
|
#define _TTY_NOWARN_PORT_ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
class QReadWriteLock; |
|
|
|
class QReadWriteLock; |
|
|
|
class Win_QextSerialThread; |
|
|
|
class Win_QextSerialThread; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
\author Stefan Sander |
|
|
|
\author Stefan Sander |
|
|
|
\author Michal Policht |
|
|
|
\author Michal Policht |
|
|
|
|
|
|
|
|
|
|
|
A cross-platform serial port class. |
|
|
|
A cross-platform serial port class. |
|
|
|
This class encapsulates the Windows portion of QextSerialPort. The user will be notified of |
|
|
|
This class encapsulates the Windows portion of QextSerialPort. The user will be notified of |
|
|
|
errors and possible portability conflicts at run-time by default - this behavior can be turned |
|
|
|
errors and possible portability conflicts at run-time by default - this behavior can be turned |
|
|
|
off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off |
|
|
|
off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off |
|
|
|
portability warnings) in the project. Note that defining _TTY_NOWARN_ also defines |
|
|
|
portability warnings) in the project. Note that defining _TTY_NOWARN_ also defines |
|
|
|
_TTY_NOWARN_PORT_. |
|
|
|
_TTY_NOWARN_PORT_. |
|
|
|
|
|
|
|
|
|
|
|
\note |
|
|
|
\note |
|
|
|
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may |
|
|
|
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may |
|
|
|
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can |
|
|
|
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can |
|
|
|
make no guarantees as to the quality of POSIX support under NT/2000 however. |
|
|
|
make no guarantees as to the quality of POSIX support under NT/2000 however. |
|
|
|
|
|
|
|
|
|
|
|
\todo remove copy constructor and assign operator. |
|
|
|
\todo remove copy constructor and assign operator. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Win_QextSerialPort: public QextSerialBase
|
|
|
|
class Win_QextSerialPort: public QextSerialBase
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_OBJECT |
|
|
|
Q_OBJECT |
|
|
|
friend class Win_QextSerialThread; |
|
|
|
friend class Win_QextSerialThread; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* This method is a part of constructor. |
|
|
|
* This method is a part of constructor. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void init(); |
|
|
|
void init(); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
HANDLE Win_Handle; |
|
|
|
HANDLE Win_Handle; |
|
|
|
HANDLE threadStartEvent; |
|
|
|
HANDLE threadStartEvent; |
|
|
|
HANDLE threadTerminateEvent; |
|
|
|
HANDLE threadTerminateEvent; |
|
|
|
OVERLAPPED overlap; |
|
|
|
OVERLAPPED overlap; |
|
|
|
OVERLAPPED overlapWrite; |
|
|
|
OVERLAPPED overlapWrite; |
|
|
|
COMMCONFIG Win_CommConfig; |
|
|
|
COMMCONFIG Win_CommConfig; |
|
|
|
COMMTIMEOUTS Win_CommTimeouts; |
|
|
|
COMMTIMEOUTS Win_CommTimeouts; |
|
|
|
QReadWriteLock * bytesToWriteLock; ///< @todo maybe move to QextSerialBase.
|
|
|
|
QReadWriteLock * bytesToWriteLock; ///< @todo maybe move to QextSerialBase.
|
|
|
|
qint64 _bytesToWrite; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
|
|
|
|
qint64 _bytesToWrite; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
|
|
|
|
Win_QextSerialThread * overlapThread; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
|
|
|
|
Win_QextSerialThread * overlapThread; ///< @todo maybe move to QextSerialBase (and implement in POSIX).
|
|
|
|
|
|
|
|
|
|
|
|
void monitorCommEvent(); |
|
|
|
void monitorCommEvent(); |
|
|
|
void terminateCommWait(); |
|
|
|
void terminateCommWait(); |
|
|
|
virtual qint64 readData(char *data, qint64 maxSize); |
|
|
|
virtual qint64 readData(char *data, qint64 maxSize); |
|
|
|
virtual qint64 writeData(const char *data, qint64 maxSize); |
|
|
|
virtual qint64 writeData(const char *data, qint64 maxSize); |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
Win_QextSerialPort(QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(Win_QextSerialPort const& s); |
|
|
|
Win_QextSerialPort(Win_QextSerialPort const& s); |
|
|
|
Win_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(const QString & name, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(const PortSettings& settings, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort(const QString & name, const PortSettings& settings, QextSerialBase::QueryMode mode); |
|
|
|
Win_QextSerialPort& operator=(const Win_QextSerialPort& s); |
|
|
|
Win_QextSerialPort& operator=(const Win_QextSerialPort& s); |
|
|
|
virtual ~Win_QextSerialPort(); |
|
|
|
virtual ~Win_QextSerialPort(); |
|
|
|
virtual bool open(OpenMode mode); |
|
|
|
virtual bool open(OpenMode mode); |
|
|
|
virtual void close(); |
|
|
|
virtual void close(); |
|
|
|
virtual void flush(); |
|
|
|
virtual void flush(); |
|
|
|
virtual qint64 size() const; |
|
|
|
virtual qint64 size() const; |
|
|
|
virtual void ungetChar(char c); |
|
|
|
virtual void ungetChar(char c); |
|
|
|
virtual void setFlowControl(FlowType); |
|
|
|
virtual void setFlowControl(FlowType); |
|
|
|
virtual void setParity(ParityType); |
|
|
|
virtual void setParity(ParityType); |
|
|
|
virtual void setDataBits(DataBitsType); |
|
|
|
virtual void setDataBits(DataBitsType); |
|
|
|
virtual void setStopBits(StopBitsType); |
|
|
|
virtual void setStopBits(StopBitsType); |
|
|
|
virtual void setBaudRate(BaudRateType); |
|
|
|
virtual void setBaudRate(BaudRateType); |
|
|
|
virtual void setDtr(bool set=true); |
|
|
|
virtual void setDtr(bool set=true); |
|
|
|
virtual void setRts(bool set=true); |
|
|
|
virtual void setRts(bool set=true); |
|
|
|
virtual ulong lineStatus(void); |
|
|
|
virtual ulong lineStatus(void); |
|
|
|
virtual qint64 bytesAvailable() const; |
|
|
|
virtual qint64 bytesAvailable() const; |
|
|
|
virtual void translateError(ulong); |
|
|
|
virtual void translateError(ulong); |
|
|
|
virtual void setTimeout(long); |
|
|
|
virtual void setTimeout(long); |
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* Return number of bytes waiting in the buffer. Currently this shows number
|
|
|
|
* Return number of bytes waiting in the buffer. Currently this shows number
|
|
|
|
* of bytes queued within write() and before the TX_EMPTY event occured. TX_EMPTY |
|
|
|
* of bytes queued within write() and before the TX_EMPTY event occured. TX_EMPTY |
|
|
|
* event is created whenever last character in the system buffer was sent. |
|
|
|
* event is created whenever last character in the system buffer was sent. |
|
|
|
*
|
|
|
|
*
|
|
|
|
* \return number of bytes queued within write(), before the first TX_EMPTY
|
|
|
|
* \return number of bytes queued within write(), before the first TX_EMPTY
|
|
|
|
* event occur. |
|
|
|
* event occur. |
|
|
|
*
|
|
|
|
*
|
|
|
|
* \warning this function may not give you expected results since TX_EMPTY may occur
|
|
|
|
* \warning this function may not give you expected results since TX_EMPTY may occur
|
|
|
|
* while writing data to the buffer. Eventually some TX_EMPTY events may not be |
|
|
|
* while writing data to the buffer. Eventually some TX_EMPTY events may not be |
|
|
|
* catched. |
|
|
|
* catched. |
|
|
|
*
|
|
|
|
*
|
|
|
|
* \note this function always returns 0 in polling mode. |
|
|
|
* \note this function always returns 0 in polling mode. |
|
|
|
*
|
|
|
|
*
|
|
|
|
* \see flush(). |
|
|
|
* \see flush(). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
virtual qint64 bytesToWrite() const; |
|
|
|
virtual qint64 bytesToWrite() const; |
|
|
|
|
|
|
|
|
|
|
|
virtual bool waitForReadyRead(int msecs); ///< @todo implement.
|
|
|
|
virtual bool waitForReadyRead(int msecs); ///< @todo implement.
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* This thread monitors communication events. |
|
|
|
* This thread monitors communication events. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Win_QextSerialThread: public QThread |
|
|
|
class Win_QextSerialThread: public QThread |
|
|
|
{ |
|
|
|
{ |
|
|
|
Win_QextSerialPort * qesp; |
|
|
|
Win_QextSerialPort * qesp; |
|
|
|
bool terminate; |
|
|
|
bool terminate; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* Constructor. |
|
|
|
* Constructor. |
|
|
|
*
|
|
|
|
*
|
|
|
|
* \param qesp valid serial port object. |
|
|
|
* \param qesp valid serial port object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Win_QextSerialThread(Win_QextSerialPort * qesp); |
|
|
|
Win_QextSerialThread(Win_QextSerialPort * qesp); |
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
/*!
|
|
|
|
* Stop the thread. |
|
|
|
* Stop the thread. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void stop(); |
|
|
|
void stop(); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
//overriden
|
|
|
|
//overriden
|
|
|
|
virtual void run(); |
|
|
|
virtual void run(); |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|