Environment configuration: Host: xp QT:5.4.0
The focus here is not to tell people how to achieve 921600 bps in qt serial programming.
1, using the serial port in Qt, we need a third-party serial port class:qextserialport. In its qextserialbase.h file, the following commonly used baud rates are available:
enum BaudRateType
{
BAUD50, //POSIX ONLY
BAUD75, //POSIX ONLY
BAUD110,
BAUD134, //POSIX ONLY
BAUD150, //POSIX ONLY
BAUD200, //POSIX ONLY
BAUD300,
BAUD600,
BAUD1200,
BAUD1800, //POSIX ONLY
BAUD2400,
BAUD4800,
BAUD9600,
BAUD14400, //WINDOWS ONLY
BAUD19200,
BAUD38400,
BAUD56000, //WINDOWS ONLY
BAUD57600,
BAUD76800, //POSIX ONLY
BAUD115200,
BAUD128000, //WINDOWS ONLY
BAUD256000 //WINDOWS ONLY
};
2, in fact, to do is simply to add a baud rate we need, do not need special knowledge, consider from the application layer to the OS layer implementation of the process, we just follow this process, add the corresponding data-macro definition/enumeration value can be.
3, then, do it. Take 921600bps as an example.
1) in QT programming, set the serial port baud rate to invoke the enumeration value in Baudratetype, then add 921600 of the enumeration value in Baudratetype:
enum BaudRateType
{
......
BAUD921600
}
2) BAUD921600 the underlying call in void Win_qextserialport::setbaudrate (Baudratetype baudrate) of the Win_qextserialport.cpp file, Then we will add its corresponding Case statement:
void Win_QextSerialPort::setBaudRate(BaudRateType baudRate)
{
......
/* 921600 baud */
case BAUD921600:
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 921600 baud operation.");
Win_CommConfig.dcb.BaudRate=CBR_921600;
break;
}
3) Now, we need to find the underlying call to cbr_921600, which is in the Qt installation directory C:\Qt\Qt5.4.0\Tools\mingw491_32\i686-w64-mingw32\include the winbase.h file below:
C:\Qt\Qt5.4.0\Tools\mingw491_32\i686-w64-mingw32\include\winbase.h:
#define CBR_110 110
#define CBR_300 300
#define CBR_600 600
#define CBR_1200 1200
#define CBR_2400 2400
#define CBR_4800 4800
#define CBR_9600 9600
#define CBR_14400 14400
#define CBR_19200 19200
#define CBR_38400 38400
#define CBR_56000 56000
#define CBR_57600 57600
#define CBR_115200 115200
#define CBR_128000 128000
#define CBR_256000 256000
#define CBR_460800 460800
#define CBR_921600 921600
We just need to add the baud rate corresponding to the cbr_921600.
4) accomplished
4, write here, the focus is to understand, the face of the problem when the way of thinking. Or the idea, is very important. In a nutshell, it's a lot of brain.
A method of 921600 baud rate for QT serial port