My solution is use Qextserialport (http://qextserialport.sourceforge.ne...ialport-1.1.x/)
I use winXP, usb-serial converter and QtCreator 4.5.1
i have tested this with simple microcontroller program which sends data when button is pressed..
When using in "real" situation you need to use QThread to set reader active if you want to maintain programs functionality.
Here is simply code example
comPort = new QextSerialPort("COM7");
//set com port settings
comPort->setBaudRate(BAUD9600);
comPort->setFlowControl(FLOW_HARDWARE);
comPort->setParity(PAR_NONE);
comPort->setDataBits(DATA_8);
comPort->setStopBits(STOP_1);
//read data from com port
char buff[1024];
int numBytes;
numBytes = comPort->bytesAvailable();
if(numBytes > 0)
{
if(numBytes > 1024){
numBytes = 1024;}
int i = comPort->read(buff, numBytes);
buff[i] = '\0';
msg = buff;
}
comPort = new QextSerialPort("COM7");
//set com port settings
comPort->setBaudRate(BAUD9600);
comPort->setFlowControl(FLOW_HARDWARE);
comPort->setParity(PAR_NONE);
comPort->setDataBits(DATA_8);
comPort->setStopBits(STOP_1);
//read data from com port
comPort->open(QIODevice::ReadWrite);
char buff[1024];
int numBytes;
QString msg;
numBytes = comPort->bytesAvailable();
if(numBytes > 0)
{
if(numBytes > 1024){
numBytes = 1024;}
int i = comPort->read(buff, numBytes);
buff[i] = '\0';
msg = buff;
}
To copy to clipboard, switch view to plain text mode
And here is .pro
//my qextserialport dir is C:/qt/qextserialport
...
INCLUDEPATH += C:/Qt/qextserialport
LIBS += C:\Qt\qextserialport\build\qextserialport.dll
..
//my qextserialport dir is C:/qt/qextserialport
...
INCLUDEPATH += C:/Qt/qextserialport
LIBS += C:\Qt\qextserialport\build\qextserialport.dll
..
To copy to clipboard, switch view to plain text mode
-Jeo
Bookmarks