#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 bool | isOpen () const |
| virtual void | close ()=0 |
| virtual void | flush ()=0 |
| virtual qint64 | size () const =0 |
| virtual qint64 | bytesAvailable ()=0 |
| virtual bool | atEnd () const |
| virtual bool | getChar (char *c)=0 |
| virtual bool | putChar (char c)=0 |
| 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 |
| virtual qint64 | readData (char *data, qint64 maxSize)=0 |
| virtual qint64 | writeData (const char *data, qint64 maxSize)=0 |
Protected Attributes | |
| QString | port |
| bool | portOpen |
| PortSettings | Settings |
| ulong | lastErr |
Static Protected Attributes | |
| static QMutex * | mutex = NULL |
| static ulong | refCount = 0 |
|
|
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 }
|
|
|
Construct a port and assign it to the device specified by the name parameter. 00054 : QIODevice()
00055 {
00056 setPortName(name);
00057 construct();
00058 }
|
|
|
Standard destructor. 00065 {
00066
00067 #ifdef QT_THREAD_SUPPORT
00068 refCount--;
00069 if (mutex && refCount==0) {
00070 delete mutex;
00071 mutex=NULL;
00072 }
00073 #endif
00074
00075 }
|
|
|
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 portOpen=false;
00100 }
|
|
|
Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0". 00107 {
00108 port = name;
00109 }
|
|
|
Returns the name set by setPortName(). 00116 {
00117 return port;
00118 }
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Returns the baud rate of the serial port. For a list of possible return values see the definition of the enum BaudRateType.
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Returns the number of data bits used by the port. For a list of possible values returned by this function, see the definition of the enum DataBitsType.
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Returns the type of parity used by the port. For a list of possible values returned by this function, see the definition of the enum ParityType.
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Returns the number of stop bits used by the port. For a list of possible return values, see the definition of the enum StopBitsType.
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
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 }
|
|
||||||||||||
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Returns true if the port associated with the class is currently open, or false if it is not. 00175 {
00176 return portOpen;
00177 }
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
This function will return true if the input buffer is empty (or on error), and false otherwise. Call QextSerialBase::lastError() for error information. 00185 {
00186 if (size()) {
00187 return true;
00188 }
00189 return false;
00190 }
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
||||||||||||
|
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. 00199 {
00200 qint64 numBytes = bytesAvailable();
00201 char* pData = data;
00202
00203 /*if nothing waiting, return 0 length*/
00204 if (numBytes<1) {
00205 return 0;
00206 }
00207
00208 /*read a byte at a time for MIN(bytesAvail, maxSize) iterations, or until a newline*/
00209 while (pData<(data+numBytes) && --maxSize) {
00210 readData(pData, 1);
00211 if (*pData++ == '\n') {
00212 break;
00213 }
00214 }
00215 *pData++='\0';
00216
00217 /*return size of data read*/
00218 return (pData-data);
00219 }
|
|
|
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
00248 {
00249 return lastErr;
00250 }
|
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
||||||||||||
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
||||||||||||
|
Implemented in Posix_QextSerialPort, and Win_QextSerialPort. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.4.1