Qt Serial Port Driver
The QSPD project is a designed to be a cross platform interface to a computer's RS232 communications port. This software is built to used in project that also use the Nokia QT platform signal/slot infrastructure using C++.
The 2 core files to use are QSerialPort.cpp and QSerialPort.hpp. The source tree provided can be used as a external library or you can just copy the 2 source files into your project and use them directly.
To start we first need to make an instance of the QSerialPort object. This is done like the following:
QSerialPort *MySerialPort = new QserialPort(); |
Once you have a QSerialPort object, you can now connect up its signals to your application.
The QSerialPort object emits the following signals:
· hasData()
o gets signaled when the receiver thread adds anything to the receive queue for processing.
· openPortFailed()
o signaled if opening the requested serial port failed.
· openPortSuccess()
o signaled if opening the requested serial port was sucessfull
· bufferOverflow()
o signaled if the receiver thread notices that the receive buffer is over a threshold size.
o 1023 bytes is the default threshold. Defined @ line 131 in QSerialPort.cpp
Connect up the signals as follows:
connect(MySerialPort, SIGNAL(hasData()), SomeUsersClass, SLOT(processData())); connect(MySerialPort, SIGNAL(openPortFailed()),SomeUsersClass, SLOT(openPortFailed())); connect(MySerialPort, SIGNAL(openPortSuccess()),SomeUsersClass, SLOT(openPortSuccess())); connect(MySerialPort, SIGNAL(bufferOverflow()),SomeUsersClass, SLOT(bufferOverflow())); |
Opening the serial port:
serialDevice->usePort( "/dev/ttyUSB0", Baud9600 , CS8, SB1, ParityNone ); |
· dev
o device to open as a ascii string. examples: (windows)"COM1", (linux)"/dev/ttyUSB0"
· baud
o One of the following values as defined in QSerialPort.hpp
§ Baud300
§ Baud600
§ Baud1200
§ Baud2400
§ Baud4800
§ Baud9600
§ Baud19200
§ Baud38400
§ Baud57600
§ Baud115200
· byteSize
o number of bits in a rs232 transaction 5,6,7,8 bits values as defined in QSerialPort.hpp
§ CS8
§ CS7
§ CS6
§ CS5
· sb
o number of stop bits to use, 1 or 2 as defined in QSerialPort.hpp
§ SB1
§ SB2
· parity
o Parity used, if used at all
§ ParityEven
§ ParityOdd
§ ParityNone
If you need more help, Try email: biovore@gmail.com