#include <qextserialbase.h>
Inheritance diagram for QextSerialBase:
Public Member Functions | |
QextSerialBase () | |
QextSerialBase (const QString &name) | |
virtual | ~QextSerialBase () |
virtual void | construct () |
virtual void | setPortName (const QString &name) |
virtual QString | portName () const |
virtual void | setBaudRate (BaudRateType)=0 |
virtual BaudRateType | baudRate () const |
virtual void | setDataBits (DataBitsType)=0 |
virtual DataBitsType | dataBits () const |
virtual void | setParity (ParityType)=0 |
virtual ParityType | parity () const |
virtual void | setStopBits (StopBitsType)=0 |
virtual StopBitsType | stopBits () const |
virtual void | setFlowControl (FlowType)=0 |
virtual FlowType | flowControl () const |
virtual void | setTimeout (ulong, ulong)=0 |
virtual bool | open (OpenMode mode=0)=0 |
virtual void | close ()=0 |
virtual void | flush ()=0 |
virtual qint64 | size () const =0 |
virtual qint64 | bytesAvailable ()=0 |
virtual bool | atEnd () const |
virtual void | ungetChar (char c)=0 |
virtual qint64 | readLine (char *data, qint64 maxSize) |
virtual ulong | lastError () const |
virtual void | translateError (ulong error)=0 |
virtual void | setDtr (bool set=true)=0 |
virtual void | setRts (bool set=true)=0 |
virtual ulong | lineStatus ()=0 |
Protected Member Functions | |
virtual qint64 | readData (char *data, qint64 maxSize)=0 |
virtual qint64 | writeData (const char *data, qint64 maxSize)=0 |
Protected Attributes | |
QString | port |
PortSettings | Settings |
ulong | lastErr |
Static Protected Attributes | |
static QMutex * | mutex = NULL |
static ulong | refCount = 0 |
QextSerialBase::QextSerialBase | ( | ) |
Default constructor.
00021 : QIODevice() 00022 { 00023 00024 #ifdef _TTY_WIN_ 00025 setPortName("COM1"); 00026 00027 #elif defined(_TTY_IRIX_) 00028 setPortName("/dev/ttyf1"); 00029 00030 #elif defined(_TTY_HPUX_) 00031 setPortName("/dev/tty1p0"); 00032 00033 #elif defined(_TTY_SUN_) 00034 setPortName("/dev/ttya"); 00035 00036 #elif defined(_TTY_DIGITAL_) 00037 setPortName("/dev/tty01"); 00038 00039 #elif defined(_TTY_FREEBSD_) 00040 setPortName("/dev/ttyd1"); 00041 00042 #else 00043 setPortName("/dev/ttyS0"); 00044 #endif 00045 00046 construct(); 00047 }
QextSerialBase::QextSerialBase | ( | const QString & | name | ) |
Construct a port and assign it to the device specified by the name parameter.
00054 : QIODevice() 00055 { 00056 setPortName(name); 00057 construct(); 00058 }
QextSerialBase::~QextSerialBase | ( | ) | [virtual] |
void QextSerialBase::construct | ( | ) | [virtual] |
Common constructor function for setting up default port settings. (115200 Baud, 8N1, Hardware flow control where supported, otherwise no flow control, and 500 ms timeout).
00083 { 00084 Settings.BaudRate=BAUD115200; 00085 Settings.DataBits=DATA_8; 00086 Settings.Parity=PAR_NONE; 00087 Settings.StopBits=STOP_1; 00088 Settings.FlowControl=FLOW_HARDWARE; 00089 Settings.Timeout_Sec=0; 00090 Settings.Timeout_Millisec=500; 00091 00092 #ifdef QT_THREAD_SUPPORT 00093 if (!mutex) { 00094 mutex=new QMutex( QMutex::Recursive ); 00095 } 00096 refCount++; 00097 #endif 00098 00099 setOpenMode(QIODevice::NotOpen); 00100 }
void QextSerialBase::setPortName | ( | const QString & | name | ) | [virtual] |
Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0".
00107 { 00108 port = name; 00109 }
QString QextSerialBase::portName | ( | ) | const [virtual] |
virtual void QextSerialBase::setBaudRate | ( | BaudRateType | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
BaudRateType QextSerialBase::baudRate | ( | void | ) | const [virtual] |
virtual void QextSerialBase::setDataBits | ( | DataBitsType | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
DataBitsType QextSerialBase::dataBits | ( | ) | const [virtual] |
virtual void QextSerialBase::setParity | ( | ParityType | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
ParityType QextSerialBase::parity | ( | ) | const [virtual] |
virtual void QextSerialBase::setStopBits | ( | StopBitsType | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
StopBitsType QextSerialBase::stopBits | ( | ) | const [virtual] |
virtual void QextSerialBase::setFlowControl | ( | FlowType | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
FlowType QextSerialBase::flowControl | ( | ) | const [virtual] |
Returns the type of flow control used by the port. For a list of possible values returned by this function, see the definition of the enum FlowType.
00166 { 00167 return Settings.FlowControl; 00168 }
virtual void QextSerialBase::setTimeout | ( | ulong | , | |
ulong | ||||
) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual bool QextSerialBase::open | ( | OpenMode | mode = 0 |
) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual void QextSerialBase::close | ( | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual void QextSerialBase::flush | ( | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual qint64 QextSerialBase::size | ( | ) | const [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual qint64 QextSerialBase::bytesAvailable | ( | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
bool QextSerialBase::atEnd | ( | ) | const [virtual] |
This function will return true if the input buffer is empty (or on error), and false otherwise. Call QextSerialBase::lastError() for error information.
00176 { 00177 if (size()) { 00178 return true; 00179 } 00180 return false; 00181 }
virtual void QextSerialBase::ungetChar | ( | char | c | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
qint64 QextSerialBase::readLine | ( | char * | data, | |
qint64 | maxSize | |||
) | [virtual] |
This function will read a line of buffered input from the port, stopping when either maxSize bytes have been read, the port has no more data available, or a newline is encountered. The value returned is the length of the string that was read.
00190 { 00191 qint64 numBytes = bytesAvailable(); 00192 char* pData = data; 00193 00194 if (maxSize < 2) //maxSize must be larger than 1 00195 return -1; 00196 00197 /*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/ 00198 while (pData<(data+numBytes) && --maxSize) { 00199 readData(pData, 1); 00200 if (*pData++ == '\n') { 00201 break; 00202 } 00203 } 00204 *pData='\0'; 00205 00206 /*return size of data read*/ 00207 return (pData-data); 00208 }
ulong QextSerialBase::lastError | ( | ) | const [virtual] |
Returns the code for the last error encountered by the port, or E_NO_ERROR if the last port operation was successful. Possible error codes are:
Error Explanation --------------------------- ------------------------------------------------------------- E_NO_ERROR No Error has occured E_INVALID_FD Invalid file descriptor (port was not opened correctly) E_NO_MEMORY Unable to allocate memory tables (POSIX) E_CAUGHT_NON_BLOCKED_SIGNAL Caught a non-blocked signal (POSIX) E_PORT_TIMEOUT Operation timed out (POSIX) E_INVALID_DEVICE The file opened by the port is not a character device (POSIX) E_BREAK_CONDITION The port detected a break condition E_FRAMING_ERROR The port detected a framing error (usually caused by incorrect baud rate settings) E_IO_ERROR There was an I/O error while communicating with the port E_BUFFER_OVERRUN Character buffer overrun E_RECEIVE_OVERFLOW Receive buffer overflow E_RECEIVE_PARITY_ERROR The port detected a parity error in the received data E_TRANSMIT_OVERFLOW Transmit buffer overflow E_READ_FAILED General read operation failure E_WRITE_FAILED General write operation failure
00237 { 00238 return lastErr; 00239 }
virtual void QextSerialBase::translateError | ( | ulong | error | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual void QextSerialBase::setDtr | ( | bool | set = true |
) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual void QextSerialBase::setRts | ( | bool | set = true |
) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual ulong QextSerialBase::lineStatus | ( | ) | [pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual qint64 QextSerialBase::readData | ( | char * | data, | |
qint64 | maxSize | |||
) | [protected, pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
virtual qint64 QextSerialBase::writeData | ( | const char * | data, | |
qint64 | maxSize | |||
) | [protected, pure virtual] |
Implemented in Posix_QextSerialPort, and Win_QextSerialPort.
QString QextSerialBase::port [protected] |
PortSettings QextSerialBase::Settings [protected] |
ulong QextSerialBase::lastErr [protected] |
QMutex * QextSerialBase::mutex = NULL [static, protected] |
unsigned long QextSerialBase::refCount = 0 [static, protected] |